GlsMenu
gls_mfd_menu.h
Go to the documentation of this file.
1 
41 #if !defined( GLS_MFDMENU_H )
42 # define GLS_MFDMENU_H
43 
44 # ifdef WIN32
45 # pragma warning( disable : 4786 )
46 # endif
47 
48 # include <string>
49 
50 # include "gls_bool_expression.h"
51 # include "gls_menu.h"
52 # include "gls_menu_data.h"
53 # include "gls_mfd.h"
54 
55 //----------------------------------------------------------------------------
65 //----------------------------------------------------------------------------
66 template<class MenuItemId_t>
68 {
69 public:
70  //------------------------------------------------------------------------
74  //------------------------------------------------------------------------
75  GlsMFDSubmenu_T( const std::string& name, GlsMenuDictionary& dataDict )
76  : GlsMenuDataGroup( name )
77  , _dataDict( dataDict )
78  , _visible( dataDict, true )
79  , _showLabel( dataDict, true )
80  {
81  _attr.Add( new GlsMenuData_T<MenuItemId_t>( "Begin", &_begin ) );
82  _attr.Add( new GlsMenuData_T<MenuItemId_t>( "End", &_end ) );
83  _attr.Add( new GlsMenuData_T<GlsBoolExpression>( "Visible", &_visible ) );
84  _attr.Add( new GlsMenuData_T<GlsBoolExpression>( "ShowLabel", &_showLabel ) );
85  }
86 
87  //------------------------------------------------------------------------
91  //------------------------------------------------------------------------
92  virtual ~GlsMFDSubmenu_T() {}
93 
94  //------------------------------------------------------------------------
98  //------------------------------------------------------------------------
99  MenuItemId_t Begin() { return _begin; }
100 
101  //------------------------------------------------------------------------
105  //------------------------------------------------------------------------
106  MenuItemId_t End() { return _end; }
107 
108  //------------------------------------------------------------------------
112  //------------------------------------------------------------------------
113  bool ShowLabel() { return _showLabel(); }
114 
115  //------------------------------------------------------------------------
119  //------------------------------------------------------------------------
120  std::string Label()
121  {
122  return _showLabel() ? _dataDict.Expand( Name() ) : "";
123  }
124 
125  //------------------------------------------------------------------------
129  //------------------------------------------------------------------------
130  bool Visible() { return _visible(); }
131 
132 protected:
135 
137  MenuItemId_t _begin;
138 
140  MenuItemId_t _end;
141 
144 
147 
148 }; // end GlsMFDSubmenu_T
149 
150 //----------------------------------------------------------------------------
157 //----------------------------------------------------------------------------
158 template<class MenuItem_t, class Submenu_t, class PageId_t>
159 class GlsMFDMenu_T : public GlsMenu_T<MenuItem_t, GlsMFD::MenuItemId_t>
160 {
161 public:
164  typedef std::vector<Submenu_t*> SubmenuCont_t;
165 
166  //------------------------------------------------------------------------
170  //------------------------------------------------------------------------
172  const std::string& name,
173  GlsMenuDictionary& dataDict,
174  GlsMenuAction::HandlerCont_t& actionHandlers )
175  :
176 
177  BaseClass( name, dataDict, actionHandlers )
178  , _page( PageId_t( 0 ) )
179  {
181  BaseClass::_attr.Add( new SubmenuGroup_t( "Submenus", dataDict ) );
182  }
183 
184  //------------------------------------------------------------------------
188  //------------------------------------------------------------------------
189  virtual ~GlsMFDMenu_T() {}
190 
191  //------------------------------------------------------------------------
195  //------------------------------------------------------------------------
196  PageId_t Page() const
197  {
198  return _page;
199  }
200 
201  //------------------------------------------------------------------------
205  //------------------------------------------------------------------------
206  virtual std::istream& ReadValue( std::istream& instr )
207  {
208  static const disti::AttributeName SUBMENUS( "Submenus" );
209  BaseClass::ReadValue( instr );
210  _submenus.clear();
211 
212  SubmenuGroup_t* submenus = dynamic_cast<SubmenuGroup_t*>( BaseClass::_attr.Get( SUBMENUS ) );
213 
214  if( submenus )
215  {
217  for( submenuIt = submenus->Attributes().Begin();
218  submenuIt != submenus->Attributes().End();
219  ++submenuIt )
220  {
221  Submenu_t* submenu = dynamic_cast<Submenu_t*>( *submenuIt );
222  if( submenu )
223  {
224  _submenus.push_back( submenu );
225  }
226  }
227  }
228 
229  return instr;
230  }
231 
232  //------------------------------------------------------------------------
238  //------------------------------------------------------------------------
239  const SubmenuCont_t& Submenus() const
240  {
241  return _submenus;
242  }
243 
244 protected:
245  // MFD display associated with this menu.
246  PageId_t _page;
247 
248  // Container of submenus
249  SubmenuCont_t _submenus;
250 
251 }; // end GlsMFDMenu
252 
253 #endif // GLS_MFDMENU_H
This file defines all menu meta-data classes.
virtual std::istream & ReadValue(std::istream &instr)
Definition: gls_mfd_menu.h:206
GlsBoolExpression _visible
Determines if the submenu is visible at any given instance.
Definition: gls_mfd_menu.h:143
MenuItemId_t _end
Ending menu item of the submenu.
Definition: gls_mfd_menu.h:140
std::string Label()
Definition: gls_mfd_menu.h:120
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:134
const_iterator Begin() const
PageId_t _page
Definition: gls_mfd_menu.h:246
virtual void Add(disti::DistiAttributeBase *attr)
const_iterator End() const
disti::DistiAttribDict::const_iterator const_iterator
std::map< std::string, ActionHandler_t * > HandlerCont_t
virtual disti::DistiAttributeBase * Get(const disti::AttributeName &name) const
SubmenuCont_t _submenus
Definition: gls_mfd_menu.h:249
PageId_t Page() const
Definition: gls_mfd_menu.h:196
const GlsMenuDictionary & Attributes() const
std::string Name(Side_t side)
Definition: gls_mfd.h:90
std::vector< Submenu_t * > SubmenuCont_t
Definition: gls_mfd_menu.h:164
const SubmenuCont_t & Submenus() const
Definition: gls_mfd_menu.h:239
virtual std::istream & ReadValue(std::istream &instr)
MenuItemId_t End()
Definition: gls_mfd_menu.h:106
MenuItemId_t Begin()
Definition: gls_mfd_menu.h:99
GlsMFDSubmenu_T(const std::string &name, GlsMenuDictionary &dataDict)
Definition: gls_mfd_menu.h:75
GlsMenu_T< MenuItem_t, GlsMFD::MenuItemId_t > BaseClass
Definition: gls_mfd_menu.h:162
GlsMenuDataGroup_T< Submenu_t > SubmenuGroup_t
Definition: gls_mfd_menu.h:163
virtual ~GlsMFDMenu_T()
Definition: gls_mfd_menu.h:189
GlsBoolExpression _showLabel
Determines if the submenu label should be shown at any given instance.
Definition: gls_mfd_menu.h:146
virtual ~GlsMFDSubmenu_T()
Definition: gls_mfd_menu.h:92
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:137
GlsMFDMenu_T(const std::string &name, GlsMenuDictionary &dataDict, GlsMenuAction::HandlerCont_t &actionHandlers)
Definition: gls_mfd_menu.h:171
std::string Expand(const std::string &str, const char *startDelim="$(", const char *endDelim=")")