GlsMenu
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 <string>
48 #include <iomanip>
49 
50 #include "gls_menu_data.h"
51 #include "gls_menu_action.h"
52 #include "gls_menu_dictionary.h"
53 
54 
55 //============================================================================
61 //============================================================================
63 {
64 public:
65 
66  //------------------------------------------------------------------------
70  //------------------------------------------------------------------------
71  virtual ~GlsMenuDataGroup();
72 
73  //------------------------------------------------------------------------
79  //------------------------------------------------------------------------
80  const GlsMenuDictionary& Attributes() const { return _attr; }
81 
82  //------------------------------------------------------------------------
88  //------------------------------------------------------------------------
89  virtual std::istream& ReadValue(std::istream& instr);
90 
91  //------------------------------------------------------------------------
97  //------------------------------------------------------------------------
98  virtual std::ostream& WriteValue(std::ostream& outstr);
99 
100 protected:
101 
104 
105  //------------------------------------------------------------------------
109  //------------------------------------------------------------------------
110  GlsMenuDataGroup(const std::string& name);
111 
112 }; // end GlsMenuDataGroup
113 
114 
115 //============================================================================
124 //============================================================================
126 {
127 public:
128 
129  //------------------------------------------------------------------------
135  //------------------------------------------------------------------------
136  GlsMenuDynDataGroup(const std::string& name, bool uniqueKeys = true);
137 
138  //------------------------------------------------------------------------
142  //------------------------------------------------------------------------
143  virtual ~GlsMenuDynDataGroup();
144 
145  //------------------------------------------------------------------------
151  //------------------------------------------------------------------------
152  virtual std::istream& ReadValue(std::istream& instr);
153 
154 protected:
155 
158 
159  //------------------------------------------------------------------------
167  //------------------------------------------------------------------------
168  virtual GlsMenuData* CreateDataItem(const std::string& name) const = 0;
169 
170 }; // end GlsMenuDynDataGroup
171 
172 
173 //============================================================================
182 //============================================================================
183 template <class T>
185 {
186 public:
187 
188  //------------------------------------------------------------------------
196  //------------------------------------------------------------------------
197  GlsMenuDataGroup_T(const std::string& name,
198  GlsMenuDictionary& dataDict,
199  bool uniqueKeys = true) :
200  GlsMenuDynDataGroup(name, uniqueKeys),
201  _dataDict(dataDict)
202  {
203  }
204 
205  //------------------------------------------------------------------------
209  //------------------------------------------------------------------------
210  virtual ~GlsMenuDataGroup_T() {}
211 
212  //------------------------------------------------------------------------
221  //------------------------------------------------------------------------
222  T* Item(const std::string& name) const
223  {
224  return dynamic_cast<T*>(_attr.Get(disti::AttributeName(name)));
225  }
226 
227 protected:
228 
232 
233  //------------------------------------------------------------------------
242  //------------------------------------------------------------------------
243  virtual GlsMenuData* CreateDataItem(const std::string& name) const
244  {
245  return static_cast<GlsMenuData*>(new T(name, _dataDict));
246  }
247 
248 }; // end GlsMenuDataGroup_T
249 
250 
251 //============================================================================
260 //============================================================================
261 template <class T>
263 {
264 public:
265 
266  //------------------------------------------------------------------------
277  //------------------------------------------------------------------------
278  GlsMenuHandlerGroup_T(const std::string& name,
279  GlsMenuDictionary& dataDict,
280  GlsMenuAction::HandlerCont_t& actionHandlers,
281  bool uniqueKeys = true) :
282  GlsMenuDynDataGroup(name, uniqueKeys),
283  _dataDict(dataDict),
284  _handlers(actionHandlers)
285  {
286  }
287 
288  //------------------------------------------------------------------------
292  //------------------------------------------------------------------------
294 
295  //------------------------------------------------------------------------
304  //------------------------------------------------------------------------
305  T* Item(const std::string& name) const
306  {
307  return dynamic_cast<T*>(_attr.Get(disti::AttributeName(name)));
308  }
309 
310 protected:
311 
315 
316  // Action/Handler pairs passed in from the creator to pass to items
317  // created in the group.
319 
320  //------------------------------------------------------------------------
330  //------------------------------------------------------------------------
331  virtual GlsMenuData* CreateDataItem(const std::string& name) const
332  {
333  return static_cast<GlsMenuData*>(new T(name, _dataDict, _handlers));
334  }
335 
336 }; // end GlsMenuHandlerGroup_T
337 
338 #endif
339 
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