Code

Node tool: correctly save node skewing to undo history
[inkscape.git] / src / connection-pool.h
1 #ifndef CONNECTION_POOL_H
2 #define CONNECTION_POOL_H
4 #include <glib-object.h>
5 #include <gtkmm.h>
6 #include <sigc++/sigc++.h>
8 namespace Inkscape
9 {
10 class ConnectionPool
11 {
12   public:
14     enum Exception
15     {
16       NAME_EXISTS,
17       NAME_DOES_NOT_EXIST
18     };
20     typedef std::map<std::string, sigc::connection*> ConnectionMap;
22     virtual ~ConnectionPool ()
23     {
24         for (ConnectionMap::iterator iter = map.begin (), end = map.end (); iter != end; ++iter) {
25             sigc::connection* connection = (*iter).second;
26             connection->disconnect ();
27             delete connection;
28         }
29     }
31     void
32     add_connection (std::string name, sigc::connection* connection)
33     {
34         if (map.find (name) != map.end ()) throw NAME_EXISTS;
35         map.insert (std::make_pair (name, connection)); 
36     }
38     void
39     del_connection (std::string name)
40     {
41       ConnectionMap::iterator iter = map.find (name); 
42       if (iter == map.end ()) throw NAME_DOES_NOT_EXIST;
43       sigc::connection* connection = (*iter).second;
44       connection->disconnect ();
45       delete connection;
46     }
49     static Inkscape::ConnectionPool*
50     new_connection_pool (std::string name)
51     {
52        return new ConnectionPool (name); 
53     }
55     static void
56     del_connection_pool (Inkscape::ConnectionPool* pool)
57     {
58       delete pool;
59     }
61     static void
62     connect_destroy (GObject *obj, Inkscape::ConnectionPool *pool)
63     {
64       g_object_connect (obj, "swapped-signal::destroy", G_CALLBACK (del_connection_pool), pool, NULL);
65     }
67     operator std::string ()
68     {
69       return name;
70     }
72   private:
74     ConnectionPool (std::string name) : name (name)
75     {}
77     ConnectionMap map;
78     std::string   name;
79 };
80 }
82 #endif