1 //-----------------------------------------------------------------------------
2 // This file is a part of the Qanava and LTM software.
5 // \author Benoit Autheman (benoit@faktiss.net)
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
20 #include "./utlConfig.h"
29 #ifndef QANAVA_NOBOOST
30 #include <signals/signal0.hpp>
31 #include <signals/signal1.hpp>
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.
48 //! Mode of maangement.
54 //! Elements are just shared by the manager and left unmodified after manager destruction.
57 //! Elements are owned by the manager and freed during the manager destruction.
63 //! Manage a group of generic object instances.
65 Support the virtual model behaviour trought the apropriate signals.
69 template < class Item
>
70 class Manager
: public ManagerBase
72 /*! \name Manager Constructor/Destructor *///----------------------
76 //! Manager constructor.
77 Manager( Mode mode
= OWNED
);
79 //! Manager destructor.
84 //! Manager empty private copy constructor.
85 Manager( const Manager
< Item
>& manager
) : _mode( manager
.mode
) { }
87 //-----------------------------------------------------------------
91 /*! \name Items management *///------------------------------------
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).
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
; }
159 //! Internal list of item registered in the manager.
162 //-----------------------------------------------------------------
166 /*! \name Model Signals Management *///----------------------------
170 #ifndef QANAVA_NOBOOST
172 boost::signal0
< void > modified
;
176 #ifndef QANAVA_NOBOOST
178 boost::signal0
< void > destroyed
;
180 void destroyed( ) { }
183 //-----------------------------------------------------------------
185 } // ::ROOT_NAMESPACE::utl
186 } // ::ROOT_NAMESPACE
187 //-----------------------------------------------------------------------------
190 #include "./utlManager.hpp"
193 #endif // qan/ltm_utlManager_h