diff options
| author | Liam P. White <inkscapebrony@gmail.com> | 2014-07-29 20:54:43 +0000 |
|---|---|---|
| committer | Liam P. White <inkscapebrony@gmail.com> | 2014-07-29 20:54:43 +0000 |
| commit | 61efb08544085d06a84067707c9ce0e79760965b (patch) | |
| tree | 135aaad126acfe2e0b78077e8db6755d01ace7b3 /src | |
| parent | revert unintentional change in last commit. (diff) | |
| download | inkscape-61efb08544085d06a84067707c9ce0e79760965b.tar.gz inkscape-61efb08544085d06a84067707c9ce0e79760965b.zip | |
Refactor some disgusting code
(bzr r13341.1.105)
Diffstat (limited to 'src')
| -rw-r--r-- | src/connection-pool.h | 128 |
1 files changed, 72 insertions, 56 deletions
diff --git a/src/connection-pool.h b/src/connection-pool.h index b1ac6f07a..4637a3cc1 100644 --- a/src/connection-pool.h +++ b/src/connection-pool.h @@ -1,84 +1,100 @@ +/* + * Author: + * mderezynski <mderezynski@users.sourceforge.net> + * + * Copyright (C) 2006 Author + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + #ifndef CONNECTION_POOL_H #define CONNECTION_POOL_H -#include <map> #include <glib-object.h> -#include <stddef.h> -#include <string> #include <sigc++/sigc++.h> -namespace Inkscape -{ -class ConnectionPool -{ - public: +#include <map> +#include <stddef.h> +#include <string> +#include <exception> + +namespace Inkscape { + +/** + * @class ConnectionPool + * an auxilliary class to manage sigc::connections as if the referred object + * were a GObject; in that way, the class that holds a ConnectionPool does not + * need to also hold several sigc::connection objects + */ +class ConnectionPool { +public: + typedef std::map<std::string, sigc::connection*> ConnectionMap; - enum Exception - { - NAME_EXISTS, - NAME_DOES_NOT_EXIST + struct NameExistsException : public std::exception { + virtual const char* what() const throw() { return "Inkscape::ConnectionPool: name exists"; } + }; + struct NameDoesNotExistException : public std::exception { + virtual const char* what() const throw() { return "Inkscape::ConnectionPool: name doesn't exist"; } }; - typedef std::map<std::string, sigc::connection*> ConnectionMap; - - virtual ~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 NameExistsException(); } + _map.insert(std::make_pair(name, 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; + void del_connection(std::string name) { + ConnectionMap::iterator iter = _map.find(name); + if (iter == _map.end()) { + throw NameDoesNotExistException(); + } + sigc::connection* connection = (*iter).second; + connection->disconnect(); + delete connection; } - static Inkscape::ConnectionPool* - new_connection_pool (std::string name) - { - return new ConnectionPool (name); + 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 del_connection_pool(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); + static void connect_destroy(GObject *obj, ConnectionPool *pool) { + g_object_connect (obj, "swapped-signal::destroy", G_CALLBACK(del_connection_pool), pool, NULL); } - operator std::string () - { - return name; + operator std::string() { + return _name; } - private: - - ConnectionPool (std::string name) : name (name) - {} +private: + ConnectionPool(std::string name) : _name(name) {} + virtual ~ConnectionPool() { + for (ConnectionMap::iterator iter = _map.begin(), end = _map.end(); iter != end; ++iter) { + sigc::connection* connection = (*iter).second; + connection->disconnect(); + delete connection; + } + } - ConnectionMap map; - std::string name; + ConnectionMap _map; + std::string _name; }; } #endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 : |
