sttcl  v0.9c
STTCL C++ template state machine framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SttclCx11Time.h
Go to the documentation of this file.
1 
25 #ifndef STTCLCX11TIME_H_
26 #define STTCLCX11TIME_H_
27 
28 #include <chrono>
29 
30 #if defined(STTCL_CX11_TIME) or defined(STTCL_CX11_IMPL)
31 namespace sttcl
32 {
33 
34 namespace internal
35 {
36 namespace cx11_impl
37 {
41 class SttclCx11TimeDuration
42 {
43 public:
44  typedef std::chrono::nanoseconds NativeTimeDuration;
45 
46  SttclCx11TimeDuration(unsigned int argHours, unsigned int argMinutes, unsigned int argSeconds = 0, unsigned int argMilliSeconds = 0, unsigned long argMicroSeconds = 0, unsigned long argNanoSeconds = 0)
47  : td(std::chrono::hours(argHours) +
48  std::chrono::minutes(argMinutes) +
49  std::chrono::seconds(argSeconds))
50  {
51  td += std::chrono::milliseconds(argMilliSeconds);
52  td += std::chrono::microseconds(argMicroSeconds);
53  td += std::chrono::nanoseconds(argNanoSeconds);
54  }
55  SttclCx11TimeDuration(const SttclCx11TimeDuration& rhs)
56  : td(rhs.td)
57  {
58  }
59  SttclCx11TimeDuration(const NativeTimeDuration& nativeTimeDuration)
60  : td(nativeTimeDuration)
61  {
62  }
63  ~SttclCx11TimeDuration()
64  {
65  }
66 
67  SttclCx11TimeDuration& operator=(const SttclCx11TimeDuration& rhs)
68  {
69  td = rhs.td;
70  return *this;
71  }
72 
73  bool operator==(const SttclCx11TimeDuration& rhs) const
74  {
75  return td == rhs.td;
76  }
77  bool operator!=(const SttclCx11TimeDuration& rhs) const
78  {
79  return td != rhs.td;
80  }
81  bool operator<(const SttclCx11TimeDuration& rhs) const
82  {
83  return td < rhs.td;
84  }
85  bool operator<=(const SttclCx11TimeDuration& rhs) const
86  {
87  return td <= rhs.td;
88  }
89 
90  bool operator>(const SttclCx11TimeDuration& rhs) const
91  {
92  return td > rhs.td;
93  }
94  bool operator>=(const SttclCx11TimeDuration& rhs) const
95  {
96  return td >= rhs.td;
97  }
98 
99  SttclCx11TimeDuration& operator+=(const SttclCx11TimeDuration& rhs)
100  {
101  td += rhs.td;
102  return *this;
103  }
104 
105  SttclCx11TimeDuration& operator-=(const SttclCx11TimeDuration& rhs)
106  {
107  td -= rhs.td;
108  return *this;
109  }
110 
111  SttclCx11TimeDuration& operator*=(int factor)
112  {
113  td *=factor;
114  return *this;
115  }
116 
117  SttclCx11TimeDuration& operator/=(int divider)
118  {
119  td /= divider;
120  return *this;
121  }
122 
123 
124 // long hours() const
125 // {
126 // return td.hours();
127 // }
128 //
129 // long minutes() const
130 // {
131 // return td.minutes();
132 // }
133 //
134 // long seconds() const
135 // {
136 // return td.seconds();
137 // }
138 // long milliseconds() const
139 // {
140 // return td.total_milliseconds();
141 // }
142 // long microseconds() const
143 // {
144 // return td.total_microseconds();
145 // }
146 // long nanoseconds() const
147 // {
148 // return td.total_nanoseconds();
149 // }
150 //
151 // void hours(int newHours)
152 // {
153 // NativeTimeDuration result(td);
154 // result -= NativeTimeDuration(td.hours() + newHours,0,0);
155 // td = result;
156 // }
157 // void minutes(int newMinutes)
158 // {
159 // NativeTimeDuration result(td);
160 // result -= NativeTimeDuration(0,td.minutes() + newMinutes,0);
161 // td = result;
162 // }
163 // void seconds(int newSeconds)
164 // {
165 // NativeTimeDuration result(td);
166 // result -= NativeTimeDuration(0,0,td.seconds() + newSeconds);
167 // td = result;
168 // }
169  /*
170  void milliseconds(int newMilliSeconds)
171  {
172  NativeTimeDuration result(td);
173  result -= std::time::milliseconds(td.total_milliseconds());
174  result += std::time::milliseconds(newMilliSeconds);
175  td = result;
176  }
177  void microseconds(int newMicroSeconds)
178  {
179  NativeTimeDuration result(td);
180  result -= std::time::microseconds(td.total_microseconds());
181  result += std::time::microseconds(newMicroSeconds);
182  td = result;
183  }
184  void nanoseconds(long newNanoSeconds)
185  {
186 #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
187 
188  NativeTimeDuration result(td);
189  result -= std::time::nanoseconds(td.total_nanoseconds());
190  result += std::time::nanoseconds(newNanoSeconds);
191  td = result;
192 #endif
193  }
194  */
195  const NativeTimeDuration& getNativeValue() const
196  {
197  return td;
198  }
199 
200 private:
201  NativeTimeDuration td;
202 };
203 }
204 }
205 }
206 #endif
207 #endif /* STTCLCX11TIME_H_ */