GlsMenu  1.5.4
gls_menu_data_group.h
Go to the documentation of this file.
1 
40 #if !defined( GLS_MENUDATAGROUP_H )
41 # define GLS_MENUDATAGROUP_H
42 
43 # ifdef WIN32
44 # pragma warning( disable : 4786 )
45 # endif
46 
47 # include <iomanip>
48 # include <string>
49 
50 # include "gls_menu_action.h"
51 # include "gls_menu_data.h"
52 # include "gls_menu_dictionary.h"
53 
54 //============================================================================
60 //============================================================================
62 {
63 public:
64  //------------------------------------------------------------------------
68  //------------------------------------------------------------------------
69  virtual ~GlsMenuDataGroup();
70 
71  //------------------------------------------------------------------------
77  //------------------------------------------------------------------------
78  const GlsMenuDictionary& Attributes() const { return _attr; }
79 
80  //------------------------------------------------------------------------
86  //------------------------------------------------------------------------
87  virtual std::istream& ReadValue( std::istream& instr );
88 
89  //------------------------------------------------------------------------
95  //------------------------------------------------------------------------
96  virtual std::ostream& WriteValue( std::ostream& outstr );
97 
98 protected:
101 
102  //------------------------------------------------------------------------
106  //------------------------------------------------------------------------
107  GlsMenuDataGroup( const std::string& name );
108 
109 }; // end GlsMenuDataGroup
110 
111 //============================================================================
120 //============================================================================
122 {
123 public:
124  //------------------------------------------------------------------------
130  //------------------------------------------------------------------------
131  GlsMenuDynDataGroup( const std::string& name, bool uniqueKeys = true );
132 
133  //------------------------------------------------------------------------
137  //------------------------------------------------------------------------
138  virtual ~GlsMenuDynDataGroup();
139 
140  //------------------------------------------------------------------------
146  //------------------------------------------------------------------------
147  virtual std::istream& ReadValue( std::istream& instr );
148 
149 protected:
152 
153  //------------------------------------------------------------------------
161  //------------------------------------------------------------------------
162  virtual GlsMenuData* CreateDataItem( const std::string& name ) const = 0;
163 
164 }; // end GlsMenuDynDataGroup
165 
166 //============================================================================
175 //============================================================================
176 template<class T>
178 {
179 public:
180  //------------------------------------------------------------------------
188  //------------------------------------------------------------------------
189  GlsMenuDataGroup_T( const std::string& name,
190  GlsMenuDictionary& dataDict,
191  bool uniqueKeys = true )
192  : GlsMenuDynDataGroup( name, uniqueKeys )
193  , _dataDict( dataDict )
194  {
195  }
196 
197  //------------------------------------------------------------------------
201  //------------------------------------------------------------------------
202  virtual ~GlsMenuDataGroup_T() {}
203 
204  //------------------------------------------------------------------------
213  //------------------------------------------------------------------------
214  T* Item( const std::string& name ) const
215  {
216  return dynamic_cast<T*>( _attr.Get( disti::AttributeName( name ) ) );
217  }
218 
219 protected:
223 
224  //------------------------------------------------------------------------
233  //------------------------------------------------------------------------
234  virtual GlsMenuData* CreateDataItem( const std::string& name ) const
235  {
236  return static_cast<GlsMenuData*>( new T( name, _dataDict ) );
237  }
238 
239 }; // end GlsMenuDataGroup_T
240 
241 //============================================================================
250 //============================================================================
251 template<class T>
253 {
254 public:
255  //------------------------------------------------------------------------
266  //------------------------------------------------------------------------
267  GlsMenuHandlerGroup_T( const std::string& name,
268  GlsMenuDictionary& dataDict,
269  GlsMenuAction::HandlerCont_t& actionHandlers,
270  bool uniqueKeys = true )
271  : GlsMenuDynDataGroup( name, uniqueKeys )
272  , _dataDict( dataDict )
273  , _handlers( actionHandlers )
274  {
275  }
276 
277  //------------------------------------------------------------------------
281  //------------------------------------------------------------------------
283 
284  //------------------------------------------------------------------------
293  //------------------------------------------------------------------------
294  T* Item( const std::string& name ) const
295  {
296  return dynamic_cast<T*>( _attr.Get( disti::AttributeName( name ) ) );
297  }
298 
299 protected:
303 
304  // Action/Handler pairs passed in from the creator to pass to items
305  // created in the group.
307 
308  //------------------------------------------------------------------------
318  //------------------------------------------------------------------------
319  virtual GlsMenuData* CreateDataItem( const std::string& name ) const
320  {
321  return static_cast<GlsMenuData*>( new T( name, _dataDict, _handlers ) );
322  }
323 
324 }; // end GlsMenuHandlerGroup_T
325 
326 #endif
This file defines all menu meta-data classes.
virtual ~GlsMenuDynDataGroup()
This file defines a meta-data dictionary class.
GlsMenuDictionary _attr
The dictionary of attributes for the group attribute.
std::map< std::string, ActionHandler_t * > HandlerCont_t
GlsMenuDynDataGroup(const std::string &name, bool uniqueKeys=true)
virtual std::ostream & WriteValue(std::ostream &outstr)
const GlsMenuDictionary & Attributes() const
virtual std::istream & ReadValue(std::istream &instr)
bool _uniqueKeys
Specifies whether attribute names should be unique or not.
GlsMenuHandlerGroup_T(const std::string &name, GlsMenuDictionary &dataDict, GlsMenuAction::HandlerCont_t &actionHandlers, bool uniqueKeys=true)
virtual std::istream & ReadValue(std::istream &instr)
T * Item(const std::string &name) const
virtual GlsMenuData * CreateDataItem(const std::string &name) const
virtual GlsMenuData * CreateDataItem(const std::string &name) const =0
virtual ~GlsMenuDataGroup()
GlsMenuAction::HandlerCont_t & _handlers
GlsMenuDictionary & _dataDict
Data dictionary to pass to items created in the group. This is the dictionary used to evaluate menu d...
GlsMenuDataGroup_T(const std::string &name, GlsMenuDictionary &dataDict, bool uniqueKeys=true)
virtual GlsMenuData * CreateDataItem(const std::string &name) const
GlsMenuDataGroup(const std::string &name)
This file defines menu action (callback) meta-data classes.
GlsMenuDictionary & _dataDict
Data dictionary to pass to items created in the group. This is the dictionary used to evaluate menu d...
T * Item(const std::string &name) const