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 
9  public:
10 
12  : initialized(false) {}
13 
14  StepTrigger(int period, int first_step_in=-1)
15  : initialized(true),
16  period(period),
17  // If no value is provided for the optional first_step_in argument, then the first step is the period
18  // i.e. if period is 2, then the first call is on step 2
19  first_step(first_step_in==-1 ? period : first_step_in) {}
20 
21  /* Returns whether or not the action is triggered this step
22  * */
23  bool is_triggered(int step){
24  int steps_since_first = step - first_step;
25  return (initialized && (step>=first_step && steps_since_first%period==0));
26  }
27 
28  /* Returns whether or not we have passed the first trigger yet
29  * */
30  bool has_been_triggered(int step){
31  return (initialized && step>=first_step);
32  }
33 
39  int trigger_count(int step){
40  if (initialized){
41  // C++ rounds down by default
42  return ( (step-first_step)/period );
43  } else {
44  return (0);
45  }
46  }
47 };
48 
49 #endif
bool has_been_triggered(int step)
Definition: step_trigger.hpp:30
int period
Number of steps between trigger.
Definition: step_trigger.hpp:6
bool initialized
Definition: step_trigger.hpp:5
StepTrigger()
Definition: step_trigger.hpp:11
int first_step
First step it can be called.
Definition: step_trigger.hpp:7
StepTrigger(int period, int first_step_in=-1)
Definition: step_trigger.hpp:14
int trigger_count(int step)
Definition: step_trigger.hpp:39
bool is_triggered(int step)
Definition: step_trigger.hpp:23
Definition: step_trigger.hpp:4