1
/***************************************************************************
2
* Copyright (C) 2004-2007 by Dr. Marc Boris Duerner *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU Library General Public License as *
6
* published by the Free Software Foundation; either version 2 of the *
7
* License, or (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU Library General Public *
15
* License along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18
***************************************************************************/
19
#ifndef cxxtools_Connectable_h
20
#define cxxtools_Connectable_h
22
#include <cxxtools/connection.h>
27
/** @brief Connection management for signal and slot objects
29
This class implements connection management for signal and slot
30
objects. It makes sure that all connections where this object
31
is involved are closed on destruction. Deriving classes can
32
overload Connectable::opened and Connectable::closed to tune
33
connection managenment.
38
/** @brief Default constructor.
40
Creates an empty %Connectable.
44
/** @brief Closes all connections.
46
When a %Connectable object is destroyed, it closes all its
47
connections automatically.
49
virtual ~Connectable();
51
/** @brief Registers a Connection with the %Connectable.
53
This function is called when a new Connection involving
54
this object is opened. The default implementation adds
55
the connection to a list, so the destructor can close it.
57
@param c Connection being opened
58
@return True if the Connection was accepted
60
virtual bool opened(const Connection& c);
62
/** @brief Unregisters a Connection from the %Connectable.
64
This function is called when a new Connection involving
65
this object is closed. The default implementation removes
66
the connection from its list of connections.
68
@param c Connection being opened
70
virtual void closed(const Connection& c);
72
//! @internal @brief For unit tests only.
73
size_t connectionCount() const
74
{ return _connections.size(); }
77
/** @brief Copy constructor
79
@sa Connectable::operator=()
81
Connectable(const Connectable& c);
83
/** @brief Assignment operator
85
Connectables can be copy constructed if the derived class
86
provides a public copy constructor. Copying a %Connectable
87
will not change its connections.
89
Connectable& operator=(const Connectable& rhs);
91
/** @brief Returns a list of all current connections
93
const std::list<Connection>& connections() const
94
{ return _connections; }
96
/** @brief Returns a list of all current connections
98
std::list<Connection>& connections()
99
{ return _connections; }
102
/** @brief A list of all current connections
104
mutable std::list<Connection> _connections;
110
} // namespace cxxtools