OKVIS ROS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NsecTimeUtilities.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2  * OKVIS - Open Keyframe-based Visual-Inertial SLAM
3  * Copyright (c) 2015, Autonomous Systems Lab / ETH Zurich
4  *
5  * Copyright (c) 2011-2013, Paul Furgale and others.
6  * All rights reserved.
7  *
8  * Unlike otherwise stated in source files, the code in this repository is
9  * published under the Revised BSD (New BSD) license.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are met:
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  * * Neither the name of the <organization> nor the
19  * names of its contributors may be used to endorse or promote products
20  * derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
26  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *********************************************************************************/
33 
42 #ifndef INCLUDE_OKVIS_TIMING_NSECTIMEUTILITIES_HPP_
43 #define INCLUDE_OKVIS_TIMING_NSECTIMEUTILITIES_HPP_
44 #include <chrono>
45 #include <boost/cstdint.hpp>
46 
47 namespace okvis {
48 namespace timing {
49 
51 typedef boost::int64_t NsecTime;
52 
54 std::chrono::system_clock::time_point nsecToChrono( const NsecTime & time );
55 
57 NsecTime chronoToNsec( const std::chrono::system_clock::time_point & time );
58 
61 
63 double nsecToSec( const NsecTime & time );
64 
66 NsecTime secToNsec( const double & time );
67 
69 constexpr NsecTime getInvalidTime();
70 
73 bool isValid(const NsecTime & time);
74 
75 } // namespace timing
76 } // namespace okvis
77 
78 #endif /* INCLUDE_OKVIS_TIMING_NSECTIMEUTILITIES_HPP_ */
NsecTime chronoToNsec(const std::chrono::system_clock::time_point &time)
Convert std::chrono to nanoseconds since the epoch.
Definition: NsecTimeUtilities.cpp:48
NsecTime secToNsec(const double &time)
Convert the time (in seconds) to integer nanoseconds.
Definition: NsecTimeUtilities.cpp:67
constexpr NsecTime getInvalidTime()
return a magic number representing an invalid timestamp
Definition: NsecTimeUtilities.cpp:71
std::chrono::system_clock::time_point nsecToChrono(const NsecTime &time)
Convert nanoseconds since the epoch to std::chrono.
Definition: NsecTimeUtilities.cpp:40
boost::int64_t NsecTime
Nanoseconds since the epoch.
Definition: NsecTimeUtilities.hpp:51
NsecTime nsecNow()
Get the epoch time as nanoseconds since the epoch.
Definition: NsecTimeUtilities.cpp:54
bool isValid(const NsecTime &time)
Is the time valid? This uses a magic number std::numeric_limits<NsecTime>::min() to represent an inva...
Definition: NsecTimeUtilities.cpp:75
double nsecToSec(const NsecTime &time)
Convert the time (in integer nanoseconds) to decimal seconds.
Definition: NsecTimeUtilities.cpp:61