00001 /****************************************************************************** 00002 * * 00003 * time_pa.cpp * 00004 * =========== * 00005 * * 00006 ******************************************************************************* 00007 * * 00008 * github repository * 00009 * https://github.com/TUC-ProAut/ros_octomap * 00010 * * 00011 * Chair of Automation Technology, Technische Universität Chemnitz * 00012 * https://www.tu-chemnitz.de/etit/proaut * 00013 * * 00014 ******************************************************************************* 00015 * * 00016 * New BSD License * 00017 * * 00018 * Copyright (c) 2015-2018, Peter Weissig, Technische Universität Chemnitz * 00019 * All rights reserved. * 00020 * * 00021 * Redistribution and use in source and binary forms, with or without * 00022 * modification, are permitted provided that the following conditions are met: * 00023 * * Redistributions of source code must retain the above copyright * 00024 * notice, this list of conditions and the following disclaimer. * 00025 * * Redistributions in binary form must reproduce the above copyright * 00026 * notice, this list of conditions and the following disclaimer in the * 00027 * documentation and/or other materials provided with the distribution. * 00028 * * Neither the name of the Technische Universität Chemnitz nor the * 00029 * names of its contributors may be used to endorse or promote products * 00030 * derived from this software without specific prior written permission. * 00031 * * 00032 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * 00033 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * 00034 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * 00035 * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY * 00036 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * 00037 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * 00038 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * 00039 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * 00040 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * 00041 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 00042 * DAMAGE. * 00043 * * 00044 ******************************************************************************/ 00045 00046 // local headers 00047 #include "octomap_pa/time_pa.h" 00048 00049 // standard headers 00050 #include <cmath> 00051 00052 00053 //**************************[cTimePa]****************************************** 00054 cTimePa::cTimePa (const int32_t seconds, const int32_t nanoseconds): 00055 seconds(seconds),nanoseconds(nanoseconds){ 00056 00057 } 00058 00059 cTimePa::cTimePa (const double seconds) { 00060 00061 this->seconds = floor(seconds); 00062 this->nanoseconds = round((seconds - floor(seconds)) * 1e9); 00063 00064 fix(); 00065 } 00066 00067 cTimePa::cTimePa (const cTimePa &other): seconds(other.seconds), 00068 nanoseconds(other.nanoseconds){ 00069 00070 } 00071 00072 const cTimePa& cTimePa::operator = (const cTimePa &other) { 00073 00074 seconds = other.seconds; 00075 nanoseconds = other.nanoseconds; 00076 return *this; 00077 } 00078 00079 bool cTimePa::operator == (const cTimePa &other) const { 00080 00081 return (seconds == other.seconds) && (nanoseconds == other.nanoseconds); 00082 } 00083 00084 bool cTimePa::operator < (const cTimePa &other) const { 00085 00086 return (seconds < other.seconds) || 00087 ((seconds == other.seconds) && (nanoseconds < other.nanoseconds)); 00088 } 00089 00090 bool cTimePa::operator > (const cTimePa &other) const { 00091 00092 return (seconds > other.seconds) || 00093 ((seconds == other.seconds) && (nanoseconds > other.nanoseconds)); 00094 } 00095 00096 cTimePa cTimePa::operator - (const cTimePa &other) { 00097 00098 cTimePa result(seconds, nanoseconds); 00099 result.seconds -= other.seconds ; 00100 result.nanoseconds-= other.nanoseconds; 00101 00102 result.fix(); 00103 return result; 00104 } 00105 00106 cTimePa cTimePa::operator + (const cTimePa &other) { 00107 00108 cTimePa result(seconds, nanoseconds); 00109 result.seconds += other.seconds ; 00110 result.nanoseconds+= other.nanoseconds; 00111 00112 result.fix(); 00113 return result; 00114 } 00115 00116 void cTimePa::fix(void) { 00117 00118 seconds += nanoseconds / 1000000000; 00119 nanoseconds %= 1000000000; 00120 00121 if (nanoseconds < 0) { 00122 seconds--; 00123 nanoseconds += 1000000000; 00124 } 00125 }