duration.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, 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 
35 #ifndef ROS_DURATION_H
36 #define ROS_DURATION_H
37 
38 /*********************************************************************
39  ** Pragmas
40  *********************************************************************/
41 
42 #ifdef _MSC_VER
43  // Rostime has some magic interface that doesn't directly include
44  // its implementation, this just disbales those warnings.
45  #pragma warning(disable: 4244)
46  #pragma warning(disable: 4661)
47 #endif
48 
49 #include <iostream>
50 #include <math.h>
51 #include <stdexcept>
52 #include <climits>
53 #include <stdint.h>
54 #include "rostime_decl.h"
55 
56 namespace boost {
57  namespace posix_time {
58  class time_duration;
59  }
60 }
61 
62 namespace rs2rosinternal
63 {
66 
71 template <class T>
73 {
74 public:
75  int32_t sec, nsec;
76  DurationBase() : sec(0), nsec(0) { }
77  DurationBase(int32_t _sec, int32_t _nsec);
78  explicit DurationBase(double t){fromSec(t);};
80  T operator+(const T &rhs) const;
81  T operator-(const T &rhs) const;
82  T operator-() const;
83  T operator*(double scale) const;
84  T& operator+=(const T &rhs);
85  T& operator-=(const T &rhs);
86  T& operator*=(double scale);
87  bool operator==(const T &rhs) const;
88  inline bool operator!=(const T &rhs) const { return !(*static_cast<const T*>(this) == rhs); }
89  bool operator>(const T &rhs) const;
90  bool operator<(const T &rhs) const;
91  bool operator>=(const T &rhs) const;
92  bool operator<=(const T &rhs) const;
93  double toSec() const { return (double)sec + 1e-9*(double)nsec; };
94  int64_t toNSec() const {return (int64_t)sec*1000000000ll + (int64_t)nsec; };
95  T& fromSec(double t);
96  T& fromNSec(int64_t t);
97  bool isZero() const;
98  //boost::posix_time::time_duration toBoost() const;
99 };
100 
101 class Rate;
102 
108 class ROSTIME_DECL Duration : public DurationBase<Duration>
109 {
110 public:
113  { }
114 
115  Duration(int32_t _sec, int32_t _nsec)
116  : DurationBase<Duration>(_sec, _nsec)
117  {}
118 
119  explicit Duration(double t) { fromSec(t); }
120  explicit Duration(const Rate&);
125  bool sleep() const;
126 };
127 
128 extern ROSTIME_DECL const Duration DURATION_MAX;
129 extern ROSTIME_DECL const Duration DURATION_MIN;
130 
136 class ROSTIME_DECL WallDuration : public DurationBase<WallDuration>
137 {
138 public:
141  { }
142 
144  : DurationBase<WallDuration>(_sec, _nsec)
145  {}
146 
147  explicit WallDuration(double t) { fromSec(t); }
148  explicit WallDuration(const Rate&);
153  bool sleep() const;
154 };
155 
156 std::ostream &operator <<(std::ostream &os, const Duration &rhs);
157 std::ostream &operator <<(std::ostream &os, const WallDuration &rhs);
158 
159 
160 }
161 
162 #endif // ROS_DURATION_H
163 
164 
WallDuration(int32_t _sec, int32_t _nsec)
Definition: duration.h:143
BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE.
ROSTIME_DECL void normalizeSecNSecSigned(int32_t &sec, int32_t &nsec)
Definition: duration.cpp:64
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:10806
ImVec4 operator*(const ImVec4 &color, float t)
Definition: model-views.h:68
bool operator>=(optional< T > const &x, optional< T > const &y)
e
Definition: rmse.py:177
ROSTIME_DECL const Duration DURATION_MIN
double toSec() const
Definition: duration.h:93
GLdouble t
::std_msgs::Duration_< std::allocator< void > > Duration
Definition: Duration.h:47
Duration representation for use with the Time class.
Definition: duration.h:108
Class to help run loops at a desired frequency.
Definition: rate.h:51
ImVec4 operator+(const ImVec4 &c, float v)
Duration representation for use with the WallTime class.
Definition: duration.h:136
bool operator<=(optional< T > const &x, optional< T > const &y)
float3 operator-(const float3 &a, const float3 &b)
Definition: rendering.h:178
std::basic_ostream< Ch, Tr > & operator<<(std::basic_ostream< Ch, Tr > &os, const basic_format< Ch, Tr, Alloc > &f)
Definition: free_funcs.hpp:33
bool operator<(optional< T > const &x, optional< T > const &y)
bool operator!=(const T &rhs) const
Definition: duration.h:88
auto operator+=(std::string &lhs, StringRef const &sr) -> std::string &
int64_t toNSec() const
Definition: duration.h:94
ROSTIME_DECL const Duration DURATION_MAX
signed __int64 int64_t
Definition: stdint.h:89
Duration(int32_t _sec, int32_t _nsec)
Definition: duration.h:115
signed int int32_t
Definition: stdint.h:77
Base class for Duration implementations. Provides storage, common functions and operator overloads...
Definition: duration.h:72
bool operator==(const function_base &f, detail::function::useless_clear_type *)
bool operator>(optional< T > const &x, optional< T > const &y)
#define ROSTIME_DECL
Definition: rostime_decl.h:52


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