]> git.tdb.fi Git - libs/gltk.git/blob - source/connector.cpp
Add ConnSignal action for Connector
[libs/gltk.git] / source / connector.cpp
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "connector.h"
9 #include "logic.h"
10
11 using namespace std;
12
13 namespace Msp {
14 namespace GLtk {
15
16 Connector::~Connector()
17 {
18         for(map<string, ConnAction *>::iterator i=actions.begin(); i!=actions.end(); ++i)
19                 delete i->second;
20 }
21
22 void Connector::connect(const Logic &logic)
23 {
24         const list<Logic::WidgetBinding> &logic_binds=logic.get_bindings();
25
26         for(list<Logic::WidgetBinding>::const_iterator i=logic_binds.begin(); i!=logic_binds.end(); ++i)
27         {
28                 map<string, ConnAction *>::const_iterator j=actions.find(i->type);
29                 if(j!=actions.end())
30                         j->second->connect(*this, *i->wdg, i->data);
31                 else
32                         throw KeyError("Unknown binding type", i->type);
33         }
34 }
35
36 void Connector::add(const string &type, ConnAction *act)
37 {
38         map<string, ConnAction *>::iterator i=actions.find(type);
39         if(i!=actions.end())
40         {
41                 delete i->second;
42                 i->second=act;
43         }
44         else
45                 actions[type]=act;
46 }
47
48 } // namespace GLtk
49 } // namespace Msp