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