X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fconnector.h;h=739f67fdd9dbbe0093a91170cb6e2c11ee2735e4;hb=HEAD;hp=1960e81b133a26af1c0a8fb2c9662d8fad5b6e1f;hpb=8ffcd589660022f05d8b3b1dbb36c0c0aa91954a;p=libs%2Fgltk.git diff --git a/source/connector.h b/source/connector.h deleted file mode 100644 index 1960e81..0000000 --- a/source/connector.h +++ /dev/null @@ -1,137 +0,0 @@ -/* $Id$ - -This file is part of libmspgltk -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#ifndef MSP_GLTK_CONNECTOR_H_ -#define MSP_GLTK_CONNECTOR_H_ - -#include -#include -#include - -namespace Msp { -namespace GLtk { - -class Connector; -class Logic; -class Widget; - -class ConnAction -{ -public: - virtual void connect(Connector &conn, Widget &wdg, const std::string &data) const =0; - virtual ~ConnAction() { } -}; - -template -class ConnFunc0: public ConnAction -{ -public: - typedef void (C::*FuncType)(W &); - - ConnFunc0(FuncType f): func(f) { } - virtual void connect(Connector &conn, Widget &wdg, const std::string &) const - { - (dynamic_cast(conn).*func)(dynamic_cast(wdg)); - } - -private: - FuncType func; -}; - -template -class ConnFunc1: public ConnAction -{ -public: - typedef void (C::*FuncType)(W &, const std::string &); - - ConnFunc1(FuncType f): func(f) { } - virtual void connect(Connector &conn, Widget &wdg, const std::string &data) const - { - (dynamic_cast(conn).*func)(dynamic_cast(wdg), data); - } - -private: - FuncType func; -}; - -template -class ConnSignal: public ConnAction -{ -public: - ConnSignal(S W::*s, F f): signal(s), func(f) { } - virtual void connect(Connector &conn, Widget &wdg, const std::string &) const - { - (dynamic_cast(wdg).*signal).connect(sigc::mem_fun(&dynamic_cast(conn).get_object(), func)); - } - -private: - S W::*signal; - F func; -}; - -/** -Provides an interface for associating the bindings stored in a Logic object -with actual code. Derive a class from this and use the add functions to -specify handlers for each binding type. - -Bindings are normally handled by member functions of the Connector class. The -function must take a reference to a widget (of any type) as its first parameter. -If it takes a second parameter, the binding data is passed in as well. - -As a shortcut for simple connections, signals of widgets can be connected -directly to a handler object. For this to work, the Connector class must be a -public inner class of the handler class and it must have a get_object() member -function returning a reference to the handler object. - -TODO: lexical_cast the binding data (requires working around references) -*/ -class Connector -{ -private: - std::map actions; - -protected: - Connector() { } -public: - virtual ~Connector(); - - /** - Processes all bindings in the Logic object and calls appropriate handlers. - */ - void connect(const Logic &); - -protected: - /** - Adds a handler function for a binding. - */ - template - void add(const std::string &type, void (C::*func)(W &)) - { add(type, new ConnFunc0(func)); } - - /** - Adds a handler function for a binding. The binding data is passed in the - second parameter. - */ - template - void add(const std::string &type, void (C::*func)(W &, const std::string &)) - { add(type, new ConnFunc1(func)); } - - /** - Adds a signal connector for a binding. - */ - template - void add(const std::string &type, S W::*signal, F H::*func) - { add(type, new ConnSignal(signal, func)); } - -private: - void add(const std::string &, ConnAction *); -}; - -} // namespace GLtk -} // namespace Msp - -#endif