GlsMenu
gls_mfd_menu.h
Go to the documentation of this file.
1 
42 #if !defined(GLS_MFDMENU_H)
43 #define GLS_MFDMENU_H
44 
45 #ifdef WIN32
46 #pragma warning (disable:4786)
47 #endif
48 
49 #include <string>
50 
51 #include "gls_menu.h"
52 #include "gls_mfd.h"
53 #include "gls_menu_data.h"
54 #include "gls_bool_expression.h"
55 
56 
57 //----------------------------------------------------------------------------
67 //----------------------------------------------------------------------------
68 template <class MenuItemId_t>
70 {
71 public:
72 
73  //------------------------------------------------------------------------
77  //------------------------------------------------------------------------
78  GlsMFDSubmenu_T(const std::string& name, GlsMenuDictionary& dataDict) :
79  GlsMenuDataGroup(name),
80  _dataDict(dataDict),
81  _visible(dataDict, true),
82  _showLabel(dataDict, true)
83  {
84  _attr.Add(new GlsMenuData_T<MenuItemId_t> ("Begin", &_begin));
85  _attr.Add(new GlsMenuData_T<MenuItemId_t> ("End", &_end));
86  _attr.Add(new GlsMenuData_T<GlsBoolExpression>("Visible", &_visible));
87  _attr.Add(new GlsMenuData_T<GlsBoolExpression>("ShowLabel", &_showLabel));
88  }
89 
90  //------------------------------------------------------------------------
94  //------------------------------------------------------------------------
95  virtual ~GlsMFDSubmenu_T() {}
96 
97  //------------------------------------------------------------------------
101  //------------------------------------------------------------------------
102  MenuItemId_t Begin() { return _begin; }
103 
104  //------------------------------------------------------------------------
108  //------------------------------------------------------------------------
109  MenuItemId_t End() { return _end; }
110 
111  //------------------------------------------------------------------------
115  //------------------------------------------------------------------------
116  bool ShowLabel() { return _showLabel(); }
117 
118  //------------------------------------------------------------------------
122  //------------------------------------------------------------------------
123  std::string Label()
124  {
125  return _showLabel() ?
126  _dataDict.Expand(Name()) : "";
127  }
128 
129  //------------------------------------------------------------------------
133  //------------------------------------------------------------------------
134  bool Visible() { return _visible(); }
135 
136 
137 protected:
138 
141 
143  MenuItemId_t _begin;
144 
146  MenuItemId_t _end;
147 
150 
153 
154 }; // end GlsMFDSubmenu_T
155 
156 
157 //----------------------------------------------------------------------------
164 //----------------------------------------------------------------------------
165 template <class MenuItem_t, class Submenu_t, class PageId_t>
166 class GlsMFDMenu_T : public GlsMenu_T<MenuItem_t, GlsMFD::MenuItemId_t>
167 {
168 public:
169 
172  typedef std::vector<Submenu_t*> SubmenuCont_t;
173 
174  //------------------------------------------------------------------------
178  //------------------------------------------------------------------------
180  const std::string& name,
181  GlsMenuDictionary& dataDict,
182  GlsMenuAction::HandlerCont_t& actionHandlers) :
183 
184  BaseClass(name, dataDict, actionHandlers),
185  _page(PageId_t(0))
186  {
188  BaseClass::_attr.Add(new SubmenuGroup_t("Submenus", dataDict));
189  }
190 
191  //------------------------------------------------------------------------
195  //------------------------------------------------------------------------
196  virtual ~GlsMFDMenu_T() {}
197 
198  //------------------------------------------------------------------------
202  //------------------------------------------------------------------------
203  PageId_t Page() const
204  {
205  return _page;
206  }
207 
208  //------------------------------------------------------------------------
212  //------------------------------------------------------------------------
213  virtual std::istream& ReadValue(std::istream& instr)
214  {
215  static const disti::AttributeName SUBMENUS("Submenus");
216  BaseClass::ReadValue(instr);
217  _submenus.clear();
218 
219  SubmenuGroup_t* submenus =
220  dynamic_cast<SubmenuGroup_t*>(BaseClass::_attr.Get(SUBMENUS));
221 
222  if (submenus)
223  {
224  GlsMenuDictionary::const_iterator submenuIt;
225  for (submenuIt = submenus->Attributes().Begin();
226  submenuIt != submenus->Attributes().End();
227  ++submenuIt)
228  {
229  Submenu_t* submenu = dynamic_cast<Submenu_t*>(*submenuIt);
230  if (submenu)
231  {
232  _submenus.push_back(submenu);
233  }
234  }
235  }
236 
237  return instr;
238  }
239 
240  //------------------------------------------------------------------------
246  //------------------------------------------------------------------------
247  const SubmenuCont_t& Submenus() const
248  {
249  return _submenus;
250  }
251 
252 protected:
253 
254  // MFD display associated with this menu.
255  PageId_t _page;
256 
257  // Container of submenus
258  SubmenuCont_t _submenus;
259 
260 }; // end GlsMFDMenu
261 
262 
263 #endif // GLS_MFDMENU_H
This file defines all menu meta-data classes.
virtual std::istream & ReadValue(std::istream &instr)
Definition: gls_mfd_menu.h:213
GlsBoolExpression _visible
Determines if the submenu is visible at any given instance.
Definition: gls_mfd_menu.h:149
MenuItemId_t _end
Ending menu item of the submenu.
Definition: gls_mfd_menu.h:146
std::string Label()
Definition: gls_mfd_menu.h:123
This file defines a class that provides a generic menu class.
GlsMenuDictionary _attr
The dictionary of attributes for the group attribute.
GlsMenuDictionary & _dataDict
Data dictionary for looking up menu variables.
Definition: gls_mfd_menu.h:140
PageId_t _page
Definition: gls_mfd_menu.h:255
std::map< std::string, ActionHandler_t * > HandlerCont_t
SubmenuCont_t _submenus
Definition: gls_mfd_menu.h:258
PageId_t Page() const
Definition: gls_mfd_menu.h:203
const GlsMenuDictionary & Attributes() const
std::string Name(Side_t side)
Definition: gls_mfd.h:81
std::vector< Submenu_t * > SubmenuCont_t
Definition: gls_mfd_menu.h:172
const SubmenuCont_t & Submenus() const
Definition: gls_mfd_menu.h:247
virtual std::istream & ReadValue(std::istream &instr)
MenuItemId_t End()
Definition: gls_mfd_menu.h:109
MenuItemId_t Begin()
Definition: gls_mfd_menu.h:102
GlsMFDSubmenu_T(const std::string &name, GlsMenuDictionary &dataDict)
Definition: gls_mfd_menu.h:78
GlsMenu_T< MenuItem_t, GlsMFD::MenuItemId_t > BaseClass
Definition: gls_mfd_menu.h:170
GlsMenuDataGroup_T< Submenu_t > SubmenuGroup_t
Definition: gls_mfd_menu.h:171
virtual ~GlsMFDMenu_T()
Definition: gls_mfd_menu.h:196
GlsBoolExpression _showLabel
Determines if the submenu label should be shown at any given instance.
Definition: gls_mfd_menu.h:152
virtual ~GlsMFDSubmenu_T()
Definition: gls_mfd_menu.h:95
This file defines a class that provides a string-based boolean expression parser and evaluator...
This file defines common MFD types.
MenuItemId_t _begin
Starting menu item of the submenu.
Definition: gls_mfd_menu.h:143
GlsMFDMenu_T(const std::string &name, GlsMenuDictionary &dataDict, GlsMenuAction::HandlerCont_t &actionHandlers)
Definition: gls_mfd_menu.h:179
std::string Expand(const std::string &str, const char *startDelim="$(", const char *endDelim=")")