impl/duration.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 #ifndef ROSTIME_IMPL_DURATION_H_INCLUDED
35 #define ROSTIME_IMPL_DURATION_H_INCLUDED
36 
37 #include <ros/duration.h>
38 #include <ros/rate.h>
39 //#include <boost/date_time/posix_time/posix_time_types.hpp>
40 
41 namespace rs2rosinternal {
42  //
43  // DurationBase template member function implementation
44  //
45  template<class T>
47  : sec(_sec), nsec(_nsec)
48  {
50  }
51 
52  template<class T>
54  {
55  sec = (int32_t)floor(d);
56  nsec = (int32_t)((d - (double)sec)*1000000000);
57  return *static_cast<T*>(this);
58  }
59 
60  template<class T>
62  {
63  sec = (int32_t)(t / 1000000000);
64  nsec = (int32_t)(t % 1000000000);
65 
67 
68  return *static_cast<T*>(this);
69  }
70 
71  template<class T>
72  T DurationBase<T>::operator+(const T &rhs) const
73  {
74  return T(sec + rhs.sec, nsec + rhs.nsec);
75  }
76 
77  template<class T>
79  {
80  return T(toSec() * scale);
81  }
82 
83  template<class T>
84  T DurationBase<T>::operator-(const T &rhs) const
85  {
86  return T(sec - rhs.sec, nsec - rhs.nsec);
87  }
88 
89  template<class T>
91  {
92  return T(-sec , -nsec);
93  }
94 
95  template<class T>
97  {
98  *this = *this + rhs;
99  return *static_cast<T*>(this);
100  }
101 
102  template<class T>
104  {
105  *this += (-rhs);
106  return *static_cast<T*>(this);
107  }
108 
109  template<class T>
111  {
112  fromSec(toSec() * scale);
113  return *static_cast<T*>(this);
114  }
115 
116  template<class T>
117  bool DurationBase<T>::operator<(const T &rhs) const
118  {
119  if (sec < rhs.sec)
120  return true;
121  else if (sec == rhs.sec && nsec < rhs.nsec)
122  return true;
123  return false;
124  }
125 
126  template<class T>
127  bool DurationBase<T>::operator>(const T &rhs) const
128  {
129  if (sec > rhs.sec)
130  return true;
131  else if (sec == rhs.sec && nsec > rhs.nsec)
132  return true;
133  return false;
134  }
135 
136  template<class T>
137  bool DurationBase<T>::operator<=(const T &rhs) const
138  {
139  if (sec < rhs.sec)
140  return true;
141  else if (sec == rhs.sec && nsec <= rhs.nsec)
142  return true;
143  return false;
144  }
145 
146  template<class T>
147  bool DurationBase<T>::operator>=(const T &rhs) const
148  {
149  if (sec > rhs.sec)
150  return true;
151  else if (sec == rhs.sec && nsec >= rhs.nsec)
152  return true;
153  return false;
154  }
155 
156  template<class T>
157  bool DurationBase<T>::operator==(const T &rhs) const
158  {
159  return sec == rhs.sec && nsec == rhs.nsec;
160  }
161 
162  template<class T>
164  {
165  return sec == 0 && nsec == 0;
166  }
167 
168  /* template <class T>
169  boost::posix_time::time_duration*/
170  /* DurationBase<T>::toBoost() const
171  {
172  namespace bt = boost::posix_time;
173 #if defined(BOOST_DATE_TIME_HAS_NANOSECONDS)
174  return bt::seconds(sec) + bt::nanoseconds(nsec);
175 #else
176  return bt::seconds(static_cast<int64_t>(sec)) + bt::microseconds(static_cast<int64_t>(nsec/1000.0));
177 #endif
178  }*/
179 }
180 #endif
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:10806
T & operator+=(const T &rhs)
Definition: impl/duration.h:96
T & operator-=(const T &rhs)
bool operator<=(const T &rhs) const
d
Definition: rmse.py:171
double toSec() const
Definition: duration.h:93
bool operator<(const T &rhs) const
GLdouble t
bool operator>=(const T &rhs) const
ROSTIME_DECL void normalizeSecNSecSigned(int64_t &sec, int64_t &nsec)
Definition: duration.cpp:47
T operator+(const T &rhs) const
Definition: impl/duration.h:72
signed __int64 int64_t
Definition: stdint.h:89
T operator*(double scale) const
Definition: impl/duration.h:78
bool operator==(const T &rhs) const
signed int int32_t
Definition: stdint.h:77
bool operator>(const T &rhs) const
T & operator*=(double scale)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:13