GlsMenu  1.5.4
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 <iostream>
48 # include <stdio.h>
49 # include <string>
50 
51 # include "gls_bool_expression.h"
52 # include "gls_functor.h"
53 # include "gls_menu_data.h"
54 # include "gls_menu_dictionary.h"
55 # include "timer.h"
56 
57 //----------------------------------------------------------------------------
58 
59 //============================================================================
70 //============================================================================
71 class GlsMenuAction : public GlsMenuLine
72 {
73 public:
74  // Type of handler to perform menu actions. All actions will accept
75  // a stream from which arguments can be streamed out of.
77 
78  typedef std::map<std::string, ActionHandler_t*> HandlerCont_t;
79 
80  //------------------------------------------------------------------------
90  //------------------------------------------------------------------------
92  const std::string& name,
93  GlsMenuDictionary& dataDict,
94  HandlerCont_t& actionHandlers );
95 
96  //------------------------------------------------------------------------
100  //------------------------------------------------------------------------
101  virtual ~GlsMenuAction();
102 
103  //------------------------------------------------------------------------
110  //------------------------------------------------------------------------
111  virtual void Execute() const;
112 
113  //------------------------------------------------------------------------
120  //------------------------------------------------------------------------
121  static void Register( const std::string& name, ActionHandler_t* handler );
122 
123 protected:
125 
126  //------------------------------------------------------------------------
132  //------------------------------------------------------------------------
133  bool CanExecute( std::string& statement ) const;
134 
135 protected:
136  // Action/Handler pairs passed in from creator (considered local)
137  HandlerCont_t& _localHandlers;
138 
139  // Action/Handler pairs globally registered
140  static HandlerCont_t _globalHandlers;
141 
142 }; // end GlsMenuAction
143 
144 //============================================================================
176 //============================================================================
178 {
179 public:
180  //------------------------------------------------------------------------
190  //------------------------------------------------------------------------
192  const std::string& name,
193  GlsMenuDictionary& dataDict,
194  GlsMenuAction::HandlerCont_t& actionHandlers );
195 
196  //------------------------------------------------------------------------
200  //------------------------------------------------------------------------
201  virtual ~GlsMenuActionGroup();
202 
203  //------------------------------------------------------------------------
208  //------------------------------------------------------------------------
209  void Condition( const std::string& expression );
210 
211  //------------------------------------------------------------------------
218  //------------------------------------------------------------------------
219  virtual void Execute() const;
220 
221  //------------------------------------------------------------------------
227  //------------------------------------------------------------------------
228  virtual std::istream& ReadValue( std::istream& instr );
229 
230  //------------------------------------------------------------------------
236  //------------------------------------------------------------------------
237  virtual std::ostream& WriteValue( std::ostream& outstr );
238 
239 protected:
241  std::list<GlsMenuAction*> _actions;
242 
245 
248 
249 }; // end GlsMenuActionGroup
250 
251 //============================================================================
256 //============================================================================
258 {
259 public:
260  // A type for micro seconds
261  typedef unsigned long Microsecs_t;
262 
263  enum
264  {
266  };
267 
268  //------------------------------------------------------------------------
278  //------------------------------------------------------------------------
279  GlsMenuTimer(
280  const std::string& name,
281  GlsMenuDictionary& dataDict,
282  GlsMenuAction::HandlerCont_t& actionHandlers );
283 
284  //------------------------------------------------------------------------
288  //------------------------------------------------------------------------
289  virtual ~GlsMenuTimer();
290 
291  //------------------------------------------------------------------------
296  //------------------------------------------------------------------------
297  void Reset();
298 
299  //------------------------------------------------------------------------
306  //------------------------------------------------------------------------
307  void Reset( double durationInSecs );
308 
309  //------------------------------------------------------------------------
314  //------------------------------------------------------------------------
315  void Start();
316 
317  //------------------------------------------------------------------------
322  //------------------------------------------------------------------------
323  void Stop();
324 
325  //------------------------------------------------------------------------
329  //------------------------------------------------------------------------
330  bool IsExpired() const;
331 
332  //------------------------------------------------------------------------
336  //------------------------------------------------------------------------
337  double Duration() const;
338 
339 protected:
341  disti::Timer _stopWatch;
342 
345  bool _active;
346 
349  Microsecs_t _elapsedMicroseconds;
350 
352  Microsecs_t _duration;
353 };
354 
355 #endif
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)