time_pa.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 * *
3 * time_pa.cpp *
4 * =========== *
5 * *
6 *******************************************************************************
7 * *
8 * github repository *
9 * https://github.com/TUC-ProAut/ros_octomap *
10 * *
11 * Chair of Automation Technology, Technische Universität Chemnitz *
12 * https://www.tu-chemnitz.de/etit/proaut *
13 * *
14 *******************************************************************************
15 * *
16 * New BSD License *
17 * *
18 * Copyright (c) 2015-2018, Peter Weissig, Technische Universität Chemnitz *
19 * All rights reserved. *
20 * *
21 * Redistribution and use in source and binary forms, with or without *
22 * modification, are permitted provided that the following conditions are met: *
23 * * Redistributions of source code must retain the above copyright *
24 * notice, this list of conditions and the following disclaimer. *
25 * * Redistributions in binary form must reproduce the above copyright *
26 * notice, this list of conditions and the following disclaimer in the *
27 * documentation and/or other materials provided with the distribution. *
28 * * Neither the name of the Technische Universität Chemnitz nor the *
29 * names of its contributors may be used to endorse or promote products *
30 * derived from this software without specific prior written permission. *
31 * *
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" *
33 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
35 * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY *
36 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
37 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
38 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
39 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
42 * DAMAGE. *
43 * *
44 ******************************************************************************/
45 
46 // local headers
47 #include "octomap_pa/time_pa.h"
48 
49 // standard headers
50 #include <cmath>
51 
52 
53 //**************************[cTimePa]******************************************
54 cTimePa::cTimePa (const int32_t seconds, const int32_t nanoseconds):
55  seconds(seconds),nanoseconds(nanoseconds){
56 
57 }
58 
59 cTimePa::cTimePa (const double seconds) {
60 
61  this->seconds = floor(seconds);
62  this->nanoseconds = round((seconds - floor(seconds)) * 1e9);
63 
64  fix();
65 }
66 
67 cTimePa::cTimePa (const cTimePa &other): seconds(other.seconds),
68  nanoseconds(other.nanoseconds){
69 
70 }
71 
72 const cTimePa& cTimePa::operator = (const cTimePa &other) {
73 
74  seconds = other.seconds;
75  nanoseconds = other.nanoseconds;
76  return *this;
77 }
78 
79 bool cTimePa::operator == (const cTimePa &other) const {
80 
81  return (seconds == other.seconds) && (nanoseconds == other.nanoseconds);
82 }
83 
84 bool cTimePa::operator < (const cTimePa &other) const {
85 
86  return (seconds < other.seconds) ||
87  ((seconds == other.seconds) && (nanoseconds < other.nanoseconds));
88 }
89 
90 bool cTimePa::operator > (const cTimePa &other) const {
91 
92  return (seconds > other.seconds) ||
93  ((seconds == other.seconds) && (nanoseconds > other.nanoseconds));
94 }
95 
97 
98  cTimePa result(seconds, nanoseconds);
99  result.seconds -= other.seconds ;
100  result.nanoseconds-= other.nanoseconds;
101 
102  result.fix();
103  return result;
104 }
105 
107 
108  cTimePa result(seconds, nanoseconds);
109  result.seconds += other.seconds ;
110  result.nanoseconds+= other.nanoseconds;
111 
112  result.fix();
113  return result;
114 }
115 
116 void cTimePa::fix(void) {
117 
118  seconds += nanoseconds / 1000000000;
119  nanoseconds %= 1000000000;
120 
121  if (nanoseconds < 0) {
122  seconds--;
123  nanoseconds += 1000000000;
124  }
125 }
cTimePa operator-(const cTimePa &other)
Definition: time_pa.cpp:96
bool operator<(const cTimePa &other) const
Definition: time_pa.cpp:84
cTimePa operator+(const cTimePa &other)
Definition: time_pa.cpp:106
bool operator==(const cTimePa &other) const
Definition: time_pa.cpp:79
const cTimePa & operator=(const cTimePa &other)
Definition: time_pa.cpp:72
void fix(void)
Definition: time_pa.cpp:116
int32_t nanoseconds
Definition: time_pa.h:73
int32_t seconds
Definition: time_pa.h:72
cTimePa(const int32_t seconds=0, const int32_t nanoseconds=0)
Definition: time_pa.cpp:54
bool operator>(const cTimePa &other) const
Definition: time_pa.cpp:90


octomap_pa
Author(s):
autogenerated on Fri Jun 7 2019 22:04:53