adevs
adevs_time.h
Go to the documentation of this file.
1 #ifndef _adevs_time_h_
2 #define _adevs_time_h_
3 #include <limits>
4 
13 namespace adevs
14 {
15 
24 template <typename RealType>
26 {
27  public:
29  RealType real;
31  int logical;
35  SuperDenseTime(RealType real, int logical):real(real),logical(logical){}
44  {
46  real+h.real,logical*(h.real==RealType(0))+h.logical);
47  }
53  {
54  if (real == preceding.real)
55  return SuperDenseTime<RealType>(RealType(0),logical-preceding.logical);
56  return SuperDenseTime<RealType>(real-preceding.real,logical);
57  }
59  bool operator<(const SuperDenseTime<RealType>& other) const
60  {
61  return (real < other.real) ||
62  ((real == other.real) && (logical < other.logical));
63  }
65  bool operator<=(const SuperDenseTime<RealType>& other) const
66  {
67  return (real < other.real) ||
68  ((real == other.real) && (logical <= other.logical));
69  }
71  bool operator==(const SuperDenseTime<RealType>& other) const
72  {
73  return (real == other.real && logical == other.logical);
74  }
75 };
76 
79 
80 };
81 
87 template <class T> inline T adevs_inf();
88 template <> inline adevs::SuperDenseTime<int> adevs_inf() {
90  std::numeric_limits<int>::max(),
91  std::numeric_limits<int>::max());
92 }
93 template <class T> inline T adevs_inf();
94 template <> inline adevs::SuperDenseTime<long> adevs_inf() {
96  std::numeric_limits<long>::max(),
97  std::numeric_limits<int>::max());
98 }
101  std::numeric_limits<double>::infinity(),
102  std::numeric_limits<int>::max());
103 }
104 template <> inline int adevs_inf() {
105  return std::numeric_limits<int>::max();
106 }
107 
113 template <typename T> inline T adevs_zero();
115  return adevs::SuperDenseTime<int>(0,0);
116 }
118  return adevs::SuperDenseTime<long>(0,0);
119 }
121  return adevs::SuperDenseTime<double>(0.0,0);
122 }
123 template <> inline int adevs_zero() { return 0; }
129 template <class T> inline T adevs_epsilon();
131  return adevs::SuperDenseTime<int>(0,1);
132 }
134  return adevs::SuperDenseTime<long>(0,1);
135 }
137  return adevs::SuperDenseTime<double>(0.0,1);
138 }
139 template <> inline int adevs_epsilon() { return 1; }
140 
141 #endif
SuperDenseTime(RealType real, int logical)
Constructor assigns initial values to real and logical.
Definition: adevs_time.h:35
This is the default super dense simulation time.
Definition: adevs_time.h:25
RealType real
The real, physically meaningful part of time.
Definition: adevs_time.h:29
T adevs_zero()
Returns the zero value for a time type.
Definition: adevs_time.h:114
T adevs_inf()
Returns the maximum value for a time type.
Definition: adevs_time.h:88
int logical
The logical part of time for order at a real instant.
Definition: adevs_time.h:31
SuperDenseTime< RealType > operator+(const SuperDenseTime< RealType > &h) const
Advance the time by h.
Definition: adevs_time.h:43
Definition: adevs_base.h:21
T adevs_epsilon()
Returns the smallest increment of time.
Definition: adevs_time.h:130
SuperDenseTime()
Default constructor.
Definition: adevs_time.h:33
SuperDenseTime< RealType > operator-(const SuperDenseTime< RealType > &preceding) const
Get the length of the interval from preceding to this. The format for the call is big number - small ...
Definition: adevs_time.h:52
bool operator==(const SuperDenseTime< RealType > &other) const
Times are identical.
Definition: adevs_time.h:71