impl/time.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 /*********************************************************************
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2008, Willow Garage, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of Willow Garage, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *********************************************************************/
35 
36 #ifndef ROS_TIME_IMPL_H_INCLUDED
37 #define ROS_TIME_IMPL_H_INCLUDED
38 
39 /*********************************************************************
40 ** Headers
41 *********************************************************************/
42 
43 #include <ros/platform.h>
44 #include <iostream>
45 #include <cmath>
46 #include <ros/exception.h>
47 #include <ros/time.h>
48 
49 /*********************************************************************
50 ** Cross Platform Headers
51 *********************************************************************/
52 
53 #ifdef WIN32
54  #include <sys/timeb.h>
55 #else
56  #include <sys/time.h>
57 #endif
58 
59 namespace roswrap
60 {
61 
62  template<class T, class D>
63  T& TimeBase<T, D>::fromNSec(uint64_t t)
64  {
65  uint64_t sec64 = 0;
66  uint64_t nsec64 = t;
67 
68  normalizeSecNSec(sec64, nsec64);
69 
70  sec = (uint32_t)sec64;
71  nsec = (uint32_t)nsec64;
72 
73  return *static_cast<T*>(this);
74  }
75 
76  template<class T, class D>
77  D TimeBase<T, D>::operator-(const T &rhs) const
78  {
79  return D((int32_t)sec - (int32_t)rhs.sec,
80  (int32_t)nsec - (int32_t)rhs.nsec); // carry handled in ctor
81  }
82 
83  template<class T, class D>
84  T TimeBase<T, D>::operator-(const D &rhs) const
85  {
86  return *static_cast<const T*>(this) + ( -rhs);
87  }
88 
89  template<class T, class D>
90  T TimeBase<T, D>::operator+(const D &rhs) const
91  {
92  int64_t sec_sum = (int64_t)sec + (int64_t)rhs.sec;
93  int64_t nsec_sum = (int64_t)nsec + (int64_t)rhs.nsec;
94 
95  // Throws an exception if we go out of 32-bit range
96  normalizeSecNSecUnsigned(sec_sum, nsec_sum);
97 
98  // now, it's safe to downcast back to uint32 bits
99  return T((uint32_t)sec_sum, (uint32_t)nsec_sum);
100  }
101 
102  template<class T, class D>
103  T& TimeBase<T, D>::operator+=(const D &rhs)
104  {
105  *this = *this + rhs;
106  return *static_cast<T*>(this);
107  }
108 
109  template<class T, class D>
110  T& TimeBase<T, D>::operator-=(const D &rhs)
111  {
112  *this += (-rhs);
113  return *static_cast<T*>(this);
114  }
115 
116  template<class T, class D>
117  bool TimeBase<T, D>::operator==(const T &rhs) const
118  {
119  return sec == rhs.sec && nsec == rhs.nsec;
120  }
121 
122  template<class T, class D>
123  bool TimeBase<T, D>::operator<(const T &rhs) const
124  {
125  if (sec < rhs.sec)
126  return true;
127  else if (sec == rhs.sec && nsec < rhs.nsec)
128  return true;
129  return false;
130  }
131 
132  template<class T, class D>
133  bool TimeBase<T, D>::operator>(const T &rhs) const
134  {
135  if (sec > rhs.sec)
136  return true;
137  else if (sec == rhs.sec && nsec > rhs.nsec)
138  return true;
139  return false;
140  }
141 
142  template<class T, class D>
143  bool TimeBase<T, D>::operator<=(const T &rhs) const
144  {
145  if (sec < rhs.sec)
146  return true;
147  else if (sec == rhs.sec && nsec <= rhs.nsec)
148  return true;
149  return false;
150  }
151 
152  template<class T, class D>
153  bool TimeBase<T, D>::operator>=(const T &rhs) const
154  {
155  if (sec > rhs.sec)
156  return true;
157  else if (sec == rhs.sec && nsec >= rhs.nsec)
158  return true;
159  return false;
160  }
161 
162 // template<class T, class D>
163 // boost::posix_time::ptime
164 // TimeBase<T, D>::toBoost() const
165 // {
166 // namespace pt = boost::posix_time;
167 // #if defined(BOOST_DATE_TIME_HAS_NANOSECONDS)
168 // return pt::from_time_t(sec) + pt::nanoseconds(nsec);
169 // #else
170 // return pt::from_time_t(sec) + pt::microseconds((int)(nsec/1000.0));
171 // #endif
172 // }
173 
174 
175 }
176 
177 #endif // ROS_IMPL_TIME_H_INCLUDED
178 
roswrap::TimeBase::operator>=
bool operator>=(const T &rhs) const
Definition: impl/time.h:157
roswrap::TimeBase::operator<
bool operator<(const T &rhs) const
Definition: impl/time.h:127
roswrap::normalizeSecNSecUnsigned
void normalizeSecNSecUnsigned(int64_t &sec, int64_t &nsec)
Definition: time_modi.cpp:594
roswrap::TimeBase::operator+
T operator+(const D &rhs) const
Definition: impl/time.h:94
roswrap::TimeBase::operator==
bool operator==(const T &rhs) const
Definition: impl/time.h:121
nsec
uint32_t nsec(const rosTime &time)
Definition: sick_ros_wrapper.h:175
roswrap::TimeBase::operator+=
T & operator+=(const D &rhs)
Definition: impl/time.h:107
roswrap::TimeBase::operator<=
bool operator<=(const T &rhs) const
Definition: impl/time.h:147
roswrap::TimeBase::fromNSec
T & fromNSec(uint64_t t)
Definition: impl/time.h:67
roswrap::TimeBase::operator>
bool operator>(const T &rhs) const
Definition: impl/time.h:137
roswrap
Definition: param_modi.cpp:41
sec
uint32_t sec(const rosTime &time)
Definition: sick_ros_wrapper.h:174
roswrap::TimeBase::operator-
D operator-(const T &rhs) const
Definition: impl/time.h:81
sick_scan_base.h
roswrap::normalizeSecNSec
void normalizeSecNSec(uint64_t &sec, uint64_t &nsec)
Definition: time_modi.cpp:571
roswrap::TimeBase::operator-=
T & operator-=(const D &rhs)
Definition: impl/time.h:114
t
geometry_msgs::TransformStamped t


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:12