(empty message)
[qanava.git] / src / utl / utlManager.h
blobcbaaf250d01c88d4c61ceb07879299c72c393e87
1 //-----------------------------------------------------------------------------
2 // This file is a part of the Qanava and LTM software.
3 //
4 // \file utlManager.h
5 // \author Benoit Autheman (benoit@faktiss.net)
6 // \date 2003 June 02
7 //-----------------------------------------------------------------------------
10 #ifndef qan_utlManager_h
11 #define qan_utlManager_h
14 // Change the BOOST signals namespace name to avoid clash with QT MOC 'signals' keyword
15 #undef BOOST_SIGNALS_NAMESPACE
16 #define BOOST_SIGNALS_NAMESPACE boost_signals
19 // LTM headers
20 #include "./utlConfig.h"
23 // Standard includes
24 #include <list>
25 #include <vector>
28 // Boost headers
29 #ifndef QANAVA_NOBOOST
30 #include <signals/signal0.hpp>
31 #include <signals/signal1.hpp>
32 #endif
35 //-----------------------------------------------------------------------------
36 namespace QAN_UTL_ROOT_NAMESPACE // ::QAN_UTL_ROOT_NAMESPACE
38 namespace utl // ::QAN_UTL_ROOT_NAMESPACE::utl
40 //! Empty glue class for all generic managers.
41 /*!
42 \nosubgrouping
44 class ManagerBase
46 public:
48 //! Mode of maangement.
49 enum Mode
51 //! Mode undefined.
52 UNDEFINED = 1,
54 //! Elements are just shared by the manager and left unmodified after manager destruction.
55 SHARED = 2,
57 //! Elements are owned by the manager and freed during the manager destruction.
58 OWNED = 4
63 //! Manage a group of generic object instances.
64 /*!
65 Support the virtual model behaviour trought the apropriate signals.
67 \nosubgrouping
69 template < class Item >
70 class Manager : public ManagerBase
72 /*! \name Manager Constructor/Destructor *///----------------------
73 //@{
74 public:
76 //! Manager constructor.
77 Manager( Mode mode = OWNED );
79 //! Manager destructor.
80 virtual ~Manager( );
82 private:
84 //! Manager empty private copy constructor.
85 Manager( const Manager< Item >& manager ) : _mode( manager.mode ) { }
86 //@}
87 //-----------------------------------------------------------------
91 /*! \name Items management *///------------------------------------
92 //@{
93 public:
95 //! STL vector of pointer to item type definition.
96 typedef std::list< Item* > Items;
98 //! Shortcut to the equivalent stl container member.
99 typedef typename Items::iterator iterator;
101 //! Shortcut to the equivalent stl container member.
102 typedef typename Items::const_iterator const_iterator;
104 //! Shortcut to the equivalent stl container member.
105 unsigned int size( ) const { return ( unsigned int )_items.size( ); }
107 //! Shortcut to the equivalent stl container member.
108 iterator begin( ) { return _items.begin( ); }
110 //! Shortcut to the equivalent stl container member.
111 const_iterator begin( ) const { return _items.begin( ); }
113 //! Shortcut to the equivalent stl container member.
114 iterator end( ) { return _items.end( ); }
116 //! Shortcut to the equivalent stl container member.
117 const_iterator end( ) const { return _items.end( ); }
119 //! Get a const reference on the manager items list.
120 /*! \return Manager items list const reference. */
121 const Items& getItems( ) const { return _items; }
123 //! Get a reference on the manager items list.
124 /*! \return Manager items list reference. */
125 Items& getItems( ) { return _items; }
127 //! Register an item by adding its reference to manager item list.
128 virtual void add( Item& item );
130 //! Register a list of items by adding their references to this manager.
131 virtual void add( Items& items );
133 //! Remove an item from this manager.
134 virtual void remove( Item& item );
136 //! Test if an item is registered in the manager.
137 bool has( Item& item ) const;
139 //! Clear the database of all managed items.
140 void clear( bool destroy = false );
142 //! Return the manager first item pointer (0 if manager is empty).
143 Item* first( );
145 //! Return a pointer on th ith managed object.
146 Item* get( unsigned int index );
148 //! Return a const pointer on th ith managed object.
149 const Item* get( unsigned int index ) const;
151 //! Return the manager mode.
152 Mode getMode( ) const { return _mode; }
154 private:
156 //! Management mode.
157 Mode _mode;
159 //! Internal list of item registered in the manager.
160 Items _items;
161 //@}
162 //-----------------------------------------------------------------
166 /*! \name Model Signals Management *///----------------------------
167 //@{
168 public:
170 #ifndef QANAVA_NOBOOST
171 //! .
172 boost::signal0< void > modified;
173 #else
174 void modified( ) { }
175 #endif
176 #ifndef QANAVA_NOBOOST
177 //! .
178 boost::signal0< void > destroyed;
179 #else
180 void destroyed( ) { }
181 #endif
182 //@}
183 //-----------------------------------------------------------------
185 } // ::ROOT_NAMESPACE::utl
186 } // ::ROOT_NAMESPACE
187 //-----------------------------------------------------------------------------
190 #include "./utlManager.hpp"
193 #endif // qan/ltm_utlManager_h