SyDEVS  v0.6.7
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
discrete_event_time.h
Go to the documentation of this file.
1 #pragma once
2 #ifndef SYDEVS_SYSTEMS_DISCRETE_EVENT_TIME_H_
3 #define SYDEVS_SYSTEMS_DISCRETE_EVENT_TIME_H_
4 
6 
7 namespace sydevs {
8 namespace systems {
9 
10 
37 {
38 public:
44 
50 
56 
57  discrete_event_time(const discrete_event_time&) = default;
61  virtual ~discrete_event_time() = default;
62 
63  const time_point& t() const;
64  int64 t_index() const;
65  int64 c() const;
66 
67  void advance(duration dt, const time_point& end_t);
68  void advance();
69 
70 private:
71  time_point t_;
72  int64 t_index_;
73  int64 c_;
74 };
75 
76 
78  : t_()
79  , t_index_(0)
80  , c_(0)
81 {
82 }
83 
84 
86  : t_(t)
87  , t_index_(0)
88  , c_(0)
89 {
90 }
91 
92 
94  : t_(t)
95  , t_index_(0)
96  , c_(c)
97 {
98 }
99 
100 
101 inline const time_point& discrete_event_time::t() const
102 {
103  return t_;
104 }
105 
106 
108 {
109  return t_index_;
110 }
111 
112 
114 {
115  return c_;
116 }
117 
118 
119 inline void discrete_event_time::advance(duration dt, const time_point& end_t)
120 {
121  if (dt == 0_s) {
122  ++c_;
123  }
124  else {
125  if (dt.finite()) {
126  t_.advance(dt);
127  if (t_ > end_t) {
128  t_ = end_t;
129  }
130  }
131  else {
132  t_ = end_t;
133  }
134  ++t_index_;
135  c_ = 0;
136  }
137 }
138 
139 
141 {
142  c_++;
143 }
144 
145 
146 } // namespace
147 } // namespace
148 
149 #endif
int64 t_index() const
Return the index associated with the current point in simulated time.
Definition: discrete_event_time.h:107
A data structure which represents progress through a simulation, encapsulating both simulated time an...
Definition: discrete_event_time.h:36
void advance()
Advance the counter without changing simulated time point.
Definition: discrete_event_time.h:140
const time_point & t() const
Return the current point in simulated time.
Definition: discrete_event_time.h:101
constexpr auto _s
Definition: units.h:128
constexpr bool finite() const
Returns true if the quantity value is finite.
Definition: quantity.h:395
int64 c() const
Return the counter value of associated with the current point in simulated time.
Definition: discrete_event_time.h:113
A data structure which represents a point in time as an arbitrary-precision multiple of its shortest ...
Definition: time_point.h:84
virtual ~discrete_event_time()=default
Destructor.
discrete_event_time()
Constructs a discrete_event_time object starting at time zero and a counter value of zero...
Definition: discrete_event_time.h:77
time_point & advance(duration rhs)
Advances the time_point object by the specified duration.
Definition: time_point.cpp:75
discrete_event_time & operator=(const discrete_event_time &)=default
Copy assignment.