3 This file is part of libmspgltk
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #ifndef MSP_GLTK_CONNECTOR_H_
9 #define MSP_GLTK_CONNECTOR_H_
24 virtual void connect(Connector &conn, Widget &wdg, const std::string &data) const =0;
25 virtual ~ConnAction() { }
28 template<typename C, typename W>
29 class ConnFunc0: public ConnAction
32 typedef void (C::*FuncType)(W &);
34 ConnFunc0(FuncType f): func(f) { }
35 virtual void connect(Connector &conn, Widget &wdg, const std::string &) const
37 (dynamic_cast<C &>(conn).*func)(dynamic_cast<W &>(wdg));
44 template<typename C, typename W>
45 class ConnFunc1: public ConnAction
48 typedef void (C::*FuncType)(W &, const std::string &);
50 ConnFunc1(FuncType f): func(f) { }
51 virtual void connect(Connector &conn, Widget &wdg, const std::string &data) const
53 (dynamic_cast<C &>(conn).*func)(dynamic_cast<W &>(wdg), data);
61 Provides an interface for associating the actions stored in a Logic object with
62 actual code. Derive a class from this and use the add functions to specify
63 handlers for each action type.
68 std::map<std::string, ConnAction *> actions;
75 void connect(const Logic &);
78 template<typename C, typename W>
79 void add(const std::string &type, void (C::*func)(W &))
80 { add(type, new ConnFunc0<C, W>(func)); }
82 template<typename C, typename W>
83 void add(const std::string &type, void (C::*func)(W &, const std::string &))
84 { add(type, new ConnFunc1<C, W>(func)); }
87 void add(const std::string &, ConnAction *);