]> git.tdb.fi Git - libs/gltk.git/blob - source/connector.cpp
2b64d0019af1abcb3a6c50be76e0005cc8ff54e9
[libs/gltk.git] / source / connector.cpp
1 #include "connector.h"
2 #include "logic.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace GLtk {
8
9 Connector::~Connector()
10 {
11         for(map<string, ConnAction *>::iterator i=actions.begin(); i!=actions.end(); ++i)
12                 delete i->second;
13 }
14
15 void Connector::connect(const Logic &logic)
16 {
17         const list<Logic::WidgetBinding> &logic_binds = logic.get_bindings();
18
19         for(list<Logic::WidgetBinding>::const_iterator i=logic_binds.begin(); i!=logic_binds.end(); ++i)
20         {
21                 map<string, ConnAction *>::const_iterator j = actions.find(i->type);
22                 if(j!=actions.end())
23                         j->second->connect(*this, *i->wdg, i->data);
24                 else
25                         throw KeyError("Unknown binding type", i->type);
26         }
27 }
28
29 void Connector::add(const string &type, ConnAction *act)
30 {
31         map<string, ConnAction *>::iterator i = actions.find(type);
32         if(i!=actions.end())
33         {
34                 delete i->second;
35                 i->second = act;
36         }
37         else
38                 actions[type] = act;
39 }
40
41 } // namespace GLtk
42 } // namespace Msp