Code

make win32 compile using libxslt
[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     ~ConnectionPool ()
23     {
24       for (ConnectionMap::iterator iter = map.begin (), end = map.end (); iter != end; ++iter)
25       {
26         sigc::connection* connection = (*iter).second;
27         connection->disconnect ();
28         delete connection;
29       }
30     }
32     void
33     add_connection (std::string name, sigc::connection* connection)
34     {
35       if (map.find (name) != map.end ()) throw NAME_EXISTS;
36       map.insert (std::make_pair (name, connection)); 
37     }
39     void
40     del_connection (std::string name)
41     {
42       ConnectionMap::iterator iter = map.find (name); 
43       if (iter == map.end ()) throw NAME_DOES_NOT_EXIST;
44       sigc::connection* connection = (*iter).second;
45       connection->disconnect ();
46       delete connection;
47     }
50     static Inkscape::ConnectionPool*
51     new_connection_pool (std::string name)
52     {
53        return new ConnectionPool (name); 
54     }
56     static void
57     del_connection_pool (Inkscape::ConnectionPool* pool)
58     {
59       delete pool;
60     }
62     static void
63     connect_destroy (GObject *obj, Inkscape::ConnectionPool *pool)
64     {
65       g_object_connect (obj, "swapped-signal::destroy", G_CALLBACK (del_connection_pool), pool, NULL);
66     }
68     operator std::string ()
69     {
70       return name;
71     }
73   private:
75     ConnectionPool (std::string name) : name (name)
76     {}
78     ConnectionMap map;
79     std::string   name;
80 };
81 }
83 #endif