duration.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_DURATION_H
37 #define ROS_DURATION_H
38 
39 /*********************************************************************
40  ** Pragmas
41  *********************************************************************/
42 
43 #ifdef _MSC_VER
44  // Rostime has some magic interface that doesn't directly include
45  // its implementation, this just disbales those warnings.
46  #pragma warning(disable: 4244)
47  #pragma warning(disable: 4661)
48 #endif
49 
50 #include <iostream>
51 #include <math.h>
52 #include <stdexcept>
53 #include <climits>
54 #include <stdint.h>
55 #include "rostime_decl.h"
56 
57 namespace boost {
58  namespace posix_time {
59  class time_duration;
60  }
61 }
62 
63 namespace roswrap
64 {
65 ROSTIME_DECL void normalizeSecNSecSigned(int64_t& sec, int64_t& nsec);
66 ROSTIME_DECL void normalizeSecNSecSigned(int32_t& sec, int32_t& nsec);
67 
72 template <class T>
74 {
75 public:
76  int32_t sec, nsec;
77  DurationBase() : sec(0), nsec(0) { }
78  DurationBase(int32_t _sec, int32_t _nsec);
79  explicit DurationBase(double t){fromSec(t);};
81  T operator+(const T &rhs) const;
82  T operator-(const T &rhs) const;
83  T operator-() const;
84  T operator*(double scale) const;
85  T& operator+=(const T &rhs);
86  T& operator-=(const T &rhs);
87  T& operator*=(double scale);
88  bool operator==(const T &rhs) const;
89  inline bool operator!=(const T &rhs) const { return !(*static_cast<const T*>(this) == rhs); }
90  bool operator>(const T &rhs) const;
91  bool operator<(const T &rhs) const;
92  bool operator>=(const T &rhs) const;
93  bool operator<=(const T &rhs) const;
94  double toSec() const { return (double)sec + 1e-9*(double)nsec; };
95  int64_t toNSec() const {return (int64_t)sec*1000000000ll + (int64_t)nsec; };
96  T& fromSec(double t);
97  T& fromNSec(int64_t t);
98  bool isZero() const;
99  //boost::posix_time::time_duration toBoost() const;
100 };
101 
102 class Rate;
103 
109 class ROSTIME_DECL Duration : public DurationBase<Duration>
110 {
111 public:
114  { }
115 
116  Duration(int32_t _sec, int32_t _nsec)
117  : DurationBase<Duration>(_sec, _nsec)
118  {}
119 
120  explicit Duration(double t) { fromSec(t); }
121  explicit Duration(const Rate&);
126  bool sleep() const;
127 };
128 
129 extern ROSTIME_DECL const Duration DURATION_MAX;
130 extern ROSTIME_DECL const Duration DURATION_MIN;
131 
137 class ROSTIME_DECL WallDuration : public DurationBase<WallDuration>
138 {
139 public:
142  { }
143 
144  WallDuration(int32_t _sec, int32_t _nsec)
145  : DurationBase<WallDuration>(_sec, _nsec)
146  {}
147 
148  explicit WallDuration(double t) { fromSec(t); }
149  explicit WallDuration(const Rate&);
154  bool sleep() const;
155 };
156 
157 std::ostream &operator <<(std::ostream &os, const Duration &rhs);
158 std::ostream &operator <<(std::ostream &os, const WallDuration &rhs);
159 
160 
161 }
162 
163 #endif // ROS_DURATION_H
164 
165 
roswrap::normalizeSecNSecSigned
ROSTIME_DECL void normalizeSecNSecSigned(int64_t &sec, int64_t &nsec)
Definition: duration.cpp:79
roswrap::DurationBase::fromSec
T & fromSec(double t)
Definition: impl/duration.h:53
roswrap::DurationBase::operator<=
bool operator<=(const T &rhs) const
Definition: impl/duration.h:137
roswrap::DurationBase::operator-=
T & operator-=(const T &rhs)
Definition: impl/duration.h:103
roswrap::DurationBase::fromNSec
T & fromNSec(int64_t t)
Definition: impl/duration.h:61
roswrap::DurationBase::operator*
T operator*(double scale) const
Definition: impl/duration.h:78
roswrap::Rate
Class to help run loops at a desired frequency.
Definition: rate.h:52
roswrap::DurationBase::operator-
T operator-() const
Definition: impl/duration.h:90
roswrap::operator<<
std::ostream & operator<<(std::ostream &os, const Time &rhs)
Definition: time_modi.cpp:394
boost
roswrap::DurationBase::DurationBase
DurationBase(double t)
Definition: duration.h:79
roswrap::DurationBase::toNSec
int64_t toNSec() const
Definition: duration.h:95
roswrap::DurationBase::operator*=
T & operator*=(double scale)
Definition: impl/duration.h:110
roswrap::DURATION_MIN
const ROSTIME_DECL Duration DURATION_MIN
roswrap::Duration::Duration
Duration(double t)
Definition: duration.h:120
roswrap::DURATION_MAX
const ROSTIME_DECL Duration DURATION_MAX
roswrap::DurationBase::sec
int32_t sec
Definition: duration.h:76
roswrap::DurationBase::operator+=
T & operator+=(const T &rhs)
Definition: impl/duration.h:96
std_msgs::Duration
::std_msgs::Duration_< std::allocator< void > > Duration
Definition: Duration.h:48
roswrap::DurationBase::operator<
bool operator<(const T &rhs) const
Definition: impl/duration.h:117
nsec
uint32_t nsec(const rosTime &time)
Definition: sick_ros_wrapper.h:175
roswrap::Duration::Duration
Duration()
Definition: duration.h:112
roswrap::WallDuration::WallDuration
WallDuration(double t)
Definition: duration.h:148
roswrap::Duration
Duration representation for use with the Time class.
Definition: duration.h:109
roswrap::DurationBase::isZero
bool isZero() const
Definition: impl/duration.h:163
roswrap::WallDuration::WallDuration
WallDuration(int32_t _sec, int32_t _nsec)
Definition: duration.h:144
roswrap::DurationBase::operator==
bool operator==(const T &rhs) const
Definition: impl/duration.h:157
roswrap::DurationBase::nsec
int32_t nsec
Definition: duration.h:76
roswrap::DurationBase::operator>=
bool operator>=(const T &rhs) const
Definition: impl/duration.h:147
roswrap
Definition: param_modi.cpp:41
roswrap::WallDuration
Duration representation for use with the WallTime class.
Definition: duration.h:137
sec
uint32_t sec(const rosTime &time)
Definition: sick_ros_wrapper.h:174
roswrap::DurationBase::operator+
T operator+(const T &rhs) const
Definition: impl/duration.h:72
roswrap::DurationBase::DurationBase
DurationBase()
Definition: duration.h:77
roswrap::DurationBase::operator!=
bool operator!=(const T &rhs) const
Definition: duration.h:89
roswrap::DurationBase::~DurationBase
~DurationBase()
Definition: duration.h:80
sick_scan_base.h
roswrap::WallDuration::WallDuration
WallDuration()
Definition: duration.h:140
roswrap::DurationBase::toSec
double toSec() const
Definition: duration.h:94
roswrap::DurationBase::operator>
bool operator>(const T &rhs) const
Definition: impl/duration.h:127
roswrap::Duration::Duration
Duration(int32_t _sec, int32_t _nsec)
Definition: duration.h:116
ROSTIME_DECL
#define ROSTIME_DECL
Definition: rostime_decl.h:53
sleep
void sleep(int secs)
roswrap::DurationBase
Base class for Duration implementations. Provides storage, common functions and operator overloads....
Definition: duration.h:73
t
geometry_msgs::TransformStamped t
rostime_decl.h


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