SyDEVS  v0.6.6
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
time_point.h
Go to the documentation of this file.
1 #pragma once
2 #ifndef SYDEVS_TIME_POINT_H_
3 #define SYDEVS_TIME_POINT_H_
4 
5 #include <sydevs/core/quantity.h>
6 #include <stdexcept>
7 #include <vector>
8 
9 namespace sydevs {
10 
11 
85 {
86 public:
90  time_point();
91 
103  explicit time_point(duration dt);
104 
105  time_point(const time_point&) = default;
106  time_point& operator=(const time_point&) = default;
107  time_point(time_point&&) = default;
108  time_point& operator=(time_point&&) = default;
109  ~time_point() = default;
110 
111  int64 sign() const;
112  scale precision() const;
113  int64 nscales() const;
114 
115  int64 scale_digit(scale precision) const;
116  int64 scale_phase(scale precision) const;
117  int64 epoch_phase(scale precision) const;
118 
132 
135 
136  const time_point operator+(duration rhs) const;
137  const time_point operator-(duration rhs) const;
138 
152  const duration operator-(const time_point& rhs) const;
153 
168  duration gap(const time_point& rhs) const;
169 
170  bool operator==(const time_point& rhs) const;
171  bool operator!=(const time_point& rhs) const;
172  bool operator<(const time_point& rhs) const;
173  bool operator>(const time_point& rhs) const;
174  bool operator<=(const time_point& rhs) const;
175  bool operator>=(const time_point& rhs) const;
176 
177  bool operator==(duration rhs) const;
178  bool operator!=(duration rhs) const;
179  bool operator<(duration rhs) const;
180  bool operator>(duration rhs) const;
181  bool operator<=(duration rhs) const;
182  bool operator>=(duration rhs) const;
183 
184 private:
185  scale upper_discrepant_precision(const time_point& rhs) const;
186 
187  int8 sign_;
188  scale precision_;
189  std::vector<int16> digits_;
190 };
191 
192 
193 std::ostream& operator<<(std::ostream& os, const time_point& rhs);
194 
195 
196 bool operator==(duration lhs, const time_point& rhs);
197 bool operator!=(duration lhs, const time_point& rhs);
198 bool operator<(duration lhs, const time_point& rhs);
199 bool operator>(duration lhs, const time_point& rhs);
200 bool operator<=(duration lhs, const time_point& rhs);
201 bool operator>=(duration lhs, const time_point& rhs);
202 
203 
204 inline int64 time_point::sign() const
205 {
206  return sign_;
207 }
208 
209 
211 {
212  return precision_;
213 }
214 
215 
217 {
218  return digits_.size();
219 }
220 
221 
222 } // namespace
223 
224 #endif
time_point()
Constructs a zero time_point object.
Definition: time_point.cpp:11
time_point & operator=(const time_point &)=default
Copy assignment.
arraynd< bool, ndims > operator==(const arraynd< T, ndims > &lhs, const arraynd< T, ndims > &rhs)
Definition: arraynd.h:931
bool operator>(const time_point &rhs) const
Returns true if the time_point object is greater than rhs.
Definition: time_point.cpp:293
int64 scale_digit(scale precision) const
Returns the digit associated with the precision scale.
Definition: time_point.cpp:28
std::ostream & operator<<(std::ostream &os, const arraynd< T, ndims > &rhs)
Definition: arraynd.h:1156
int64 nscales() const
Returns the length of the vector of digits.
Definition: time_point.h:216
scale precision() const
Returns the precision of the shortest non-zero digit.
Definition: time_point.h:210
~time_point()=default
Destructor.
bool operator<(const time_point &rhs) const
Returns true if the time_point object is less than rhs.
Definition: time_point.cpp:286
int64 sign() const
Returns the sign (+1 or -1) of the time_point object.
Definition: time_point.h:204
arraynd< bool, ndims > operator>(const arraynd< T, ndims > &lhs, const arraynd< T, ndims > &rhs)
Definition: arraynd.h:901
arraynd< bool, ndims > operator<(const arraynd< T, ndims > &lhs, const arraynd< T, ndims > &rhs)
Definition: arraynd.h:891
A data type which represents the general concept of scale as a dimensionless power of 1000...
Definition: scale.h:70
bool operator>=(const time_point &rhs) const
Returns true if the time_point object is at least rhs.
Definition: time_point.cpp:307
A data structure which represents a point in time as an arbitrary-precision multiple of its shortest ...
Definition: time_point.h:84
int64 epoch_phase(scale precision) const
Returns the 5-scale (epoch) offset from the left.
Definition: time_point.cpp:54
arraynd< bool, ndims > operator<=(const arraynd< T, ndims > &lhs, const arraynd< T, ndims > &rhs)
Definition: arraynd.h:911
int64 scale_phase(scale precision) const
Returns the single-scale offset from the left.
Definition: time_point.cpp:36
bool operator!=(const time_point &rhs) const
Returns true if the time_point object does not equal rhs.
Definition: time_point.cpp:279
arraynd< bool, ndims > operator>=(const arraynd< T, ndims > &lhs, const arraynd< T, ndims > &rhs)
Definition: arraynd.h:921
bool operator<=(const time_point &rhs) const
Returns true if the time_point object is at most rhs.
Definition: time_point.cpp:300
time_point & operator+=(duration rhs)
Modifies the time_point object by adding the duration rhs.
Definition: time_point.cpp:100
time_point & advance(duration rhs)
Advances the time_point object by the specified duration.
Definition: time_point.cpp:75
const time_point operator+(duration rhs) const
Returns a new time_point with duration rhs added.
Definition: time_point.cpp:191
arraynd< bool, ndims > operator!=(const arraynd< T, ndims > &lhs, const arraynd< T, ndims > &rhs)
Definition: arraynd.h:941
const time_point operator-(duration rhs) const
Returns a new time_point with duration rhs subtracted.
Definition: time_point.cpp:199
duration gap(const time_point &rhs) const
Approximates the difference between the time_point object and time_point rhs.
Definition: time_point.cpp:226
time_point & operator-=(duration rhs)
Modifies the time_point object by subtracting the duration rhs.
Definition: time_point.cpp:184
int8_t int8
Definition: number_types.h:11
bool operator==(const time_point &rhs) const
Returns true if the time_point object equals rhs.
Definition: time_point.cpp:272