diff options
| author | Milosz Derezynski <mderezynski@gmail.com> | 2006-05-19 03:28:16 +0000 |
|---|---|---|
| committer | mderezynski <mderezynski@users.sourceforge.net> | 2006-05-19 03:28:16 +0000 |
| commit | 03d41b96100e017d21279248c04945be3cc3723c (patch) | |
| tree | 50a4302d6db1430e19090d435afd8cd67123a595 /src/connection-pool.h | |
| parent | fixed crash when starting up without Inkscape GUI: Inkscape messages were bei... (diff) | |
| download | inkscape-03d41b96100e017d21279248c04945be3cc3723c.tar.gz inkscape-03d41b96100e017d21279248c04945be3cc3723c.zip | |
* Add connection-pool.h: Inkscape::ConnectionPool, an auxilliary class to manage sigc::connections
* Finish listening to selections, make family selector work properly
(bzr r887)
Diffstat (limited to 'src/connection-pool.h')
| -rw-r--r-- | src/connection-pool.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/connection-pool.h b/src/connection-pool.h new file mode 100644 index 000000000..7a14f57d8 --- /dev/null +++ b/src/connection-pool.h @@ -0,0 +1,83 @@ +#ifndef CONNECTION_POOL_H +#define CONNECTION_POOL_H + +#include <glib-object.h> +#include <gtkmm.h> +#include <sigc++/sigc++.h> + +namespace Inkscape +{ +class ConnectionPool +{ + public: + + enum Exception + { + NAME_EXISTS, + NAME_DOES_NOT_EXIST + }; + + typedef std::map<std::string, sigc::connection*> ConnectionMap; + + ~ConnectionPool () + { + for (ConnectionMap::iterator iter = map.begin (), end = map.end (); iter != end; ++iter) + { + sigc::connection* connection = (*iter).second; + connection->disconnect (); + delete connection; + } + } + + void + add_connection (std::string name, sigc::connection* connection) + { + if (map.find (name) != map.end ()) throw NAME_EXISTS; + map.insert (std::make_pair (name, connection)); + } + + void + del_connection (std::string name) + { + ConnectionMap::iterator iter = map.find (name); + if (iter == map.end ()) throw NAME_DOES_NOT_EXIST; + sigc::connection* connection = (*iter).second; + connection->disconnect (); + delete connection; + } + + + static Inkscape::ConnectionPool* + new_connection_pool (std::string name) + { + return new ConnectionPool (name); + } + + static void + del_connection_pool (Inkscape::ConnectionPool* pool) + { + delete pool; + } + + static void + connect_destroy (GObject *obj, Inkscape::ConnectionPool *pool) + { + g_object_connect (obj, "swapped-signal::destroy", G_CALLBACK (del_connection_pool), pool, NULL); + } + + operator std::string () + { + return name; + } + + private: + + ConnectionPool (std::string name) : name (name) + {} + + ConnectionMap map; + std::string name; +}; +} + +#endif |
