GlsMenu
gls_menu_action.h
Go to the documentation of this file.
1 
41 #if !defined(GLS_MENUACTION_H)
42 #define GLS_MENUACTION_H
43 
44 #ifdef WIN32
45 #pragma warning (disable:4786)
46 #endif
47 #include <stdio.h>
48 #include <iostream>
49 #include <string>
50 
51 #include "gls_functor.h"
52 #include "gls_bool_expression.h"
53 #include "gls_menu_dictionary.h"
54 #include "gls_menu_data.h"
55 #include "timer.h"
56 
57 //----------------------------------------------------------------------------
58 
59 //============================================================================
70 //============================================================================
71 class GlsMenuAction : public GlsMenuLine
72 {
73 public:
74 
75  // Type of handler to perform menu actions. All actions will accept
76  // a stream from which arguments can be streamed out of.
78 
79  typedef std::map<std::string, ActionHandler_t*> HandlerCont_t;
80 
81  //------------------------------------------------------------------------
91  //------------------------------------------------------------------------
93  const std::string& name,
94  GlsMenuDictionary& dataDict,
95  HandlerCont_t& actionHandlers);
96 
97  //------------------------------------------------------------------------
101  //------------------------------------------------------------------------
102  virtual ~GlsMenuAction();
103 
104  //------------------------------------------------------------------------
111  //------------------------------------------------------------------------
112  virtual void Execute() const;
113 
114  //------------------------------------------------------------------------
121  //------------------------------------------------------------------------
122  static void Register(const std::string& name, ActionHandler_t* handler);
123 
124 protected:
125 
127 
128  //------------------------------------------------------------------------
134  //------------------------------------------------------------------------
135  bool CanExecute(std::string& statement) const;
136 
137 
138 protected:
139 
140  // Action/Handler pairs passed in from creator (considered local)
141  HandlerCont_t& _localHandlers;
142 
143  // Action/Handler pairs globally registered
144  static HandlerCont_t _globalHandlers;
145 
146 }; // end GlsMenuAction
147 
148 
149 
150 //============================================================================
182 //============================================================================
184 {
185 public:
186 
187  //------------------------------------------------------------------------
197  //------------------------------------------------------------------------
199  const std::string& name,
200  GlsMenuDictionary& dataDict,
201  GlsMenuAction::HandlerCont_t& actionHandlers);
202 
203  //------------------------------------------------------------------------
207  //------------------------------------------------------------------------
208  virtual ~GlsMenuActionGroup();
209 
210  //------------------------------------------------------------------------
215  //------------------------------------------------------------------------
216  void Condition(const std::string& expression);
217 
218  //------------------------------------------------------------------------
225  //------------------------------------------------------------------------
226  virtual void Execute() const;
227 
228  //------------------------------------------------------------------------
234  //------------------------------------------------------------------------
235  virtual std::istream& ReadValue(std::istream& instr);
236 
237  //------------------------------------------------------------------------
243  //------------------------------------------------------------------------
244  virtual std::ostream& WriteValue(std::ostream& outstr);
245 
246 protected:
247 
249  std::list<GlsMenuAction*> _actions;
250 
253 
256 
257 }; // end GlsMenuActionGroup
258 
259 
260 
261 
262 //============================================================================
267 //============================================================================
269 {
270 
271 public:
272 
273  // A type for micro seconds
274  typedef unsigned long Microsecs_t;
275 
276  enum {MICROSECS_PER_SEC = 1000000};
277 
278 
279  //------------------------------------------------------------------------
289  //------------------------------------------------------------------------
290  GlsMenuTimer(
291  const std::string& name,
292  GlsMenuDictionary& dataDict,
293  GlsMenuAction::HandlerCont_t& actionHandlers);
294 
295  //------------------------------------------------------------------------
299  //------------------------------------------------------------------------
300  virtual ~GlsMenuTimer();
301 
302  //------------------------------------------------------------------------
307  //------------------------------------------------------------------------
308  void Reset();
309 
310  //------------------------------------------------------------------------
317  //------------------------------------------------------------------------
318  void Reset(double durationInSecs);
319 
320  //------------------------------------------------------------------------
325  //------------------------------------------------------------------------
326  void Start();
327 
328  //------------------------------------------------------------------------
333  //------------------------------------------------------------------------
334  void Stop();
335 
336  //------------------------------------------------------------------------
340  //------------------------------------------------------------------------
341  bool IsExpired() const;
342 
343  //------------------------------------------------------------------------
347  //------------------------------------------------------------------------
348  double Duration() const;
349 
350 
351 protected:
352 
354  disti::Timer _stopWatch;
355 
358  bool _active;
359 
362  Microsecs_t _elapsedMicroseconds;
363 
365  Microsecs_t _duration;
366 };
367 
368 
369 #endif
370 
GlsMenuActionGroup(const std::string &name, GlsMenuDictionary &dataDict, GlsMenuAction::HandlerCont_t &actionHandlers)
This file defines all menu meta-data classes.
std::list< GlsMenuAction * > _actions
List of actions to execute if condition is true.
HandlerCont_t & _localHandlers
This file defines a meta-data dictionary class.
double Duration() const
GlsMenuTimer(const std::string &name, GlsMenuDictionary &dataDict, GlsMenuAction::HandlerCont_t &actionHandlers)
bool IsExpired() const
static HandlerCont_t _globalHandlers
virtual ~GlsMenuActionGroup()
GlsMenuDictionary & _dataDict
GlsMenuAction(const std::string &name, GlsMenuDictionary &dataDict, HandlerCont_t &actionHandlers)
virtual void Execute() const
GlsBoolExpression _condition
Condition to check for true before executing all actions.
std::map< std::string, ActionHandler_t * > HandlerCont_t
GlsFunctor1_T< std::istream & > ActionHandler_t
void Condition(const std::string &expression)
virtual std::ostream & WriteValue(std::ostream &outstr)
Microsecs_t _elapsedMicroseconds
Stored elapsed time whenever the timer is stopped. This is incremented by the stop watches time whene...
bool _conditionIsSet
This is set to true when the condition is set using the Condition method.
virtual std::istream & ReadValue(std::istream &instr)
bool _active
Whether or not the timer is actively running and incrementing its elapsed time.
Microsecs_t _duration
Time duration after which the timer will be expired.
This file defines generic function object (functor) classes.
virtual void Execute() const
disti::Timer _stopWatch
A stop watch used to count elapsed time.
This file defines a class that provides a string-based boolean expression parser and evaluator...
virtual ~GlsMenuAction()
bool CanExecute(std::string &statement) const
virtual ~GlsMenuTimer()
unsigned long Microsecs_t
static void Register(const std::string &name, ActionHandler_t *handler)