XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
step_trigger.hpp
Go to the documentation of this file.
1 #ifndef STEP_TRIGGER_HPP
2 #define STEP_TRIGGER_HPP
3 
4 class StepTrigger{
5  bool initialized;
6  int period;
7  int first_step;
8  int last_step;
9 
10  public:
11 
13  : initialized(false) {}
14 
15  StepTrigger(int period, int first_step_in=-1, int last_step_in=-1)
16  : initialized(true),
17  period(period),
18  // If no value is provided for the optional first_step_in argument, then the first step is the period
19  // i.e. if period is 2, then the first call is on step 2
20  first_step(first_step_in==-1 ? period : first_step_in),
21  last_step(last_step_in) {}
22 
23  /* Returns whether or not the action is triggered this step
24  * */
25  bool is_triggered(int step) const{
26  int steps_since_first = step - first_step;
27  return (initialized &&
28  (step>=first_step && steps_since_first%period==0) &&
29  (last_step==-1 || step<=last_step)
30  );
31  }
32 
33  /* Returns whether or not we have passed the first trigger yet
34  * */
35  bool has_been_triggered(int step) const{
36  return (initialized && step>=first_step);
37  }
38 
39  /* Returns period
40  * */
41  int get_period() const{
42  return period;
43  }
44 
50  int trigger_count(int step) const{
51  if (initialized){
52  // C++ rounds down by default
53  return ( (step-first_step)/period );
54  } else {
55  return (0);
56  }
57  }
58 };
59 
60 #endif
StepTrigger(int period, int first_step_in=-1, int last_step_in=-1)
Definition: step_trigger.hpp:15
bool has_been_triggered(int step) const
Definition: step_trigger.hpp:35
int period
Number of steps between trigger.
Definition: step_trigger.hpp:6
bool initialized
Definition: step_trigger.hpp:5
StepTrigger()
Definition: step_trigger.hpp:12
int first_step
First step it can be called.
Definition: step_trigger.hpp:7
int trigger_count(int step) const
Definition: step_trigger.hpp:50
bool is_triggered(int step) const
Definition: step_trigger.hpp:25
int get_period() const
Definition: step_trigger.hpp:41
int last_step
Last step it can be called.
Definition: step_trigger.hpp:8
Definition: step_trigger.hpp:4