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