~ubuntu-branches/ubuntu/wily/cxxtools/wily-proposed

« back to all changes in this revision

Viewing changes to include/cxxtools/connectable.h

  • Committer: Bazaar Package Importer
  • Author(s): Kari Pahula
  • Date: 2008-06-16 12:24:28 UTC
  • mfrom: (3.1.3 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616122428-7bllgyt1358u779r
Tags: 1.4.8-2
Made libcxxtools-dev depend on libcxxtools6, not libcxxtools5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2004-2007 by Dr. Marc Boris Duerner                     *
 
3
 *                                                                         *
 
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.                       *
 
8
 *                                                                         *
 
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.                          *
 
13
 *                                                                         *
 
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
 
21
 
 
22
#include <cxxtools/connection.h>
 
23
#include <list>
 
24
 
 
25
namespace cxxtools {
 
26
 
 
27
    /** @brief Connection management for signal and slot objects
 
28
 
 
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.
 
34
    */
 
35
    class Connectable
 
36
    {
 
37
        public:
 
38
            /** @brief Default constructor.
 
39
 
 
40
                Creates an empty %Connectable.
 
41
            */
 
42
            Connectable();
 
43
 
 
44
            /** @brief Closes all connections.
 
45
 
 
46
                When a %Connectable object is destroyed, it closes all its
 
47
                connections automatically.
 
48
            */
 
49
            virtual ~Connectable();
 
50
 
 
51
            /** @brief Registers a Connection with the %Connectable.
 
52
 
 
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.
 
56
 
 
57
                @param c Connection being opened
 
58
                @return True if the Connection was accepted
 
59
            */
 
60
            virtual bool opened(const Connection& c);
 
61
 
 
62
            /** @brief Unregisters a Connection from the %Connectable.
 
63
 
 
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.
 
67
 
 
68
                @param c Connection being opened
 
69
            */
 
70
            virtual void closed(const Connection& c);
 
71
 
 
72
            //! @internal @brief For unit tests only.
 
73
            size_t connectionCount() const
 
74
            { return _connections.size(); }
 
75
 
 
76
        protected:
 
77
            /** @brief Copy constructor
 
78
 
 
79
                @sa Connectable::operator=()
 
80
            */
 
81
            Connectable(const Connectable& c);
 
82
 
 
83
            /** @brief Assignment operator
 
84
 
 
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.
 
88
            */
 
89
            Connectable& operator=(const Connectable& rhs);
 
90
 
 
91
            /** @brief Returns a list of all current connections
 
92
            */
 
93
            const std::list<Connection>& connections() const
 
94
            { return _connections; }
 
95
 
 
96
            /** @brief Returns a list of all current connections
 
97
            */
 
98
            std::list<Connection>& connections()
 
99
            { return _connections; }
 
100
 
 
101
        protected:
 
102
            /** @brief A list of all current connections
 
103
            */
 
104
            mutable std::list<Connection> _connections;
 
105
 
 
106
            //! @internal
 
107
            void clear();
 
108
    };
 
109
 
 
110
} // namespace cxxtools
 
111
 
 
112
#endif