time.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016  
00017 
00018 #ifndef ROS_TIME_H_
00019 #define ROS_TIME_H_
00020 
00021 #include <math.h>
00022 #include <stdint.h>
00023 
00024 #include "ros/duration.h"
00025 
00026 namespace ros
00027 {
00028   void normalizeSecNSec(uint32_t &sec, uint32_t &nsec);
00029 
00030   class Time
00031   {
00032     public:
00033       uint32_t sec, nsec;
00034 
00035       Time() : sec(0), nsec(0) {}
00036       Time(uint32_t _sec, uint32_t _nsec) : sec(_sec), nsec(_nsec)
00037       {
00038         normalizeSecNSec(sec, nsec);
00039       }
00040 
00041       double toSec() const { return (double)sec + 1e-9*(double)nsec; };
00042       void fromSec(double t) { sec = (uint32_t) floor(t); nsec = (uint32_t) round((t-sec) * 1e9); };
00043 
00044       uint32_t toNsec() { return (uint32_t)sec*1000000000ull + (uint32_t)nsec; };
00045       Time& fromNSec(int32_t t);
00046 
00047       Time& operator +=(const Duration &rhs);
00048       Time& operator -=(const Duration &rhs);
00049 
00050       static Time now();
00051       static void setNow( Time & new_now);
00052   };
00053 
00054 }
00055 
00056 #endif


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Thu Jun 6 2019 20:43:57