v01
This commit is contained in:
2
thirdparty/ros/roscpp_core/.gitignore
vendored
Normal file
2
thirdparty/ros/roscpp_core/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
._*
|
||||
*~
|
||||
124
thirdparty/ros/roscpp_core/cpp_common/CHANGELOG.rst
vendored
Normal file
124
thirdparty/ros/roscpp_core/cpp_common/CHANGELOG.rst
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Changelog for package cpp_common
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
0.7.2 (2020-05-28)
|
||||
------------------
|
||||
|
||||
0.7.1 (2020-01-25)
|
||||
------------------
|
||||
* only depend on the boost components needed (`#117 <https://github.com/ros/roscpp_core/issues/117>`_)
|
||||
|
||||
0.7.0 (2020-01-24)
|
||||
------------------
|
||||
* various code cleanup (`#116 <https://github.com/ros/roscpp_core/issues/116>`_)
|
||||
* Bump CMake version to avoid CMP0048 warning (`#115 <https://github.com/ros/roscpp_core/issues/115>`_)
|
||||
|
||||
0.6.13 (2019-10-03)
|
||||
-------------------
|
||||
|
||||
0.6.12 (2019-03-04)
|
||||
-------------------
|
||||
* update the use of macros in platform.h (`#99 <https://github.com/ros/roscpp_core/issues/99>`_)
|
||||
* avoid unnecessary memory allocation (std::string) (`#95 <https://github.com/ros/roscpp_core/issues/95>`_)
|
||||
* fix bug in HAVE_CXXABI_H compiler check (`#89 <https://github.com/ros/roscpp_core/issues/89>`_)
|
||||
|
||||
0.6.11 (2018-06-06)
|
||||
-------------------
|
||||
|
||||
0.6.10 (2018-05-01)
|
||||
-------------------
|
||||
|
||||
0.6.9 (2018-02-02)
|
||||
------------------
|
||||
|
||||
0.6.8 (2018-01-26)
|
||||
------------------
|
||||
* define console_bridge macro with API call rather than relying on short macro being defined (`#71 <https://github.com/ros/roscpp_core/issues/71>`_)
|
||||
|
||||
0.6.7 (2017-11-03)
|
||||
------------------
|
||||
* fix support for console_bridge < 0.3.0 (`#70 <https://github.com/ros/roscpp_core/issues/70>`_, regression of 0.6.6)
|
||||
|
||||
0.6.6 (2017-10-25)
|
||||
------------------
|
||||
* replace usage of deprecated logError macros (`#69 <https://github.com/ros/roscpp_core/issues/69>`_)
|
||||
|
||||
0.6.5 (2017-07-27)
|
||||
------------------
|
||||
|
||||
0.6.4 (2017-06-06)
|
||||
------------------
|
||||
|
||||
0.6.3 (2017-05-15)
|
||||
------------------
|
||||
|
||||
0.6.2 (2017-02-14)
|
||||
------------------
|
||||
|
||||
0.6.1 (2016-09-02)
|
||||
------------------
|
||||
|
||||
0.6.0 (2016-03-17)
|
||||
------------------
|
||||
|
||||
0.5.7 (2016-03-09)
|
||||
------------------
|
||||
* export symbols for Header (`#46 <https://github.com/ros/roscpp_core/pull/46>`_)
|
||||
|
||||
0.5.6 (2015-05-20)
|
||||
------------------
|
||||
|
||||
0.5.5 (2014-12-22)
|
||||
------------------
|
||||
|
||||
0.5.4 (2014-07-23)
|
||||
------------------
|
||||
|
||||
0.5.3 (2014-06-28)
|
||||
------------------
|
||||
* add missing boost dependency (`#24 <https://github.com/ros/roscpp_core/issues/24>`_)
|
||||
|
||||
0.5.2 (2014-06-27)
|
||||
------------------
|
||||
* find_package console_bridge with REQUIRED (`#23 <https://github.com/ros/roscpp_core/issues/23>`_)
|
||||
|
||||
0.5.1 (2014-06-24)
|
||||
------------------
|
||||
* convert to use console bridge from upstream debian package (`ros/rosdistro#4633 <https://github.com/ros/rosdistro/issues/4633>`_)
|
||||
|
||||
0.5.0 (2014-02-19)
|
||||
------------------
|
||||
|
||||
0.4.2 (2014-02-11)
|
||||
------------------
|
||||
|
||||
0.4.1 (2014-02-11)
|
||||
------------------
|
||||
|
||||
0.4.0 (2014-01-29)
|
||||
------------------
|
||||
|
||||
0.3.17 (2014-01-07)
|
||||
-------------------
|
||||
* move several client library independent parts from ros_comm into roscpp_core (`#12 <https://github.com/ros/roscpp_core/issues/12>`_)
|
||||
|
||||
0.3.16 (2013-07-14)
|
||||
-------------------
|
||||
|
||||
0.3.15 (2013-06-06)
|
||||
-------------------
|
||||
* fix install destination for dll's under Windows
|
||||
|
||||
0.3.14 (2013-03-21)
|
||||
-------------------
|
||||
|
||||
0.3.13 (2013-03-08)
|
||||
-------------------
|
||||
|
||||
0.3.12 (2013-01-13)
|
||||
-------------------
|
||||
|
||||
0.3.11 (2012-12-21)
|
||||
-------------------
|
||||
* first public release for Groovy
|
||||
44
thirdparty/ros/roscpp_core/cpp_common/CMakeLists.txt
vendored
Normal file
44
thirdparty/ros/roscpp_core/cpp_common/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
cmake_minimum_required(VERSION 3.0.2)
|
||||
project(cpp_common)
|
||||
|
||||
find_package(Boost REQUIRED COMPONENTS system thread)
|
||||
find_package(console_bridge REQUIRED)
|
||||
find_package(catkin REQUIRED)
|
||||
catkin_package(
|
||||
DEPENDS Boost console_bridge
|
||||
INCLUDE_DIRS include
|
||||
LIBRARIES ${PROJECT_NAME})
|
||||
|
||||
include(CheckIncludeFile)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckCXXSourceCompiles)
|
||||
|
||||
include_directories(include ${Boost_INCLUDE_DIRS} ${console_bridge_INCLUDE_DIRS})
|
||||
|
||||
# execinfo.h is needed for backtrace on glibc systems
|
||||
CHECK_INCLUDE_FILE(execinfo.h HAVE_EXECINFO_H)
|
||||
if(HAVE_EXECINFO_H)
|
||||
add_definitions(-DHAVE_EXECINFO_H=1)
|
||||
endif(HAVE_EXECINFO_H)
|
||||
# do we have demangle capability?
|
||||
# CHECK_INCLUDE_FILE doesn't work here for some reason
|
||||
CHECK_CXX_SOURCE_COMPILES("#include<cxxabi.h>\nint main(int argc,char**argv){}" HAVE_CXXABI_H)
|
||||
if(HAVE_CXXABI_H)
|
||||
add_definitions(-DHAVE_CXXABI_H=1)
|
||||
endif()
|
||||
CHECK_FUNCTION_EXISTS(backtrace HAVE_GLIBC_BACKTRACE)
|
||||
if(HAVE_GLIBC_BACKTRACE)
|
||||
add_definitions(-DHAVE_GLIBC_BACKTRACE)
|
||||
endif(HAVE_GLIBC_BACKTRACE)
|
||||
|
||||
add_library(${PROJECT_NAME} src/debug.cpp src/header.cpp)
|
||||
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES} ${console_bridge_LIBRARIES})
|
||||
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION})
|
||||
|
||||
install(DIRECTORY include/
|
||||
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
42
thirdparty/ros/roscpp_core/cpp_common/include/ros/cpp_common_decl.h
vendored
Normal file
42
thirdparty/ros/roscpp_core/cpp_common/include/ros/cpp_common_decl.h
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2009, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef ROS_CPP_COMMON_DECL_H_INCLUDED
|
||||
#define ROS_CPP_COMMON_DECL_H_INCLUDED
|
||||
|
||||
#include <ros/macros.h>
|
||||
|
||||
#ifdef ROS_BUILD_SHARED_LIBS // ros is being built around shared libraries
|
||||
#ifdef cpp_common_EXPORTS // we are building a shared lib/dll
|
||||
#define CPP_COMMON_DECL ROS_HELPER_EXPORT
|
||||
#else // we are using shared lib/dll
|
||||
#define CPP_COMMON_DECL ROS_HELPER_IMPORT
|
||||
#endif
|
||||
#else // ros is being built around static libraries
|
||||
#define CPP_COMMON_DECL
|
||||
#endif
|
||||
|
||||
#endif
|
||||
51
thirdparty/ros/roscpp_core/cpp_common/include/ros/datatypes.h
vendored
Normal file
51
thirdparty/ros/roscpp_core/cpp_common/include/ros/datatypes.h
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CPP_CORE_TYPES_H
|
||||
#define CPP_CORE_TYPES_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <list>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
namespace ros {
|
||||
|
||||
typedef std::vector<std::pair<std::string, std::string> > VP_string;
|
||||
typedef std::vector<std::string> V_string;
|
||||
typedef std::set<std::string> S_string;
|
||||
typedef std::map<std::string, std::string> M_string;
|
||||
typedef std::pair<std::string, std::string> StringPair;
|
||||
|
||||
typedef boost::shared_ptr<M_string> M_stringPtr;
|
||||
|
||||
}
|
||||
|
||||
#endif // CPP_CORE_TYPES_H
|
||||
54
thirdparty/ros/roscpp_core/cpp_common/include/ros/debug.h
vendored
Normal file
54
thirdparty/ros/roscpp_core/cpp_common/include/ros/debug.h
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2009, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ROSLIB_DEBUG_H
|
||||
#define ROSLIB_DEBUG_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "cpp_common_decl.h"
|
||||
|
||||
namespace ros
|
||||
{
|
||||
|
||||
namespace debug
|
||||
{
|
||||
typedef std::vector<void*> V_void;
|
||||
typedef std::vector<std::string> V_string;
|
||||
|
||||
CPP_COMMON_DECL std::string getBacktrace();
|
||||
CPP_COMMON_DECL std::string backtraceToString(const V_void& addresses);
|
||||
CPP_COMMON_DECL void getBacktrace(V_void& addresses);
|
||||
CPP_COMMON_DECL void translateAddresses(const V_void& addresses, V_string& lines);
|
||||
CPP_COMMON_DECL void demangleBacktrace(const V_string& names, V_string& demangled);
|
||||
CPP_COMMON_DECL std::string demangleBacktrace(const V_string& names);
|
||||
CPP_COMMON_DECL std::string demangleName(const std::string& name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
49
thirdparty/ros/roscpp_core/cpp_common/include/ros/exception.h
vendored
Normal file
49
thirdparty/ros/roscpp_core/cpp_common/include/ros/exception.h
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2009, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ROSLIB_EXCEPTION_H
|
||||
#define ROSLIB_EXCEPTION_H
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace ros
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Base class for all exceptions thrown by ROS
|
||||
*/
|
||||
class Exception : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
Exception(const std::string& what)
|
||||
: std::runtime_error(what)
|
||||
{}
|
||||
};
|
||||
|
||||
} // namespace ros
|
||||
|
||||
#endif
|
||||
89
thirdparty/ros/roscpp_core/cpp_common/include/ros/header.h
vendored
Normal file
89
thirdparty/ros/roscpp_core/cpp_common/include/ros/header.h
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* Copyright (c) 2008, Willow Garage, Inc.
|
||||
* Copyright (c) 2013, Open Source Robotics Foundation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CPP_CORE_HEADER_H
|
||||
#define CPP_CORE_HEADER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boost/shared_array.hpp>
|
||||
|
||||
#include "ros/datatypes.h"
|
||||
#include "cpp_common_decl.h"
|
||||
|
||||
namespace ros
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Provides functionality to parse a connection header and retrieve values from it
|
||||
*/
|
||||
class CPP_COMMON_DECL Header
|
||||
{
|
||||
public:
|
||||
Header();
|
||||
~Header();
|
||||
|
||||
/**
|
||||
* \brief Get a value from a parsed header
|
||||
* \param key Key value
|
||||
* \param value OUT -- value corresponding to the key if there is one
|
||||
* \return Returns true if the header had the specified key in it
|
||||
*/
|
||||
bool getValue(const std::string& key, std::string& value) const;
|
||||
/**
|
||||
* \brief Returns a shared pointer to the internal map used
|
||||
*/
|
||||
M_stringPtr getValues() { return read_map_; }
|
||||
|
||||
/**
|
||||
* \brief Parse a header out of a buffer of data
|
||||
*/
|
||||
bool parse(const boost::shared_array<uint8_t>& buffer, uint32_t size, std::string& error_msg);
|
||||
|
||||
/**
|
||||
* \brief Parse a header out of a buffer of data
|
||||
*/
|
||||
bool parse(uint8_t* buffer, uint32_t size, std::string& error_msg);
|
||||
|
||||
static void write(const M_string& key_vals, boost::shared_array<uint8_t>& buffer, uint32_t& size);
|
||||
|
||||
private:
|
||||
|
||||
M_stringPtr read_map_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // ROSCPP_HEADER_H
|
||||
66
thirdparty/ros/roscpp_core/cpp_common/include/ros/macros.h
vendored
Normal file
66
thirdparty/ros/roscpp_core/cpp_common/include/ros/macros.h
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2010, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ROSLIB_MACROS_H_INCLUDED
|
||||
#define ROSLIB_MACROS_H_INCLUDED
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define ROS_DEPRECATED __attribute__((deprecated))
|
||||
#define ROS_FORCE_INLINE __attribute__((always_inline))
|
||||
#elif defined(_MSC_VER)
|
||||
#define ROS_DEPRECATED
|
||||
#define ROS_FORCE_INLINE __forceinline
|
||||
#else
|
||||
#define ROS_DEPRECATED
|
||||
#define ROS_FORCE_INLINE inline
|
||||
#endif
|
||||
|
||||
/*
|
||||
Windows import/export and gnu http://gcc.gnu.org/wiki/Visibility
|
||||
macros.
|
||||
*/
|
||||
#if defined(_MSC_VER)
|
||||
#define ROS_HELPER_IMPORT __declspec(dllimport)
|
||||
#define ROS_HELPER_EXPORT __declspec(dllexport)
|
||||
#define ROS_HELPER_LOCAL
|
||||
#elif __GNUC__ >= 4
|
||||
#define ROS_HELPER_IMPORT __attribute__ ((visibility("default")))
|
||||
#define ROS_HELPER_EXPORT __attribute__ ((visibility("default")))
|
||||
#define ROS_HELPER_LOCAL __attribute__ ((visibility("hidden")))
|
||||
#else
|
||||
#define ROS_HELPER_IMPORT
|
||||
#define ROS_HELPER_EXPORT
|
||||
#define ROS_HELPER_LOCAL
|
||||
#endif
|
||||
|
||||
// Ignore warnings about import/exports when deriving from std classes.
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable: 4251)
|
||||
#pragma warning(disable: 4275)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
67
thirdparty/ros/roscpp_core/cpp_common/include/ros/platform.h
vendored
Normal file
67
thirdparty/ros/roscpp_core/cpp_common/include/ros/platform.h
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2010, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Some common cross platform utilities.
|
||||
*/
|
||||
#ifndef CPP_COMMON_PLATFORM_H_
|
||||
#define CPP_COMMON_PLATFORM_H_
|
||||
|
||||
/******************************************************************************
|
||||
* Cross Platform Functions
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h> // getenv, _dupenv_s
|
||||
#include <string>
|
||||
|
||||
namespace ros {
|
||||
|
||||
/**
|
||||
* Convenient cross platform function for returning a std::string of an
|
||||
* environment variable.
|
||||
*/
|
||||
inline bool get_environment_variable(std::string &str, const char* environment_variable) {
|
||||
char* env_var_cstr = NULL;
|
||||
#ifdef _MSC_VER
|
||||
_dupenv_s(&env_var_cstr, NULL,environment_variable);
|
||||
#else
|
||||
env_var_cstr = getenv(environment_variable);
|
||||
#endif
|
||||
if ( env_var_cstr ) {
|
||||
str = std::string(env_var_cstr);
|
||||
#ifdef _MSC_VER
|
||||
free(env_var_cstr);
|
||||
#endif
|
||||
return true;
|
||||
} else {
|
||||
str = std::string("");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ros
|
||||
|
||||
#endif /* CPP_COMMON_PLATFORM_H_ */
|
||||
47
thirdparty/ros/roscpp_core/cpp_common/include/ros/types.h
vendored
Normal file
47
thirdparty/ros/roscpp_core/cpp_common/include/ros/types.h
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2008, Morgan Quigley and Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ROSCPP_TYPES_H
|
||||
#define ROSCPP_TYPES_H
|
||||
|
||||
// this is just for interoperability with visual studio, where the standard
|
||||
// integer types are not defined.
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1600 ) // MS express/studio 2008 or earlier
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef __int16 int16_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef __int8 int8_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#endif // ROSCPP_TYPES_H
|
||||
27
thirdparty/ros/roscpp_core/cpp_common/package.xml
vendored
Normal file
27
thirdparty/ros/roscpp_core/cpp_common/package.xml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<package>
|
||||
<name>cpp_common</name>
|
||||
<version>0.7.2</version>
|
||||
<description>
|
||||
cpp_common contains C++ code for doing things that are not necessarily ROS
|
||||
related, but are useful for multiple packages. This includes things like
|
||||
the ROS_DEPRECATED and ROS_FORCE_INLINE macros, as well as code for getting
|
||||
backtraces.
|
||||
|
||||
This package is a component of <a href="http://www.ros.org/wiki/roscpp">roscpp</a>.
|
||||
</description>
|
||||
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
|
||||
<license>BSD</license>
|
||||
|
||||
<url>http://www.ros.org/wiki/cpp_common</url>
|
||||
<author>John Faust</author>
|
||||
|
||||
<buildtool_depend>catkin</buildtool_depend>
|
||||
|
||||
<build_depend>libboost-system-dev</build_depend>
|
||||
<build_depend>libboost-thread-dev</build_depend>
|
||||
<build_depend>libconsole-bridge-dev</build_depend>
|
||||
|
||||
<run_depend>libboost-system-dev</run_depend>
|
||||
<run_depend>libboost-thread-dev</run_depend>
|
||||
<run_depend>libconsole-bridge-dev</run_depend>
|
||||
</package>
|
||||
154
thirdparty/ros/roscpp_core/cpp_common/src/debug.cpp
vendored
Normal file
154
thirdparty/ros/roscpp_core/cpp_common/src/debug.cpp
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (C) 2009, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "ros/debug.h"
|
||||
|
||||
#if defined(HAVE_EXECINFO_H)
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_CXXABI_H)
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
|
||||
namespace ros
|
||||
{
|
||||
namespace debug
|
||||
{
|
||||
|
||||
void getBacktrace(V_void& addresses)
|
||||
{
|
||||
#if HAVE_GLIBC_BACKTRACE
|
||||
void *array[64];
|
||||
|
||||
size_t size = backtrace(array, 64);
|
||||
for (size_t i = 1; i < size; i++)
|
||||
{
|
||||
addresses.push_back(array[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void translateAddresses(const V_void& addresses, V_string& lines)
|
||||
{
|
||||
#if HAVE_GLIBC_BACKTRACE
|
||||
if (addresses.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
size_t size = addresses.size();
|
||||
char **strings = backtrace_symbols(&addresses.front(), size);
|
||||
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
lines.push_back(strings[i]);
|
||||
}
|
||||
|
||||
free(strings);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string demangleName(const std::string& name)
|
||||
{
|
||||
#if HAVE_CXXABI_H
|
||||
int status;
|
||||
char* demangled = abi::__cxa_demangle(name.c_str(), 0, 0, &status);
|
||||
std::string out;
|
||||
if (demangled)
|
||||
{
|
||||
out = demangled;
|
||||
free(demangled);
|
||||
}
|
||||
else
|
||||
{
|
||||
out = name;
|
||||
}
|
||||
|
||||
return out;
|
||||
#else
|
||||
return name;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string demangleBacktraceLine(const std::string& line)
|
||||
{
|
||||
// backtrace_symbols outputs in the form:
|
||||
// executable(function+offset) [address]
|
||||
// We want everything between ( and + to send to demangleName()
|
||||
size_t paren_pos = line.find('(');
|
||||
size_t plus_pos = line.find('+');
|
||||
if (paren_pos == std::string::npos || plus_pos == std::string::npos)
|
||||
{
|
||||
return line;
|
||||
}
|
||||
|
||||
std::string name(line, paren_pos + 1, plus_pos - paren_pos - 1);
|
||||
return line.substr(0, paren_pos + 1) + demangleName(name) + line.substr(plus_pos);
|
||||
}
|
||||
|
||||
void demangleBacktrace(const V_string& lines, V_string& demangled)
|
||||
{
|
||||
V_string::const_iterator it = lines.begin();
|
||||
V_string::const_iterator end = lines.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
demangled.push_back(demangleBacktraceLine(*it));
|
||||
}
|
||||
}
|
||||
|
||||
std::string backtraceToString(const V_void& addresses)
|
||||
{
|
||||
V_string lines, demangled;
|
||||
translateAddresses(addresses, lines);
|
||||
demangleBacktrace(lines, demangled);
|
||||
|
||||
std::stringstream ss;
|
||||
V_string::const_iterator it = demangled.begin();
|
||||
V_string::const_iterator end = demangled.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
ss << *it << std::endl;
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string getBacktrace()
|
||||
{
|
||||
V_void addresses;
|
||||
getBacktrace(addresses);
|
||||
return backtraceToString(addresses);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
179
thirdparty/ros/roscpp_core/cpp_common/src/header.cpp
vendored
Normal file
179
thirdparty/ros/roscpp_core/cpp_common/src/header.cpp
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* Copyright (c) 2008, Willow Garage, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "ros/header.h"
|
||||
|
||||
#include "console_bridge/console.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
|
||||
#define SROS_SERIALIZE_PRIMITIVE(ptr, data) { memcpy(ptr, &data, sizeof(data)); ptr += sizeof(data); }
|
||||
#define SROS_SERIALIZE_BUFFER(ptr, data, data_size) { if (data_size > 0) { memcpy(ptr, data, data_size); ptr += data_size; } }
|
||||
#define SROS_DESERIALIZE_PRIMITIVE(ptr, data) { memcpy(&data, ptr, sizeof(data)); ptr += sizeof(data); }
|
||||
#define SROS_DESERIALIZE_BUFFER(ptr, data, data_size) { if (data_size > 0) { memcpy(data, ptr, data_size); ptr += data_size; } }
|
||||
|
||||
// Remove this when no longer supporting platforms with libconsole-bridge-dev < 0.3.0,
|
||||
// in particular Debian Jessie: https://packages.debian.org/jessie/libconsole-bridge-dev
|
||||
#ifndef CONSOLE_BRIDGE_logError
|
||||
# define CONSOLE_BRIDGE_logError(fmt, ...) \
|
||||
console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_ERROR, fmt, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ros
|
||||
{
|
||||
|
||||
Header::Header()
|
||||
: read_map_(new M_string())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Header::~Header()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool Header::parse(const boost::shared_array<uint8_t>& buffer, uint32_t size, std::string& error_msg)
|
||||
{
|
||||
return parse(buffer.get(), size, error_msg);
|
||||
}
|
||||
|
||||
bool Header::parse(uint8_t* buffer, uint32_t size, std::string& error_msg)
|
||||
{
|
||||
std::string key_;
|
||||
uint8_t* buf = buffer;
|
||||
while (buf < buffer + size)
|
||||
{
|
||||
uint32_t len;
|
||||
SROS_DESERIALIZE_PRIMITIVE(buf, len);
|
||||
|
||||
if (len > 1000000)
|
||||
{
|
||||
error_msg = "Received an invalid TCPROS header. Each element must be prepended by a 4-byte length.";
|
||||
CONSOLE_BRIDGE_logError("%s", error_msg.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
boost::string_ref line((char*)buf, len);
|
||||
|
||||
buf += len;
|
||||
|
||||
//printf(":%s:\n", line.c_str());
|
||||
size_t eqpos = line.find_first_of("=");
|
||||
if (eqpos == string::npos)
|
||||
{
|
||||
error_msg = "Received an invalid TCPROS header. Each line must have an equals sign.";
|
||||
CONSOLE_BRIDGE_logError("%s", error_msg.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
boost::string_ref key_ref = line.substr(0, eqpos);
|
||||
boost::string_ref value_ref = line.substr(eqpos+1);
|
||||
|
||||
key_.assign(key_ref.data(), key_ref.length());
|
||||
|
||||
(*read_map_)[key_].assign(value_ref.data(), value_ref.length());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Header::getValue(const std::string& key, std::string& value) const
|
||||
{
|
||||
M_string::const_iterator it = read_map_->find(key);
|
||||
if (it == read_map_->end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value = it->second;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Header::write(const M_string& key_vals, boost::shared_array<uint8_t>& buffer, uint32_t& size)
|
||||
{
|
||||
// Calculate the necessary size
|
||||
size = 0;
|
||||
{
|
||||
M_string::const_iterator it = key_vals.begin();
|
||||
M_string::const_iterator end = key_vals.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
const std::string& key = it->first;
|
||||
const std::string& value = it->second;
|
||||
|
||||
size += key.length();
|
||||
size += value.length();
|
||||
size += 1; // = sign
|
||||
size += 4; // 4-byte length
|
||||
}
|
||||
}
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
buffer.reset(new uint8_t[size]);
|
||||
char* ptr = (char*)buffer.get();
|
||||
|
||||
// Write the data
|
||||
{
|
||||
M_string::const_iterator it = key_vals.begin();
|
||||
M_string::const_iterator end = key_vals.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
const std::string& key = it->first;
|
||||
const std::string& value = it->second;
|
||||
|
||||
uint32_t len = key.length() + value.length() + 1;
|
||||
SROS_SERIALIZE_PRIMITIVE(ptr, len);
|
||||
SROS_SERIALIZE_BUFFER(ptr, key.data(), key.length());
|
||||
static const char equals = '=';
|
||||
SROS_SERIALIZE_PRIMITIVE(ptr, equals);
|
||||
SROS_SERIALIZE_BUFFER(ptr, value.data(), value.length());
|
||||
}
|
||||
}
|
||||
|
||||
assert(ptr == (char*)buffer.get() + size);
|
||||
}
|
||||
|
||||
}
|
||||
199
thirdparty/ros/roscpp_core/doc/roscpp.rst
vendored
Normal file
199
thirdparty/ros/roscpp_core/doc/roscpp.rst
vendored
Normal file
@@ -0,0 +1,199 @@
|
||||
.. roscpp core prototype documentation master file, created by
|
||||
sphinx-quickstart on Fri Nov 11 11:12:23 2011.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
A roscpp_core prototype
|
||||
=======================
|
||||
|
||||
The goal of this prototype is to discover ways to make it easy to use
|
||||
ROS message types in ways that are completely familar to the average
|
||||
Linux developer. The current prototype allows one to compile against
|
||||
and serialize the most common C++ ROS messages via only a 200k debian
|
||||
package. The build dependencies are cmake, boost, and a single path.
|
||||
|
||||
Special thanks to Morten Kjaergaard who has been indispensible in
|
||||
getting this together.
|
||||
|
||||
|
||||
How to try it out
|
||||
-----------------
|
||||
|
||||
Find an amd64 ubuntu machine with either ``lucid``, ``natty`` or
|
||||
``oneiric`` installed. You need root permissions.
|
||||
|
||||
Download the appopriate ``.deb`` file from `here
|
||||
<http://people.willowgarage.com/straszheim/files>`_, e.g. on ``lucid``::
|
||||
|
||||
wget http://people.willowgarage.com/straszheim/files/ros-fuerte-roscpp-core-prototype_lucid_amd64.deb
|
||||
|
||||
Install it::
|
||||
|
||||
dpkg -i ros-fuerte-roscpp-core-prototype_lucid_amd64.deb
|
||||
|
||||
At this point you will see that ``/opt/ros/fuerte`` has had a bunch
|
||||
of stuff dropped in to it.
|
||||
|
||||
|
||||
To try it, create a directory src and pull down two
|
||||
example files::
|
||||
|
||||
% cd /tmp
|
||||
% mkdir src
|
||||
% cd src
|
||||
% wget -nv http://people.willowgarage.com/straszheim/files/CMakeLists.txt
|
||||
2011-11-11 11:52:36 URL:http://people.willowgarage.com/straszheim/files/CMakeLists.txt [268/268] -> "CMakeLists.txt" [1]
|
||||
% wget -nv http://people.willowgarage.com/straszheim/files/main.cpp
|
||||
2011-11-11 11:52:42 URL:http://people.willowgarage.com/straszheim/files/main.cpp [581/581] -> "main.cpp" [1]
|
||||
|
||||
the main.cpp does a very simple (de)serialization of a
|
||||
``sensor_msgs/PointCloud2``::
|
||||
|
||||
#include<sensor_msgs/PointCloud2.h>
|
||||
|
||||
namespace rs = ros::serialization;
|
||||
|
||||
int main()
|
||||
{
|
||||
sensor_msgs::PointCloud2 pc_1;
|
||||
pc_1.width = 10;
|
||||
pc_1.height = 20;
|
||||
// todo set other stuff
|
||||
|
||||
std::cout << "PointCloud2 message: " << std::endl << pc_1 << std::endl;
|
||||
|
||||
uint8_t buf[1024];
|
||||
rs::OStream out(buf, sizeof(buf) );
|
||||
rs::serialize(out, pc_1);
|
||||
|
||||
std::cout << "Message Was Serialized" << std::endl;
|
||||
|
||||
sensor_msgs::PointCloud2 pc_2;
|
||||
rs::IStream in(buf, sizeof(buf) );
|
||||
rs::deserialize(in, pc_2);
|
||||
|
||||
std::cout << "Its a message again: " << std::endl << pc_2 << std::endl;
|
||||
}
|
||||
|
||||
and the ``CMakeLists.txt`` demonstrates the CMake incantations
|
||||
required to find and use the code::
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.3)
|
||||
|
||||
find_package(ROS 12.04 COMPONENTS
|
||||
cpp_common rostime roscpp_traits roscpp_serialization sensor_msgs)
|
||||
|
||||
include_directories(${ROS_INCLUDE_DIRS})
|
||||
|
||||
add_executable(something main.cpp)
|
||||
target_link_libraries(something ${ROS_LIBRARIES})
|
||||
|
||||
The important line is the ``find_package``. This usage is very
|
||||
standard CMake practice. Unfortunately it is not possible to pass
|
||||
``fuerte`` as the version, as cmake insists that the version be
|
||||
numeric.
|
||||
|
||||
Indeed, four dependencies (cpp_common, rostime, roscpp_traits,
|
||||
roscpp_serialization) does seem like a lot, but each is very tiny;
|
||||
roscpp_traits has no library, roscpp_serialization contains only one
|
||||
function. We'll be cleaning this up. The important bit is that the
|
||||
user's workflow is decoupled from upstream.
|
||||
|
||||
Now build in the usual way, with the caveat that ``CMAKE_PREFIX_PATH``
|
||||
must be specified for the ``find_package`` to work. We believe that
|
||||
we can remove this requirement in the future::
|
||||
|
||||
% cmake . -DCMAKE_PREFIX_PATH=/opt/ros/fuerte
|
||||
-- The C compiler identification is GNU
|
||||
-- The CXX compiler identification is GNU
|
||||
-- Check for working C compiler: /usr/bin/gcc
|
||||
-- Check for working C compiler: /usr/bin/gcc -- works
|
||||
-- Detecting C compiler ABI info
|
||||
-- Detecting C compiler ABI info - done
|
||||
-- Check for working CXX compiler: /usr/bin/c++
|
||||
-- Check for working CXX compiler: /usr/bin/c++ -- works
|
||||
-- Detecting CXX compiler ABI info
|
||||
-- Detecting CXX compiler ABI info - done
|
||||
-- Configuring done
|
||||
-- Generating done
|
||||
-- Build files have been written to: /tmp/src
|
||||
|
||||
Make and run as usual::
|
||||
|
||||
% make
|
||||
Scanning dependencies of target something
|
||||
[100%] Building CXX object CMakeFiles/something.dir/main.cpp.o
|
||||
Linking CXX executable something
|
||||
[100%] Built target something
|
||||
|
||||
% ./something
|
||||
PointCloud2 message:
|
||||
header:
|
||||
[ etc ]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Contents of /opt/ros/fuerte
|
||||
---------------------------
|
||||
|
||||
.. rubric:: bin/gen*.py
|
||||
|
||||
these are message generator binaries. CMake macros provided in the
|
||||
package make it easy to generate your own message types.
|
||||
|
||||
.. rubric:: lib/
|
||||
|
||||
this is currently the smallest set of libraries that you need to
|
||||
serialize ROS messages. There are three. We will be making this
|
||||
smaller, and may be able to go header-only. Anyhow the dependencies
|
||||
are fairly light::
|
||||
|
||||
% ldd /opt/ros/fuerte/lib/*.so
|
||||
|
||||
/opt/ros/fuerte/lib/libcpp_common.so:
|
||||
linux-vdso.so.1 => (0x00007fff0adc3000)
|
||||
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fbdd1bad000)
|
||||
libm.so.6 => /lib/libm.so.6 (0x00007fbdd192a000)
|
||||
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007fbdd1712000)
|
||||
libc.so.6 => /lib/libc.so.6 (0x00007fbdd138f000)
|
||||
/lib64/ld-linux-x86-64.so.2 (0x00007fbdd20f5000)
|
||||
|
||||
/opt/ros/fuerte/lib/libroscpp_serialization.so:
|
||||
linux-vdso.so.1 => (0x00007fff62ff6000)
|
||||
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f7c21ae9000)
|
||||
libm.so.6 => /lib/libm.so.6 (0x00007f7c21866000)
|
||||
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f7c2164e000)
|
||||
libc.so.6 => /lib/libc.so.6 (0x00007f7c212cb000)
|
||||
/lib64/ld-linux-x86-64.so.2 (0x00007f7c2202a000)
|
||||
|
||||
/opt/ros/fuerte/lib/librostime.so:
|
||||
linux-vdso.so.1 => (0x00007fffddb60000)
|
||||
libboost_date_time.so.1.40.0 => /usr/lib/libboost_date_time.so.1.40.0 (0x00007f0af8ffa000)
|
||||
libboost_thread.so.1.40.0 => /usr/lib/libboost_thread.so.1.40.0 (0x00007f0af8de4000)
|
||||
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f0af8acf000)
|
||||
libm.so.6 => /lib/libm.so.6 (0x00007f0af884c000)
|
||||
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f0af8635000)
|
||||
libc.so.6 => /lib/libc.so.6 (0x00007f0af82b1000)
|
||||
librt.so.1 => /lib/librt.so.1 (0x00007f0af80a9000)
|
||||
libpthread.so.0 => /lib/libpthread.so.0 (0x00007f0af7e8c000)
|
||||
/lib64/ld-linux-x86-64.so.2 (0x00007f0af9481000)
|
||||
|
||||
i.e. the only additional dependencies are ``boost::thread`` and
|
||||
``boost::date_time``. This is due to the fact that ros time classes
|
||||
are considered "primtives" by ros messages.
|
||||
|
||||
.. rubric:: include/
|
||||
|
||||
the ``ROS`` headers associated with the libraries above, and generated
|
||||
ROS message headers.
|
||||
|
||||
.. rubric:: share/msg
|
||||
|
||||
The original message definition (``.msg``) files.
|
||||
|
||||
.. rubric:: share/cmake
|
||||
|
||||
CMake infrastructure for straightforward finding/use of these headers.
|
||||
4
thirdparty/ros/roscpp_core/roscpp_core/CMakeLists.txt
vendored
Normal file
4
thirdparty/ros/roscpp_core/roscpp_core/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.0.2)
|
||||
project(roscpp_core)
|
||||
find_package(catkin REQUIRED)
|
||||
catkin_metapackage()
|
||||
23
thirdparty/ros/roscpp_core/roscpp_core/package.xml
vendored
Normal file
23
thirdparty/ros/roscpp_core/roscpp_core/package.xml
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<package>
|
||||
<name>roscpp_core</name>
|
||||
<version>0.7.2</version>
|
||||
<description>
|
||||
Underlying data libraries for roscpp messages.
|
||||
</description>
|
||||
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
|
||||
<license>BSD</license>
|
||||
|
||||
<url type="website">http://www.ros.org/wiki/roscpp_core</url>
|
||||
<author>Josh Faust</author>
|
||||
|
||||
<buildtool_depend>catkin</buildtool_depend>
|
||||
|
||||
<run_depend>cpp_common</run_depend>
|
||||
<run_depend>roscpp_serialization</run_depend>
|
||||
<run_depend>roscpp_traits</run_depend>
|
||||
<run_depend>rostime</run_depend>
|
||||
|
||||
<export>
|
||||
<metapackage/>
|
||||
</export>
|
||||
</package>
|
||||
124
thirdparty/ros/roscpp_core/roscpp_serialization/CHANGELOG.rst
vendored
Normal file
124
thirdparty/ros/roscpp_core/roscpp_serialization/CHANGELOG.rst
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Changelog for package roscpp_serialization
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
0.7.2 (2020-05-28)
|
||||
------------------
|
||||
|
||||
0.7.1 (2020-01-25)
|
||||
------------------
|
||||
|
||||
0.7.0 (2020-01-24)
|
||||
------------------
|
||||
* various code cleanup (`#116 <https://github.com/ros/roscpp_core/issues/116>`_)
|
||||
* Bump CMake version to avoid CMP0048 warning (`#115 <https://github.com/ros/roscpp_core/issues/115>`_)
|
||||
|
||||
0.6.13 (2019-10-03)
|
||||
-------------------
|
||||
* added cast to uint32_t in roscpp_serialization to fix -Wconversion warning (`#113 <https://github.com/ros/roscpp_core/issues/113>`_)
|
||||
* roscpp_serialization: replace c-style-casts with static/reinterpret casts (`#107 <https://github.com/ros/roscpp_core/issues/107>`_)
|
||||
|
||||
0.6.12 (2019-03-04)
|
||||
-------------------
|
||||
* fix GCC8 class-memaccess in VectorSerializer (`#102 <https://github.com/ros/roscpp_core/issues/102>`_)
|
||||
|
||||
0.6.11 (2018-06-06)
|
||||
-------------------
|
||||
* replace reinterpret_cast with memcpy to avoid undefined behaviour/alignment issues (`#83 <https://github.com/ros/roscpp_core/issues/83>`_)
|
||||
|
||||
0.6.10 (2018-05-01)
|
||||
-------------------
|
||||
|
||||
0.6.9 (2018-02-02)
|
||||
------------------
|
||||
|
||||
0.6.8 (2018-01-26)
|
||||
------------------
|
||||
|
||||
0.6.7 (2017-11-03)
|
||||
------------------
|
||||
|
||||
0.6.6 (2017-10-25)
|
||||
------------------
|
||||
|
||||
0.6.5 (2017-07-27)
|
||||
------------------
|
||||
|
||||
0.6.4 (2017-06-06)
|
||||
------------------
|
||||
|
||||
0.6.3 (2017-05-15)
|
||||
------------------
|
||||
|
||||
0.6.2 (2017-02-14)
|
||||
------------------
|
||||
* fix warning when compiling with -Wpedantic (`#53 <https://github.com/ros/roscpp_core/issues/53>`_)
|
||||
|
||||
0.6.1 (2016-09-02)
|
||||
------------------
|
||||
* fix warning about unused parameter (`#51 <https://github.com/ros/roscpp_core/pull/51>`_)
|
||||
|
||||
0.6.0 (2016-03-17)
|
||||
------------------
|
||||
|
||||
0.5.7 (2016-03-09)
|
||||
------------------
|
||||
* fix serializer bool on ARM (`#44 <https://github.com/ros/roscpp_core/pull/44>`_)
|
||||
|
||||
0.5.6 (2015-05-20)
|
||||
------------------
|
||||
|
||||
0.5.5 (2014-12-22)
|
||||
------------------
|
||||
|
||||
0.5.4 (2014-07-23)
|
||||
------------------
|
||||
|
||||
0.5.3 (2014-06-28)
|
||||
------------------
|
||||
|
||||
0.5.2 (2014-06-27)
|
||||
------------------
|
||||
|
||||
0.5.1 (2014-06-24)
|
||||
------------------
|
||||
|
||||
0.5.0 (2014-02-19)
|
||||
------------------
|
||||
|
||||
0.4.2 (2014-02-11)
|
||||
------------------
|
||||
|
||||
0.4.1 (2014-02-11)
|
||||
------------------
|
||||
|
||||
0.4.0 (2014-01-29)
|
||||
------------------
|
||||
* remove assignSubscriptionConnectionHeader (`#19 <https://github.com/ros/roscpp_core/issues/19>`_)
|
||||
|
||||
0.3.17 (2014-01-07)
|
||||
-------------------
|
||||
* move several client library independent parts from ros_comm into roscpp_core (`#12 <https://github.com/ros/roscpp_core/issues/12>`_)
|
||||
|
||||
0.3.16 (2013-07-14)
|
||||
-------------------
|
||||
* fix alignment in serialization on ARM (`#14 <https://github.com/ros/roscpp_core/issues/14>`_)
|
||||
|
||||
0.3.15 (2013-06-06)
|
||||
-------------------
|
||||
* fix compiler warning about unused variable (`#11 <https://github.com/ros/roscpp_core/issues/11>`_)
|
||||
* fix install destination for dll's under Windows
|
||||
|
||||
0.3.14 (2013-03-21)
|
||||
-------------------
|
||||
|
||||
0.3.13 (2013-03-08)
|
||||
-------------------
|
||||
* fix serialization on ARM
|
||||
|
||||
0.3.12 (2013-01-13)
|
||||
-------------------
|
||||
|
||||
0.3.11 (2012-12-21)
|
||||
-------------------
|
||||
* first public release for Groovy
|
||||
22
thirdparty/ros/roscpp_core/roscpp_serialization/CMakeLists.txt
vendored
Normal file
22
thirdparty/ros/roscpp_core/roscpp_serialization/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
cmake_minimum_required(VERSION 3.0.2)
|
||||
project(roscpp_serialization)
|
||||
find_package(catkin REQUIRED COMPONENTS cpp_common roscpp_traits rostime)
|
||||
catkin_package(
|
||||
INCLUDE_DIRS include
|
||||
LIBRARIES roscpp_serialization
|
||||
CATKIN_DEPENDS cpp_common roscpp_traits rostime
|
||||
)
|
||||
|
||||
include_directories(include ${catkin_INCLUDE_DIRS})
|
||||
link_directories(${catkin_LIBRARY_DIRS})
|
||||
|
||||
add_library(roscpp_serialization src/serialization.cpp)
|
||||
|
||||
install(TARGETS roscpp_serialization
|
||||
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION})
|
||||
|
||||
install(DIRECTORY include/
|
||||
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
55
thirdparty/ros/roscpp_core/roscpp_serialization/include/ros/roscpp_serialization_macros.h
vendored
Normal file
55
thirdparty/ros/roscpp_core/roscpp_serialization/include/ros/roscpp_serialization_macros.h
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/*********************************************************************
|
||||
*
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* Copyright (c) 2009, Willow Garage, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Willow Garage nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*********************************************************************/
|
||||
/*
|
||||
* Cross platform macros.
|
||||
*
|
||||
*/
|
||||
#ifndef ROSCPP_SERIALIZATION_MACROS_HPP_
|
||||
#define ROSCPP_SERIALIZATION_MACROS_HPP_
|
||||
|
||||
#include <ros/macros.h>
|
||||
|
||||
#ifdef ROS_BUILD_SHARED_LIBS // ros is being built around shared libraries
|
||||
#ifdef roscpp_serialization_EXPORTS // we are building a shared lib/dll
|
||||
#define ROSCPP_SERIALIZATION_DECL ROS_HELPER_EXPORT
|
||||
#else // we are using shared lib/dll
|
||||
#define ROSCPP_SERIALIZATION_DECL ROS_HELPER_IMPORT
|
||||
#endif
|
||||
#else // ros is being built around static libraries
|
||||
#define ROSCPP_SERIALIZATION_DECL
|
||||
#endif
|
||||
|
||||
#endif /* ROSCPP_SERIALIZATION_MACROS_HPP_ */
|
||||
886
thirdparty/ros/roscpp_core/roscpp_serialization/include/ros/serialization.h
vendored
Normal file
886
thirdparty/ros/roscpp_core/roscpp_serialization/include/ros/serialization.h
vendored
Normal file
@@ -0,0 +1,886 @@
|
||||
/*
|
||||
* Copyright (C) 2009, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ROSCPP_SERIALIZATION_H
|
||||
#define ROSCPP_SERIALIZATION_H
|
||||
|
||||
#include "roscpp_serialization_macros.h"
|
||||
|
||||
#include <ros/types.h>
|
||||
#include <ros/time.h>
|
||||
|
||||
#include "serialized_message.h"
|
||||
#include "ros/message_traits.h"
|
||||
#include "ros/builtin_message_traits.h"
|
||||
#include "ros/exception.h"
|
||||
#include "ros/datatypes.h"
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/call_traits.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/or.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#define ROS_NEW_SERIALIZATION_API 1
|
||||
|
||||
/**
|
||||
* \brief Declare your serializer to use an allInOne member instead of requiring 3 different serialization
|
||||
* functions.
|
||||
*
|
||||
* The allinone method has the form:
|
||||
\verbatim
|
||||
template<typename Stream, typename T>
|
||||
inline static void allInOne(Stream& stream, T t)
|
||||
{
|
||||
stream.next(t.a);
|
||||
stream.next(t.b);
|
||||
...
|
||||
}
|
||||
\endverbatim
|
||||
*
|
||||
* The only guarantee given is that Stream::next(T) is defined.
|
||||
*/
|
||||
#define ROS_DECLARE_ALLINONE_SERIALIZER \
|
||||
template<typename Stream, typename T> \
|
||||
inline static void write(Stream& stream, const T& t) \
|
||||
{ \
|
||||
allInOne<Stream, const T&>(stream, t); \
|
||||
} \
|
||||
\
|
||||
template<typename Stream, typename T> \
|
||||
inline static void read(Stream& stream, T& t) \
|
||||
{ \
|
||||
allInOne<Stream, T&>(stream, t); \
|
||||
} \
|
||||
\
|
||||
template<typename T> \
|
||||
inline static uint32_t serializedLength(const T& t) \
|
||||
{ \
|
||||
LStream stream; \
|
||||
allInOne<LStream, const T&>(stream, t); \
|
||||
return stream.getLength(); \
|
||||
}
|
||||
|
||||
namespace ros
|
||||
{
|
||||
namespace serialization
|
||||
{
|
||||
namespace mt = message_traits;
|
||||
namespace mpl = boost::mpl;
|
||||
|
||||
class ROSCPP_SERIALIZATION_DECL StreamOverrunException : public ros::Exception
|
||||
{
|
||||
public:
|
||||
StreamOverrunException(const std::string& what)
|
||||
: Exception(what)
|
||||
{}
|
||||
};
|
||||
|
||||
ROSCPP_SERIALIZATION_DECL void throwStreamOverrun();
|
||||
|
||||
/**
|
||||
* \brief Templated serialization class. Default implementation provides backwards compatibility with
|
||||
* old message types.
|
||||
*
|
||||
* Specializing the Serializer class is the only thing you need to do to get the ROS serialization system
|
||||
* to work with a type.
|
||||
*/
|
||||
template<typename T>
|
||||
struct Serializer
|
||||
{
|
||||
/**
|
||||
* \brief Write an object to the stream. Normally the stream passed in here will be a ros::serialization::OStream
|
||||
*/
|
||||
template<typename Stream>
|
||||
inline static void write(Stream& stream, typename boost::call_traits<T>::param_type t)
|
||||
{
|
||||
t.serialize(stream.getData(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Read an object from the stream. Normally the stream passed in here will be a ros::serialization::IStream
|
||||
*/
|
||||
template<typename Stream>
|
||||
inline static void read(Stream& stream, typename boost::call_traits<T>::reference t)
|
||||
{
|
||||
t.deserialize(stream.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Determine the serialized length of an object.
|
||||
*/
|
||||
inline static uint32_t serializedLength(typename boost::call_traits<T>::param_type t)
|
||||
{
|
||||
return t.serializationLength();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Serialize an object. Stream here should normally be a ros::serialization::OStream
|
||||
*/
|
||||
template<typename T, typename Stream>
|
||||
inline void serialize(Stream& stream, const T& t)
|
||||
{
|
||||
Serializer<T>::write(stream, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Deserialize an object. Stream here should normally be a ros::serialization::IStream
|
||||
*/
|
||||
template<typename T, typename Stream>
|
||||
inline void deserialize(Stream& stream, T& t)
|
||||
{
|
||||
Serializer<T>::read(stream, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Determine the serialized length of an object
|
||||
*/
|
||||
template<typename T>
|
||||
inline uint32_t serializationLength(const T& t)
|
||||
{
|
||||
return Serializer<T>::serializedLength(t);
|
||||
}
|
||||
|
||||
#define ROS_CREATE_SIMPLE_SERIALIZER(Type) \
|
||||
template<> struct Serializer<Type> \
|
||||
{ \
|
||||
template<typename Stream> inline static void write(Stream& stream, const Type v) \
|
||||
{ \
|
||||
memcpy(stream.advance(sizeof(v)), &v, sizeof(v) ); \
|
||||
} \
|
||||
\
|
||||
template<typename Stream> inline static void read(Stream& stream, Type& v) \
|
||||
{ \
|
||||
memcpy(&v, stream.advance(sizeof(v)), sizeof(v) ); \
|
||||
} \
|
||||
\
|
||||
inline static uint32_t serializedLength(const Type&) \
|
||||
{ \
|
||||
return sizeof(Type); \
|
||||
} \
|
||||
};
|
||||
|
||||
ROS_CREATE_SIMPLE_SERIALIZER(uint8_t)
|
||||
ROS_CREATE_SIMPLE_SERIALIZER(int8_t)
|
||||
ROS_CREATE_SIMPLE_SERIALIZER(uint16_t)
|
||||
ROS_CREATE_SIMPLE_SERIALIZER(int16_t)
|
||||
ROS_CREATE_SIMPLE_SERIALIZER(uint32_t)
|
||||
ROS_CREATE_SIMPLE_SERIALIZER(int32_t)
|
||||
ROS_CREATE_SIMPLE_SERIALIZER(uint64_t)
|
||||
ROS_CREATE_SIMPLE_SERIALIZER(int64_t)
|
||||
ROS_CREATE_SIMPLE_SERIALIZER(float)
|
||||
ROS_CREATE_SIMPLE_SERIALIZER(double)
|
||||
|
||||
/**
|
||||
* \brief Serializer specialized for bool (serialized as uint8)
|
||||
*/
|
||||
template<> struct Serializer<bool>
|
||||
{
|
||||
template<typename Stream> inline static void write(Stream& stream, const bool v)
|
||||
{
|
||||
uint8_t b = static_cast<uint8_t>(v);
|
||||
memcpy(stream.advance(1), &b, 1 );
|
||||
}
|
||||
|
||||
template<typename Stream> inline static void read(Stream& stream, bool& v)
|
||||
{
|
||||
uint8_t b;
|
||||
memcpy(&b, stream.advance(1), 1 );
|
||||
v = static_cast<bool>(b);
|
||||
}
|
||||
|
||||
inline static uint32_t serializedLength(bool)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Serializer specialized for std::string
|
||||
*/
|
||||
template<class ContainerAllocator>
|
||||
struct Serializer<std::basic_string<char, std::char_traits<char>, ContainerAllocator> >
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, ContainerAllocator> StringType;
|
||||
|
||||
template<typename Stream>
|
||||
inline static void write(Stream& stream, const StringType& str)
|
||||
{
|
||||
size_t len = str.size();
|
||||
stream.next(static_cast<uint32_t>(len));
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
memcpy(stream.advance(static_cast<uint32_t>(len)), str.data(), len);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Stream>
|
||||
inline static void read(Stream& stream, StringType& str)
|
||||
{
|
||||
uint32_t len;
|
||||
stream.next(len);
|
||||
if (len > 0)
|
||||
{
|
||||
str = StringType(reinterpret_cast<char*>(stream.advance(len)), len);
|
||||
}
|
||||
else
|
||||
{
|
||||
str.clear();
|
||||
}
|
||||
}
|
||||
|
||||
inline static uint32_t serializedLength(const StringType& str)
|
||||
{
|
||||
return 4 + static_cast<uint32_t>(str.size());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Serializer specialized for ros::Time
|
||||
*/
|
||||
template<>
|
||||
struct Serializer<ros::Time>
|
||||
{
|
||||
template<typename Stream>
|
||||
inline static void write(Stream& stream, const ros::Time& v)
|
||||
{
|
||||
stream.next(v.sec);
|
||||
stream.next(v.nsec);
|
||||
}
|
||||
|
||||
template<typename Stream>
|
||||
inline static void read(Stream& stream, ros::Time& v)
|
||||
{
|
||||
stream.next(v.sec);
|
||||
stream.next(v.nsec);
|
||||
}
|
||||
|
||||
inline static uint32_t serializedLength(const ros::Time&)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Serializer specialized for ros::Duration
|
||||
*/
|
||||
template<>
|
||||
struct Serializer<ros::Duration>
|
||||
{
|
||||
template<typename Stream>
|
||||
inline static void write(Stream& stream, const ros::Duration& v)
|
||||
{
|
||||
stream.next(v.sec);
|
||||
stream.next(v.nsec);
|
||||
}
|
||||
|
||||
template<typename Stream>
|
||||
inline static void read(Stream& stream, ros::Duration& v)
|
||||
{
|
||||
stream.next(v.sec);
|
||||
stream.next(v.nsec);
|
||||
}
|
||||
|
||||
inline static uint32_t serializedLength(const ros::Duration&)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Vector serializer. Default implementation does nothing
|
||||
*/
|
||||
template<typename T, class ContainerAllocator, class Enabled = void>
|
||||
struct VectorSerializer
|
||||
{};
|
||||
|
||||
/**
|
||||
* \brief Vector serializer, specialized for non-fixed-size, non-simple types
|
||||
*/
|
||||
template<typename T, class ContainerAllocator>
|
||||
struct VectorSerializer<T, ContainerAllocator, typename boost::disable_if<mt::IsFixedSize<T> >::type >
|
||||
{
|
||||
typedef std::vector<T, typename std::allocator_traits<ContainerAllocator>::template rebind_alloc<T>> VecType;
|
||||
typedef typename VecType::iterator IteratorType;
|
||||
typedef typename VecType::const_iterator ConstIteratorType;
|
||||
|
||||
template<typename Stream>
|
||||
inline static void write(Stream& stream, const VecType& v)
|
||||
{
|
||||
stream.next(static_cast<uint32_t>(v.size()));
|
||||
ConstIteratorType it = v.begin();
|
||||
ConstIteratorType end = v.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
stream.next(*it);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Stream>
|
||||
inline static void read(Stream& stream, VecType& v)
|
||||
{
|
||||
uint32_t len;
|
||||
stream.next(len);
|
||||
v.resize(len);
|
||||
IteratorType it = v.begin();
|
||||
IteratorType end = v.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
stream.next(*it);
|
||||
}
|
||||
}
|
||||
|
||||
inline static uint32_t serializedLength(const VecType& v)
|
||||
{
|
||||
uint32_t size = 4;
|
||||
ConstIteratorType it = v.begin();
|
||||
ConstIteratorType end = v.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
size += serializationLength(*it);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Vector serializer, specialized for fixed-size simple types
|
||||
*/
|
||||
template<typename T, class ContainerAllocator>
|
||||
struct VectorSerializer<T, ContainerAllocator, typename boost::enable_if<mt::IsSimple<T> >::type >
|
||||
{
|
||||
typedef std::vector<T, typename std::allocator_traits<ContainerAllocator>::template rebind_alloc<T>> VecType;
|
||||
typedef typename VecType::iterator IteratorType;
|
||||
typedef typename VecType::const_iterator ConstIteratorType;
|
||||
|
||||
template<typename Stream>
|
||||
inline static void write(Stream& stream, const VecType& v)
|
||||
{
|
||||
uint32_t len = static_cast<uint32_t>(v.size());
|
||||
stream.next(len);
|
||||
if (!v.empty())
|
||||
{
|
||||
const uint32_t data_len = len * static_cast<uint32_t>(sizeof(T));
|
||||
memcpy(stream.advance(data_len), &v.front(), data_len);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Stream>
|
||||
inline static void read(Stream& stream, VecType& v)
|
||||
{
|
||||
uint32_t len;
|
||||
stream.next(len);
|
||||
v.resize(len);
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
const uint32_t data_len = static_cast<uint32_t>(sizeof(T)) * len;
|
||||
memcpy(static_cast<void*>(&v.front()), stream.advance(data_len), data_len);
|
||||
}
|
||||
}
|
||||
|
||||
inline static uint32_t serializedLength(const VecType& v)
|
||||
{
|
||||
return 4 + v.size() * static_cast<uint32_t>(sizeof(T));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Vector serializer, specialized for fixed-size non-simple types
|
||||
*/
|
||||
template<typename T, class ContainerAllocator>
|
||||
struct VectorSerializer<T, ContainerAllocator, typename boost::enable_if<mpl::and_<mt::IsFixedSize<T>, mpl::not_<mt::IsSimple<T> > > >::type >
|
||||
{
|
||||
typedef std::vector<T, typename std::allocator_traits<ContainerAllocator>::template rebind_alloc<T>> VecType;
|
||||
typedef typename VecType::iterator IteratorType;
|
||||
typedef typename VecType::const_iterator ConstIteratorType;
|
||||
|
||||
template<typename Stream>
|
||||
inline static void write(Stream& stream, const VecType& v)
|
||||
{
|
||||
stream.next(static_cast<uint32_t>(v.size()));
|
||||
ConstIteratorType it = v.begin();
|
||||
ConstIteratorType end = v.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
stream.next(*it);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Stream>
|
||||
inline static void read(Stream& stream, VecType& v)
|
||||
{
|
||||
uint32_t len;
|
||||
stream.next(len);
|
||||
v.resize(len);
|
||||
IteratorType it = v.begin();
|
||||
IteratorType end = v.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
stream.next(*it);
|
||||
}
|
||||
}
|
||||
|
||||
inline static uint32_t serializedLength(const VecType& v)
|
||||
{
|
||||
uint32_t size = 4;
|
||||
if (!v.empty())
|
||||
{
|
||||
uint32_t len_each = serializationLength(v.front());
|
||||
size += len_each * static_cast<uint32_t>(v.size());
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief serialize version for std::vector
|
||||
*/
|
||||
template<typename T, class ContainerAllocator, typename Stream>
|
||||
inline void serialize(Stream& stream, const std::vector<T, ContainerAllocator>& t)
|
||||
{
|
||||
VectorSerializer<T, ContainerAllocator>::write(stream, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief deserialize version for std::vector
|
||||
*/
|
||||
template<typename T, class ContainerAllocator, typename Stream>
|
||||
inline void deserialize(Stream& stream, std::vector<T, ContainerAllocator>& t)
|
||||
{
|
||||
VectorSerializer<T, ContainerAllocator>::read(stream, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief serializationLength version for std::vector
|
||||
*/
|
||||
template<typename T, class ContainerAllocator>
|
||||
inline uint32_t serializationLength(const std::vector<T, ContainerAllocator>& t)
|
||||
{
|
||||
return VectorSerializer<T, ContainerAllocator>::serializedLength(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Array serializer, default implementation does nothing
|
||||
*/
|
||||
template<typename T, size_t N, class Enabled = void>
|
||||
struct ArraySerializer
|
||||
{};
|
||||
|
||||
/**
|
||||
* \brief Array serializer, specialized for non-fixed-size, non-simple types
|
||||
*/
|
||||
template<typename T, size_t N>
|
||||
struct ArraySerializer<T, N, typename boost::disable_if<mt::IsFixedSize<T> >::type>
|
||||
{
|
||||
typedef boost::array<T, N > ArrayType;
|
||||
typedef typename ArrayType::iterator IteratorType;
|
||||
typedef typename ArrayType::const_iterator ConstIteratorType;
|
||||
|
||||
template<typename Stream>
|
||||
inline static void write(Stream& stream, const ArrayType& v)
|
||||
{
|
||||
ConstIteratorType it = v.begin();
|
||||
ConstIteratorType end = v.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
stream.next(*it);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Stream>
|
||||
inline static void read(Stream& stream, ArrayType& v)
|
||||
{
|
||||
IteratorType it = v.begin();
|
||||
IteratorType end = v.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
stream.next(*it);
|
||||
}
|
||||
}
|
||||
|
||||
inline static uint32_t serializedLength(const ArrayType& v)
|
||||
{
|
||||
uint32_t size = 0;
|
||||
ConstIteratorType it = v.begin();
|
||||
ConstIteratorType end = v.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
size += serializationLength(*it);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Array serializer, specialized for fixed-size, simple types
|
||||
*/
|
||||
template<typename T, size_t N>
|
||||
struct ArraySerializer<T, N, typename boost::enable_if<mt::IsSimple<T> >::type>
|
||||
{
|
||||
typedef boost::array<T, N > ArrayType;
|
||||
typedef typename ArrayType::iterator IteratorType;
|
||||
typedef typename ArrayType::const_iterator ConstIteratorType;
|
||||
|
||||
template<typename Stream>
|
||||
inline static void write(Stream& stream, const ArrayType& v)
|
||||
{
|
||||
const uint32_t data_len = N * sizeof(T);
|
||||
memcpy(stream.advance(data_len), &v.front(), data_len);
|
||||
}
|
||||
|
||||
template<typename Stream>
|
||||
inline static void read(Stream& stream, ArrayType& v)
|
||||
{
|
||||
const uint32_t data_len = N * sizeof(T);
|
||||
memcpy(&v.front(), stream.advance(data_len), data_len);
|
||||
}
|
||||
|
||||
inline static uint32_t serializedLength(const ArrayType&)
|
||||
{
|
||||
return N * sizeof(T);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Array serializer, specialized for fixed-size, non-simple types
|
||||
*/
|
||||
template<typename T, size_t N>
|
||||
struct ArraySerializer<T, N, typename boost::enable_if<mpl::and_<mt::IsFixedSize<T>, mpl::not_<mt::IsSimple<T> > > >::type>
|
||||
{
|
||||
typedef boost::array<T, N > ArrayType;
|
||||
typedef typename ArrayType::iterator IteratorType;
|
||||
typedef typename ArrayType::const_iterator ConstIteratorType;
|
||||
|
||||
template<typename Stream>
|
||||
inline static void write(Stream& stream, const ArrayType& v)
|
||||
{
|
||||
ConstIteratorType it = v.begin();
|
||||
ConstIteratorType end = v.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
stream.next(*it);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Stream>
|
||||
inline static void read(Stream& stream, ArrayType& v)
|
||||
{
|
||||
IteratorType it = v.begin();
|
||||
IteratorType end = v.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
stream.next(*it);
|
||||
}
|
||||
}
|
||||
|
||||
inline static uint32_t serializedLength(const ArrayType& v)
|
||||
{
|
||||
return serializationLength(v.front()) * N;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief serialize version for boost::array
|
||||
*/
|
||||
template<typename T, size_t N, typename Stream>
|
||||
inline void serialize(Stream& stream, const boost::array<T, N>& t)
|
||||
{
|
||||
ArraySerializer<T, N>::write(stream, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief deserialize version for boost::array
|
||||
*/
|
||||
template<typename T, size_t N, typename Stream>
|
||||
inline void deserialize(Stream& stream, boost::array<T, N>& t)
|
||||
{
|
||||
ArraySerializer<T, N>::read(stream, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief serializationLength version for boost::array
|
||||
*/
|
||||
template<typename T, size_t N>
|
||||
inline uint32_t serializationLength(const boost::array<T, N>& t)
|
||||
{
|
||||
return ArraySerializer<T, N>::serializedLength(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Enum
|
||||
*/
|
||||
namespace stream_types
|
||||
{
|
||||
enum StreamType
|
||||
{
|
||||
Input,
|
||||
Output,
|
||||
Length
|
||||
};
|
||||
}
|
||||
typedef stream_types::StreamType StreamType;
|
||||
|
||||
/**
|
||||
* \brief Stream base-class, provides common functionality for IStream and OStream
|
||||
*/
|
||||
struct ROSCPP_SERIALIZATION_DECL Stream
|
||||
{
|
||||
/*
|
||||
* \brief Returns a pointer to the current position of the stream
|
||||
*/
|
||||
inline uint8_t* getData() { return data_; }
|
||||
/**
|
||||
* \brief Advances the stream, checking bounds, and returns a pointer to the position before it
|
||||
* was advanced.
|
||||
* \throws StreamOverrunException if len would take this stream past the end of its buffer
|
||||
*/
|
||||
ROS_FORCE_INLINE uint8_t* advance(uint32_t len)
|
||||
{
|
||||
uint8_t* old_data = data_;
|
||||
data_ += len;
|
||||
if (data_ > end_)
|
||||
{
|
||||
// Throwing directly here causes a significant speed hit due to the extra code generated
|
||||
// for the throw statement
|
||||
throwStreamOverrun();
|
||||
}
|
||||
return old_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns the amount of space left in the stream
|
||||
*/
|
||||
inline uint32_t getLength() { return static_cast<uint32_t>(end_ - data_); }
|
||||
|
||||
protected:
|
||||
Stream(uint8_t* _data, uint32_t _count)
|
||||
: data_(_data)
|
||||
, end_(_data + _count)
|
||||
{}
|
||||
|
||||
private:
|
||||
uint8_t* data_;
|
||||
uint8_t* end_;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Input stream
|
||||
*/
|
||||
struct ROSCPP_SERIALIZATION_DECL IStream : public Stream
|
||||
{
|
||||
static const StreamType stream_type = stream_types::Input;
|
||||
|
||||
IStream(uint8_t* data, uint32_t count)
|
||||
: Stream(data, count)
|
||||
{}
|
||||
|
||||
/**
|
||||
* \brief Deserialize an item from this input stream
|
||||
*/
|
||||
template<typename T>
|
||||
ROS_FORCE_INLINE void next(T& t)
|
||||
{
|
||||
deserialize(*this, t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ROS_FORCE_INLINE IStream& operator>>(T& t)
|
||||
{
|
||||
deserialize(*this, t);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Output stream
|
||||
*/
|
||||
struct ROSCPP_SERIALIZATION_DECL OStream : public Stream
|
||||
{
|
||||
static const StreamType stream_type = stream_types::Output;
|
||||
|
||||
OStream(uint8_t* data, uint32_t count)
|
||||
: Stream(data, count)
|
||||
{}
|
||||
|
||||
/**
|
||||
* \brief Serialize an item to this output stream
|
||||
*/
|
||||
template<typename T>
|
||||
ROS_FORCE_INLINE void next(const T& t)
|
||||
{
|
||||
serialize(*this, t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ROS_FORCE_INLINE OStream& operator<<(const T& t)
|
||||
{
|
||||
serialize(*this, t);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Length stream
|
||||
*
|
||||
* LStream is not what you would normally think of as a stream, but it is used in order to support
|
||||
* allinone serializers.
|
||||
*/
|
||||
struct ROSCPP_SERIALIZATION_DECL LStream
|
||||
{
|
||||
static const StreamType stream_type = stream_types::Length;
|
||||
|
||||
LStream()
|
||||
: count_(0)
|
||||
{}
|
||||
|
||||
/**
|
||||
* \brief Add the length of an item to this length stream
|
||||
*/
|
||||
template<typename T>
|
||||
ROS_FORCE_INLINE void next(const T& t)
|
||||
{
|
||||
count_ += serializationLength(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief increment the length by len
|
||||
*/
|
||||
ROS_FORCE_INLINE uint32_t advance(uint32_t len)
|
||||
{
|
||||
uint32_t old = count_;
|
||||
count_ += len;
|
||||
return old;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get the total length of this tream
|
||||
*/
|
||||
inline uint32_t getLength() { return count_; }
|
||||
|
||||
private:
|
||||
uint32_t count_;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Serialize a message
|
||||
*/
|
||||
template<typename M>
|
||||
inline SerializedMessage serializeMessage(const M& message)
|
||||
{
|
||||
SerializedMessage m;
|
||||
uint32_t len = serializationLength(message);
|
||||
m.num_bytes = len + 4;
|
||||
m.buf.reset(new uint8_t[m.num_bytes]);
|
||||
|
||||
OStream s(m.buf.get(), static_cast<uint32_t>(m.num_bytes));
|
||||
serialize(s, static_cast<uint32_t>(m.num_bytes) - 4);
|
||||
m.message_start = s.getData();
|
||||
serialize(s, message);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Serialize a service response
|
||||
*/
|
||||
template<typename M>
|
||||
inline SerializedMessage serializeServiceResponse(bool ok, const M& message)
|
||||
{
|
||||
SerializedMessage m;
|
||||
|
||||
if (ok)
|
||||
{
|
||||
uint32_t len = serializationLength(message);
|
||||
m.num_bytes = len + 5;
|
||||
m.buf.reset(new uint8_t[m.num_bytes]);
|
||||
|
||||
OStream s(m.buf.get(), static_cast<uint32_t>(m.num_bytes));
|
||||
serialize(s, static_cast<uint8_t>(ok));
|
||||
serialize(s, static_cast<uint32_t>(m.num_bytes) - 5);
|
||||
serialize(s, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t len = serializationLength(message);
|
||||
m.num_bytes = len + 1;
|
||||
m.buf.reset(new uint8_t[m.num_bytes]);
|
||||
|
||||
OStream s(m.buf.get(), static_cast<uint32_t>(m.num_bytes));
|
||||
serialize(s, static_cast<uint8_t>(ok));
|
||||
serialize(s, message);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Deserialize a message. If includes_length is true, skips the first 4 bytes
|
||||
*/
|
||||
template<typename M>
|
||||
inline void deserializeMessage(const SerializedMessage& m, M& message)
|
||||
{
|
||||
IStream s(m.message_start, static_cast<uint32_t>(m.num_bytes - (m.message_start - m.buf.get())));
|
||||
deserialize(s, message);
|
||||
}
|
||||
|
||||
// Additional serialization traits
|
||||
|
||||
template<typename M>
|
||||
struct PreDeserializeParams
|
||||
{
|
||||
boost::shared_ptr<M> message;
|
||||
boost::shared_ptr<std::map<std::string, std::string> > connection_header;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief called by the SubscriptionCallbackHelper after a message is
|
||||
* instantiated but before that message is deserialized
|
||||
*/
|
||||
template<typename M>
|
||||
struct PreDeserialize
|
||||
{
|
||||
static void notify(const PreDeserializeParams<M>&) { }
|
||||
};
|
||||
|
||||
} // namespace serialization
|
||||
|
||||
} // namespace ros
|
||||
|
||||
#endif // ROSCPP_SERIALIZATION_H
|
||||
66
thirdparty/ros/roscpp_core/roscpp_serialization/include/ros/serialized_message.h
vendored
Normal file
66
thirdparty/ros/roscpp_core/roscpp_serialization/include/ros/serialized_message.h
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2009, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ROSLIB_SERIALIZED_MESSAGE_H
|
||||
#define ROSLIB_SERIALIZED_MESSAGE_H
|
||||
|
||||
#include "roscpp_serialization_macros.h"
|
||||
|
||||
#include <boost/shared_array.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
namespace ros
|
||||
{
|
||||
|
||||
class ROSCPP_SERIALIZATION_DECL SerializedMessage
|
||||
{
|
||||
public:
|
||||
boost::shared_array<uint8_t> buf;
|
||||
size_t num_bytes;
|
||||
uint8_t* message_start;
|
||||
|
||||
boost::shared_ptr<void const> message;
|
||||
const std::type_info* type_info;
|
||||
|
||||
SerializedMessage()
|
||||
: buf(boost::shared_array<uint8_t>())
|
||||
, num_bytes(0)
|
||||
, message_start(0)
|
||||
, type_info(0)
|
||||
{}
|
||||
|
||||
SerializedMessage(boost::shared_array<uint8_t> buf, size_t num_bytes)
|
||||
: buf(buf)
|
||||
, num_bytes(num_bytes)
|
||||
, message_start(buf ? buf.get() : 0)
|
||||
, type_info(0)
|
||||
{ }
|
||||
};
|
||||
|
||||
} // namespace ros
|
||||
|
||||
#endif // ROSLIB_SERIALIZED_MESSAGE_H
|
||||
25
thirdparty/ros/roscpp_core/roscpp_serialization/package.xml
vendored
Normal file
25
thirdparty/ros/roscpp_core/roscpp_serialization/package.xml
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<package>
|
||||
<name>roscpp_serialization</name>
|
||||
<version>0.7.2</version>
|
||||
<description>
|
||||
roscpp_serialization contains the code for serialization as described in
|
||||
<a href="http://www.ros.org/wiki/roscpp/Overview/MessagesSerializationAndAdaptingTypes">MessagesSerializationAndAdaptingTypes</a>.
|
||||
|
||||
This package is a component of <a href="http://www.ros.org/wiki/roscpp">roscpp</a>.
|
||||
</description>
|
||||
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
|
||||
<license>BSD</license>
|
||||
|
||||
<url>http://ros.org/wiki/roscpp_serialization</url>
|
||||
<author>Josh Faust</author>
|
||||
|
||||
<buildtool_depend>catkin</buildtool_depend>
|
||||
|
||||
<build_depend>cpp_common</build_depend>
|
||||
<build_depend>roscpp_traits</build_depend>
|
||||
<build_depend>rostime</build_depend>
|
||||
|
||||
<run_depend>cpp_common</run_depend>
|
||||
<run_depend>roscpp_traits</run_depend>
|
||||
<run_depend>rostime</run_depend>
|
||||
</package>
|
||||
39
thirdparty/ros/roscpp_core/roscpp_serialization/src/serialization.cpp
vendored
Normal file
39
thirdparty/ros/roscpp_core/roscpp_serialization/src/serialization.cpp
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2009, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <ros/serialization.h>
|
||||
|
||||
namespace ros
|
||||
{
|
||||
namespace serialization
|
||||
{
|
||||
void throwStreamOverrun()
|
||||
{
|
||||
throw StreamOverrunException("Buffer Overrun");
|
||||
}
|
||||
}
|
||||
}
|
||||
121
thirdparty/ros/roscpp_core/roscpp_traits/CHANGELOG.rst
vendored
Normal file
121
thirdparty/ros/roscpp_core/roscpp_traits/CHANGELOG.rst
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Changelog for package roscpp_traits
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
0.7.2 (2020-05-28)
|
||||
------------------
|
||||
|
||||
0.7.1 (2020-01-25)
|
||||
------------------
|
||||
|
||||
0.7.0 (2020-01-24)
|
||||
------------------
|
||||
* various code cleanup (`#116 <https://github.com/ros/roscpp_core/issues/116>`_)
|
||||
* Bump CMake version to avoid CMP0048 warning (`#115 <https://github.com/ros/roscpp_core/issues/115>`_)
|
||||
|
||||
0.6.13 (2019-10-03)
|
||||
-------------------
|
||||
|
||||
0.6.12 (2019-03-04)
|
||||
-------------------
|
||||
|
||||
0.6.11 (2018-06-06)
|
||||
-------------------
|
||||
|
||||
0.6.10 (2018-05-01)
|
||||
-------------------
|
||||
|
||||
0.6.9 (2018-02-02)
|
||||
------------------
|
||||
|
||||
0.6.8 (2018-01-26)
|
||||
------------------
|
||||
|
||||
0.6.7 (2017-11-03)
|
||||
------------------
|
||||
|
||||
0.6.6 (2017-10-25)
|
||||
------------------
|
||||
* fix assignment operator of MessageEvent (`#66 <https://github.com/ros/roscpp_core/issues/66>`_)
|
||||
* fix docblock of ROS_DECLARE_MESSAGE_WITH_ALLOCATOR (`#67 <https://github.com/ros/roscpp_core/issues/67>`_)
|
||||
|
||||
0.6.5 (2017-07-27)
|
||||
------------------
|
||||
|
||||
0.6.4 (2017-06-06)
|
||||
------------------
|
||||
|
||||
0.6.3 (2017-05-15)
|
||||
------------------
|
||||
|
||||
0.6.2 (2017-02-14)
|
||||
------------------
|
||||
* fix warning when compiling with -Wpedantic (`#53 <https://github.com/ros/roscpp_core/issues/53>`_)
|
||||
* fix warning about unused parameters (`#52 <https://github.com/ros/roscpp_core/issues/52>`_)
|
||||
|
||||
0.6.1 (2016-09-02)
|
||||
------------------
|
||||
|
||||
0.6.0 (2016-03-17)
|
||||
------------------
|
||||
|
||||
0.5.7 (2016-03-09)
|
||||
------------------
|
||||
|
||||
0.5.6 (2015-05-20)
|
||||
------------------
|
||||
* fix for compile issue on OS X 10.10 (`#34 <https://github.com/ros/roscpp_core/pull/34>`_)
|
||||
|
||||
0.5.5 (2014-12-22)
|
||||
------------------
|
||||
|
||||
0.5.4 (2014-07-23)
|
||||
------------------
|
||||
|
||||
0.5.3 (2014-06-28)
|
||||
------------------
|
||||
|
||||
0.5.2 (2014-06-27)
|
||||
------------------
|
||||
|
||||
0.5.1 (2014-06-24)
|
||||
------------------
|
||||
|
||||
0.5.0 (2014-02-19)
|
||||
------------------
|
||||
|
||||
0.4.2 (2014-02-11)
|
||||
------------------
|
||||
* Revert "remove MessageEvent constructors from Message" (revert changes from 0.4.1)
|
||||
|
||||
0.4.1 (2014-02-11)
|
||||
------------------
|
||||
* remove MessageEvent constructors from Message (`#21 <https://github.com/ros/roscpp_core/issues/21>`_)
|
||||
|
||||
0.4.0 (2014-01-29)
|
||||
------------------
|
||||
* ros::MessageEvent no longer reads __connection_header from ROS message (`#19 <https://github.com/ros/roscpp_core/issues/19>`_)
|
||||
|
||||
0.3.17 (2014-01-07)
|
||||
-------------------
|
||||
* move several client library independent parts from ros_comm into roscpp_core (`#12 <https://github.com/ros/roscpp_core/issues/12>`_)
|
||||
* fix compilation with libc++ (`#15 <https://github.com/ros/roscpp_core/issues/15>`_)
|
||||
|
||||
0.3.16 (2013-07-14)
|
||||
-------------------
|
||||
|
||||
0.3.15 (2013-06-06)
|
||||
-------------------
|
||||
|
||||
0.3.14 (2013-03-21)
|
||||
-------------------
|
||||
|
||||
0.3.13 (2013-03-08)
|
||||
-------------------
|
||||
|
||||
0.3.12 (2013-01-13)
|
||||
-------------------
|
||||
|
||||
0.3.11 (2012-12-21)
|
||||
-------------------
|
||||
* first public release for Groovy
|
||||
10
thirdparty/ros/roscpp_core/roscpp_traits/CMakeLists.txt
vendored
Normal file
10
thirdparty/ros/roscpp_core/roscpp_traits/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.0.2)
|
||||
project(roscpp_traits)
|
||||
find_package(catkin REQUIRED)
|
||||
catkin_package(
|
||||
INCLUDE_DIRS include
|
||||
CATKIN_DEPENDS cpp_common rostime)
|
||||
|
||||
install(DIRECTORY include/
|
||||
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
62
thirdparty/ros/roscpp_core/roscpp_traits/include/ros/builtin_message_traits.h
vendored
Normal file
62
thirdparty/ros/roscpp_core/roscpp_traits/include/ros/builtin_message_traits.h
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2009, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ROSLIB_BUILTIN_MESSAGE_TRAITS_H
|
||||
#define ROSLIB_BUILTIN_MESSAGE_TRAITS_H
|
||||
|
||||
#include "message_traits.h"
|
||||
#include "ros/time.h"
|
||||
|
||||
namespace ros
|
||||
{
|
||||
namespace message_traits
|
||||
{
|
||||
|
||||
#define ROSLIB_CREATE_SIMPLE_TRAITS(Type) \
|
||||
template<> struct IsSimple<Type> : public TrueType {}; \
|
||||
template<> struct IsFixedSize<Type> : public TrueType {};
|
||||
|
||||
ROSLIB_CREATE_SIMPLE_TRAITS(uint8_t)
|
||||
ROSLIB_CREATE_SIMPLE_TRAITS(int8_t)
|
||||
ROSLIB_CREATE_SIMPLE_TRAITS(uint16_t)
|
||||
ROSLIB_CREATE_SIMPLE_TRAITS(int16_t)
|
||||
ROSLIB_CREATE_SIMPLE_TRAITS(uint32_t)
|
||||
ROSLIB_CREATE_SIMPLE_TRAITS(int32_t)
|
||||
ROSLIB_CREATE_SIMPLE_TRAITS(uint64_t)
|
||||
ROSLIB_CREATE_SIMPLE_TRAITS(int64_t)
|
||||
ROSLIB_CREATE_SIMPLE_TRAITS(float)
|
||||
ROSLIB_CREATE_SIMPLE_TRAITS(double)
|
||||
ROSLIB_CREATE_SIMPLE_TRAITS(Time)
|
||||
ROSLIB_CREATE_SIMPLE_TRAITS(Duration)
|
||||
|
||||
// because std::vector<bool> is not a true vector, bool is not a simple type
|
||||
template<> struct IsFixedSize<bool> : public TrueType {};
|
||||
|
||||
} // namespace message_traits
|
||||
} // namespace ros
|
||||
|
||||
#endif // ROSLIB_BUILTIN_MESSAGE_TRAITS_H
|
||||
255
thirdparty/ros/roscpp_core/roscpp_traits/include/ros/message_event.h
vendored
Normal file
255
thirdparty/ros/roscpp_core/roscpp_traits/include/ros/message_event.h
vendored
Normal file
@@ -0,0 +1,255 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) 2010, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ROSCPP_MESSAGE_EVENT_H
|
||||
#define ROSCPP_MESSAGE_EVENT_H
|
||||
|
||||
#include "ros/time.h"
|
||||
#include <ros/datatypes.h>
|
||||
#include <ros/message_traits.h>
|
||||
|
||||
#include <boost/type_traits/is_void.hpp>
|
||||
#include <boost/type_traits/is_base_of.hpp>
|
||||
#include <boost/type_traits/is_const.hpp>
|
||||
#include <boost/type_traits/add_const.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
namespace ros
|
||||
{
|
||||
|
||||
template<typename M>
|
||||
struct DefaultMessageCreator
|
||||
{
|
||||
boost::shared_ptr<M> operator()()
|
||||
{
|
||||
return boost::make_shared<M>();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename M>
|
||||
ROS_DEPRECATED inline boost::shared_ptr<M> defaultMessageCreateFunction()
|
||||
{
|
||||
return DefaultMessageCreator<M>()();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Event type for subscriptions, const ros::MessageEvent<M const>& can be used in your callback instead of const boost::shared_ptr<M const>&
|
||||
*
|
||||
* Useful if you need to retrieve meta-data about the message, such as the full connection header, or the publisher's node name
|
||||
*/
|
||||
template<typename M>
|
||||
class MessageEvent
|
||||
{
|
||||
public:
|
||||
typedef typename boost::add_const<M>::type ConstMessage;
|
||||
typedef typename boost::remove_const<M>::type Message;
|
||||
typedef boost::shared_ptr<Message> MessagePtr;
|
||||
typedef boost::shared_ptr<ConstMessage> ConstMessagePtr;
|
||||
typedef boost::function<MessagePtr()> CreateFunction;
|
||||
|
||||
MessageEvent()
|
||||
: nonconst_need_copy_(true)
|
||||
{}
|
||||
|
||||
MessageEvent(const MessageEvent<Message>& rhs)
|
||||
{
|
||||
*this = rhs;
|
||||
}
|
||||
|
||||
MessageEvent(const MessageEvent<ConstMessage>& rhs)
|
||||
{
|
||||
*this = rhs;
|
||||
}
|
||||
|
||||
MessageEvent(const MessageEvent<Message>& rhs, bool nonconst_need_copy)
|
||||
{
|
||||
*this = rhs;
|
||||
nonconst_need_copy_ = nonconst_need_copy;
|
||||
}
|
||||
|
||||
MessageEvent(const MessageEvent<ConstMessage>& rhs, bool nonconst_need_copy)
|
||||
{
|
||||
*this = rhs;
|
||||
nonconst_need_copy_ = nonconst_need_copy;
|
||||
}
|
||||
|
||||
MessageEvent(const MessageEvent<void const>& rhs, const CreateFunction& create)
|
||||
{
|
||||
init(boost::const_pointer_cast<Message>(boost::static_pointer_cast<ConstMessage>(rhs.getMessage())), rhs.getConnectionHeaderPtr(), rhs.getReceiptTime(), rhs.nonConstWillCopy(), create);
|
||||
}
|
||||
|
||||
/**
|
||||
* \todo Make this explicit in ROS 2.0. Keep as auto-converting for now to maintain backwards compatibility in some places (message_filters)
|
||||
*/
|
||||
MessageEvent(const ConstMessagePtr& message)
|
||||
{
|
||||
init(message, boost::shared_ptr<M_string>(), ros::Time::now(), true, ros::DefaultMessageCreator<Message>());
|
||||
}
|
||||
|
||||
MessageEvent(const ConstMessagePtr& message, const boost::shared_ptr<M_string>& connection_header, ros::Time receipt_time)
|
||||
{
|
||||
init(message, connection_header, receipt_time, true, ros::DefaultMessageCreator<Message>());
|
||||
}
|
||||
|
||||
MessageEvent(const ConstMessagePtr& message, ros::Time receipt_time)
|
||||
{
|
||||
init(message, boost::shared_ptr<M_string>(), receipt_time, true, ros::DefaultMessageCreator<Message>());
|
||||
}
|
||||
|
||||
MessageEvent(const ConstMessagePtr& message, const boost::shared_ptr<M_string>& connection_header, ros::Time receipt_time, bool nonconst_need_copy, const CreateFunction& create)
|
||||
{
|
||||
init(message, connection_header, receipt_time, nonconst_need_copy, create);
|
||||
}
|
||||
|
||||
void init(const ConstMessagePtr& message, const boost::shared_ptr<M_string>& connection_header, ros::Time receipt_time, bool nonconst_need_copy, const CreateFunction& create)
|
||||
{
|
||||
message_ = message;
|
||||
connection_header_ = connection_header;
|
||||
receipt_time_ = receipt_time;
|
||||
nonconst_need_copy_ = nonconst_need_copy;
|
||||
create_ = create;
|
||||
}
|
||||
|
||||
void operator=(const MessageEvent<Message>& rhs)
|
||||
{
|
||||
init(boost::static_pointer_cast<Message>(rhs.getMessage()), rhs.getConnectionHeaderPtr(), rhs.getReceiptTime(), rhs.nonConstWillCopy(), rhs.getMessageFactory());
|
||||
message_copy_.reset();
|
||||
}
|
||||
|
||||
void operator=(const MessageEvent<ConstMessage>& rhs)
|
||||
{
|
||||
init(boost::const_pointer_cast<Message>(boost::static_pointer_cast<ConstMessage>(rhs.getMessage())), rhs.getConnectionHeaderPtr(), rhs.getReceiptTime(), rhs.nonConstWillCopy(), rhs.getMessageFactory());
|
||||
message_copy_.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retrieve the message. If M is const, this returns a reference to it. If M is non const
|
||||
* and this event requires it, returns a copy. Note that it caches this copy for later use, so it will
|
||||
* only every make the copy once
|
||||
*/
|
||||
boost::shared_ptr<M> getMessage() const
|
||||
{
|
||||
return copyMessageIfNecessary<M>();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retrieve a const version of the message
|
||||
*/
|
||||
const boost::shared_ptr<ConstMessage>& getConstMessage() const { return message_; }
|
||||
/**
|
||||
* \brief Retrieve the connection header
|
||||
*/
|
||||
M_string& getConnectionHeader() const { return *connection_header_; }
|
||||
const boost::shared_ptr<M_string>& getConnectionHeaderPtr() const { return connection_header_; }
|
||||
|
||||
/**
|
||||
* \brief Returns the name of the node which published this message
|
||||
*/
|
||||
const std::string& getPublisherName() const { return connection_header_ ? (*connection_header_)["callerid"] : s_unknown_publisher_string_; }
|
||||
|
||||
/**
|
||||
* \brief Returns the time at which this message was received
|
||||
*/
|
||||
ros::Time getReceiptTime() const { return receipt_time_; }
|
||||
|
||||
bool nonConstWillCopy() const { return nonconst_need_copy_; }
|
||||
bool getMessageWillCopy() const { return !boost::is_const<M>::value && nonconst_need_copy_; }
|
||||
|
||||
bool operator<(const MessageEvent<M>& rhs)
|
||||
{
|
||||
if (message_ != rhs.message_)
|
||||
{
|
||||
return message_ < rhs.message_;
|
||||
}
|
||||
|
||||
if (receipt_time_ != rhs.receipt_time_)
|
||||
{
|
||||
return receipt_time_ < rhs.receipt_time_;
|
||||
}
|
||||
|
||||
return nonconst_need_copy_ < rhs.nonconst_need_copy_;
|
||||
}
|
||||
|
||||
bool operator==(const MessageEvent<M>& rhs)
|
||||
{
|
||||
return message_ == rhs.message_ && receipt_time_ == rhs.receipt_time_ && nonconst_need_copy_ == rhs.nonconst_need_copy_;
|
||||
}
|
||||
|
||||
bool operator!=(const MessageEvent<M>& rhs)
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
const CreateFunction& getMessageFactory() const { return create_; }
|
||||
|
||||
private:
|
||||
template<typename M2>
|
||||
typename boost::disable_if<boost::is_void<M2>, boost::shared_ptr<M> >::type copyMessageIfNecessary() const
|
||||
{
|
||||
if (boost::is_const<M>::value || !nonconst_need_copy_)
|
||||
{
|
||||
return boost::const_pointer_cast<Message>(message_);
|
||||
}
|
||||
|
||||
if (message_copy_)
|
||||
{
|
||||
return message_copy_;
|
||||
}
|
||||
|
||||
assert(create_);
|
||||
message_copy_ = create_();
|
||||
*message_copy_ = *message_;
|
||||
|
||||
return message_copy_;
|
||||
}
|
||||
|
||||
template<typename M2>
|
||||
typename boost::enable_if<boost::is_void<M2>, boost::shared_ptr<M> >::type copyMessageIfNecessary() const
|
||||
{
|
||||
return boost::const_pointer_cast<Message>(message_);
|
||||
}
|
||||
|
||||
ConstMessagePtr message_;
|
||||
// Kind of ugly to make this mutable, but it means we can pass a const MessageEvent to a callback and not worry about other things being modified
|
||||
mutable MessagePtr message_copy_;
|
||||
boost::shared_ptr<M_string> connection_header_;
|
||||
ros::Time receipt_time_;
|
||||
bool nonconst_need_copy_;
|
||||
CreateFunction create_;
|
||||
|
||||
static const std::string s_unknown_publisher_string_;
|
||||
};
|
||||
|
||||
template<typename M> const std::string MessageEvent<M>::s_unknown_publisher_string_("unknown_publisher");
|
||||
|
||||
}
|
||||
|
||||
#endif // ROSCPP_MESSAGE_EVENT_H
|
||||
70
thirdparty/ros/roscpp_core/roscpp_traits/include/ros/message_forward.h
vendored
Normal file
70
thirdparty/ros/roscpp_core/roscpp_traits/include/ros/message_forward.h
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2009, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ROSLIB_MESSAGE_FORWARD_H
|
||||
#define ROSLIB_MESSAGE_FORWARD_H
|
||||
|
||||
// Make sure that either __GLIBCXX__ or _LIBCPP_VERSION is defined.
|
||||
#include <cstddef>
|
||||
|
||||
// C++ standard section 17.4.3.1/1 states that forward declarations of STL types
|
||||
// that aren't specializations involving user defined types results in undefined
|
||||
// behavior. Apparently only libc++ has a problem with this and won't compile it.
|
||||
#ifndef _LIBCPP_VERSION
|
||||
namespace std
|
||||
{
|
||||
template<typename T> class allocator;
|
||||
}
|
||||
#else
|
||||
#include <memory>
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template<typename T> class shared_ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Forward-declare a message, including Ptr and ConstPtr types, with an allocator
|
||||
*
|
||||
* \param msg The "base" message type, i.e., the name of the .msg file
|
||||
* \param new_name The name you'd like the message to have
|
||||
* \param alloc The allocator to use, e.g. std::allocator
|
||||
*/
|
||||
#define ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(msg, new_name, alloc) \
|
||||
template<class Allocator> struct msg##_; \
|
||||
typedef msg##_<alloc<void> > new_name; \
|
||||
typedef boost::shared_ptr<new_name> new_name##Ptr; \
|
||||
typedef boost::shared_ptr<new_name const> new_name##ConstPtr;
|
||||
|
||||
/**
|
||||
* \brief Forward-declare a message, including Ptr and ConstPtr types, using std::allocator
|
||||
* \param msg The "base" message type, i.e. the name of the .msg file
|
||||
*/
|
||||
#define ROS_DECLARE_MESSAGE(msg) ROS_DECLARE_MESSAGE_WITH_ALLOCATOR(msg, msg, std::allocator)
|
||||
|
||||
#endif // ROSLIB_MESSAGE_FORWARD_H
|
||||
76
thirdparty/ros/roscpp_core/roscpp_traits/include/ros/message_operations.h
vendored
Normal file
76
thirdparty/ros/roscpp_core/roscpp_traits/include/ros/message_operations.h
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2010, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ROSLIB_MESSAGE_OPERATIONS_H
|
||||
#define ROSLIB_MESSAGE_OPERATIONS_H
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace ros
|
||||
{
|
||||
namespace message_operations
|
||||
{
|
||||
|
||||
template<typename M>
|
||||
struct Printer
|
||||
{
|
||||
template<typename Stream>
|
||||
static void stream(Stream& s, const std::string& indent, const M& value)
|
||||
{
|
||||
(void)indent;
|
||||
s << value << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
// Explicitly specialize for uint8_t/int8_t because otherwise it thinks it's a char, and treats
|
||||
// the value as a character code
|
||||
template<>
|
||||
struct Printer<int8_t>
|
||||
{
|
||||
template<typename Stream>
|
||||
static void stream(Stream& s, const std::string& indent, int8_t value)
|
||||
{
|
||||
(void)indent;
|
||||
s << static_cast<int32_t>(value) << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Printer<uint8_t>
|
||||
{
|
||||
template<typename Stream>
|
||||
static void stream(Stream& s, const std::string& indent, uint8_t value)
|
||||
{
|
||||
(void)indent;
|
||||
s << static_cast<uint32_t>(value) << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace message_operations
|
||||
} // namespace ros
|
||||
|
||||
#endif // ROSLIB_MESSAGE_OPERATIONS_H
|
||||
359
thirdparty/ros/roscpp_core/roscpp_traits/include/ros/message_traits.h
vendored
Normal file
359
thirdparty/ros/roscpp_core/roscpp_traits/include/ros/message_traits.h
vendored
Normal file
@@ -0,0 +1,359 @@
|
||||
/*
|
||||
* Copyright (C) 2009, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ROSLIB_MESSAGE_TRAITS_H
|
||||
#define ROSLIB_MESSAGE_TRAITS_H
|
||||
|
||||
#include "message_forward.h"
|
||||
|
||||
#include <ros/time.h>
|
||||
|
||||
#include <string>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
|
||||
namespace std_msgs
|
||||
{
|
||||
ROS_DECLARE_MESSAGE(Header)
|
||||
}
|
||||
|
||||
#define ROS_IMPLEMENT_SIMPLE_TOPIC_TRAITS(msg, md5sum, datatype, definition) \
|
||||
namespace ros \
|
||||
{ \
|
||||
namespace message_traits \
|
||||
{ \
|
||||
template<> struct MD5Sum<msg> \
|
||||
{ \
|
||||
static const char* value() { return md5sum; } \
|
||||
static const char* value(const msg&) { return value(); } \
|
||||
}; \
|
||||
template<> struct DataType<msg> \
|
||||
{ \
|
||||
static const char* value() { return datatype; } \
|
||||
static const char* value(const msg&) { return value(); } \
|
||||
}; \
|
||||
template<> struct Definition<msg> \
|
||||
{ \
|
||||
static const char* value() { return definition; } \
|
||||
static const char* value(const msg&) { return value(); } \
|
||||
}; \
|
||||
} \
|
||||
}
|
||||
|
||||
namespace ros
|
||||
{
|
||||
namespace message_traits
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Base type for compile-type true/false tests. Compatible with Boost.MPL. classes inheriting from this type
|
||||
* are \b true values.
|
||||
*/
|
||||
struct TrueType
|
||||
{
|
||||
static const bool value = true;
|
||||
typedef TrueType type;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Base type for compile-type true/false tests. Compatible with Boost.MPL. classes inheriting from this type
|
||||
* are \b false values.
|
||||
*/
|
||||
struct FalseType
|
||||
{
|
||||
static const bool value = false;
|
||||
typedef FalseType type;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief A simple datatype is one that can be memcpy'd directly in array form, i.e. it's a POD, fixed-size type and
|
||||
* sizeof(M) == sum(serializationLength(M:a...))
|
||||
*/
|
||||
template<typename M> struct IsSimple : public FalseType {};
|
||||
/**
|
||||
* \brief A fixed-size datatype is one whose size is constant, i.e. it has no variable-length arrays or strings
|
||||
*/
|
||||
template<typename M> struct IsFixedSize : public FalseType {};
|
||||
/**
|
||||
* \brief HasHeader informs whether or not there is a header that gets serialized as the first thing in the message
|
||||
*/
|
||||
template<typename M> struct HasHeader : public FalseType {};
|
||||
|
||||
/**
|
||||
* \brief Am I message or not
|
||||
*/
|
||||
template<typename M> struct IsMessage : public FalseType {};
|
||||
|
||||
/**
|
||||
* \brief Specialize to provide the md5sum for a message
|
||||
*/
|
||||
template<typename M>
|
||||
struct MD5Sum
|
||||
{
|
||||
static const char* value()
|
||||
{
|
||||
return M::__s_getMD5Sum().c_str();
|
||||
}
|
||||
|
||||
static const char* value(const M& m)
|
||||
{
|
||||
return m.__getMD5Sum().c_str();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Specialize to provide the datatype for a message
|
||||
*/
|
||||
template<typename M>
|
||||
struct DataType
|
||||
{
|
||||
static const char* value()
|
||||
{
|
||||
return M::__s_getDataType().c_str();
|
||||
}
|
||||
|
||||
static const char* value(const M& m)
|
||||
{
|
||||
return m.__getDataType().c_str();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Specialize to provide the definition for a message
|
||||
*/
|
||||
template<typename M>
|
||||
struct Definition
|
||||
{
|
||||
static const char* value()
|
||||
{
|
||||
return M::__s_getMessageDefinition().c_str();
|
||||
}
|
||||
|
||||
static const char* value(const M& m)
|
||||
{
|
||||
return m.__getMessageDefinition().c_str();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Header trait. In the default implementation pointer()
|
||||
* returns &m.header if HasHeader<M>::value is true, otherwise returns NULL
|
||||
*/
|
||||
template<typename M, typename Enable = void>
|
||||
struct Header
|
||||
{
|
||||
static std_msgs::Header* pointer(M& m) { (void)m; return 0; }
|
||||
static std_msgs::Header const* pointer(const M& m) { (void)m; return 0; }
|
||||
};
|
||||
|
||||
template<typename M>
|
||||
struct Header<M, typename boost::enable_if<HasHeader<M> >::type >
|
||||
{
|
||||
static std_msgs::Header* pointer(M& m) { return &m.header; }
|
||||
static std_msgs::Header const* pointer(const M& m) { return &m.header; }
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief FrameId trait. In the default implementation pointer()
|
||||
* returns &m.header.frame_id if HasHeader<M>::value is true, otherwise returns NULL. value()
|
||||
* does not exist, and causes a compile error
|
||||
*/
|
||||
template<typename M, typename Enable = void>
|
||||
struct FrameId
|
||||
{
|
||||
static std::string* pointer(M& m) { (void)m; return 0; }
|
||||
static std::string const* pointer(const M& m) { (void)m; return 0; }
|
||||
};
|
||||
|
||||
template<typename M>
|
||||
struct FrameId<M, typename boost::enable_if<HasHeader<M> >::type >
|
||||
{
|
||||
static std::string* pointer(M& m) { return &m.header.frame_id; }
|
||||
static std::string const* pointer(const M& m) { return &m.header.frame_id; }
|
||||
static std::string value(const M& m) { return m.header.frame_id; }
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief TimeStamp trait. In the default implementation pointer()
|
||||
* returns &m.header.stamp if HasHeader<M>::value is true, otherwise returns NULL. value()
|
||||
* does not exist, and causes a compile error
|
||||
*/
|
||||
template<typename M, typename Enable = void>
|
||||
struct TimeStamp
|
||||
{
|
||||
static ros::Time* pointer(M& m) { (void)m; return 0; }
|
||||
static ros::Time const* pointer(const M& m) { (void)m; return 0; }
|
||||
};
|
||||
|
||||
template<typename M>
|
||||
struct TimeStamp<M, typename boost::enable_if<HasHeader<M> >::type >
|
||||
{
|
||||
static ros::Time* pointer(typename boost::remove_const<M>::type &m) { return &m.header.stamp; }
|
||||
static ros::Time const* pointer(const M& m) { return &m.header.stamp; }
|
||||
static ros::Time value(const M& m) { return m.header.stamp; }
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief returns MD5Sum<M>::value();
|
||||
*/
|
||||
template<typename M>
|
||||
inline const char* md5sum()
|
||||
{
|
||||
return MD5Sum<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::value();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief returns DataType<M>::value();
|
||||
*/
|
||||
template<typename M>
|
||||
inline const char* datatype()
|
||||
{
|
||||
return DataType<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::value();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief returns Definition<M>::value();
|
||||
*/
|
||||
template<typename M>
|
||||
inline const char* definition()
|
||||
{
|
||||
return Definition<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::value();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief returns MD5Sum<M>::value(m);
|
||||
*/
|
||||
template<typename M>
|
||||
inline const char* md5sum(const M& m)
|
||||
{
|
||||
return MD5Sum<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::value(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief returns DataType<M>::value(m);
|
||||
*/
|
||||
template<typename M>
|
||||
inline const char* datatype(const M& m)
|
||||
{
|
||||
return DataType<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::value(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief returns Definition<M>::value(m);
|
||||
*/
|
||||
template<typename M>
|
||||
inline const char* definition(const M& m)
|
||||
{
|
||||
return Definition<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::value(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief returns Header<M>::pointer(m);
|
||||
*/
|
||||
template<typename M>
|
||||
inline std_msgs::Header* header(M& m)
|
||||
{
|
||||
return Header<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::pointer(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief returns Header<M>::pointer(m);
|
||||
*/
|
||||
template<typename M>
|
||||
inline std_msgs::Header const* header(const M& m)
|
||||
{
|
||||
return Header<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::pointer(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief returns FrameId<M>::pointer(m);
|
||||
*/
|
||||
template<typename M>
|
||||
inline std::string* frameId(M& m)
|
||||
{
|
||||
return FrameId<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::pointer(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief returns FrameId<M>::pointer(m);
|
||||
*/
|
||||
template<typename M>
|
||||
inline std::string const* frameId(const M& m)
|
||||
{
|
||||
return FrameId<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::pointer(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief returns TimeStamp<M>::pointer(m);
|
||||
*/
|
||||
template<typename M>
|
||||
inline ros::Time* timeStamp(M& m)
|
||||
{
|
||||
return TimeStamp<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::pointer(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief returns TimeStamp<M>::pointer(m);
|
||||
*/
|
||||
template<typename M>
|
||||
inline ros::Time const* timeStamp(const M& m)
|
||||
{
|
||||
return TimeStamp<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::pointer(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief returns IsSimple<M>::value;
|
||||
*/
|
||||
template<typename M>
|
||||
inline bool isSimple()
|
||||
{
|
||||
return IsSimple<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::value;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief returns IsFixedSize<M>::value;
|
||||
*/
|
||||
template<typename M>
|
||||
inline bool isFixedSize()
|
||||
{
|
||||
return IsFixedSize<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::value;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief returns HasHeader<M>::value;
|
||||
*/
|
||||
template<typename M>
|
||||
inline bool hasHeader()
|
||||
{
|
||||
return HasHeader<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::value;
|
||||
}
|
||||
|
||||
} // namespace message_traits
|
||||
} // namespace ros
|
||||
|
||||
#endif // ROSLIB_MESSAGE_TRAITS_H
|
||||
112
thirdparty/ros/roscpp_core/roscpp_traits/include/ros/service_traits.h
vendored
Normal file
112
thirdparty/ros/roscpp_core/roscpp_traits/include/ros/service_traits.h
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (C) 2009, Willow Garage, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the names of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ROSCPP_SERVICE_TRAITS_H
|
||||
#define ROSCPP_SERVICE_TRAITS_H
|
||||
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
|
||||
namespace ros
|
||||
{
|
||||
namespace service_traits
|
||||
{
|
||||
|
||||
/**
|
||||
* \brief Specialize to provide the md5sum for a service
|
||||
*/
|
||||
template<typename M>
|
||||
struct MD5Sum
|
||||
{
|
||||
static const char* value()
|
||||
{
|
||||
return M::__s_getServerMD5Sum().c_str();
|
||||
}
|
||||
|
||||
static const char* value(const M& m)
|
||||
{
|
||||
return m.__getServerMD5Sum().c_str();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Specialize to provide the datatype for a service
|
||||
*/
|
||||
template<typename M>
|
||||
struct DataType
|
||||
{
|
||||
static const char* value()
|
||||
{
|
||||
return M::__s_getServiceDataType().c_str();
|
||||
}
|
||||
|
||||
static const char* value(const M& m)
|
||||
{
|
||||
return m.__getServiceDataType().c_str();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief return MD5Sum<M>::value();
|
||||
*/
|
||||
template<typename M>
|
||||
inline const char* md5sum()
|
||||
{
|
||||
return MD5Sum<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::value();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief return DataType<M>::value();
|
||||
*/
|
||||
template<typename M>
|
||||
inline const char* datatype()
|
||||
{
|
||||
return DataType<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::value();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief return MD5Sum<M>::value(m);
|
||||
*/
|
||||
template<typename M>
|
||||
inline const char* md5sum(const M& m)
|
||||
{
|
||||
return MD5Sum<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::value(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief return DataType<M>::value();
|
||||
*/
|
||||
template<typename M>
|
||||
inline const char* datatype(const M& m)
|
||||
{
|
||||
return DataType<typename boost::remove_reference<typename boost::remove_const<M>::type>::type>::value(m);
|
||||
}
|
||||
|
||||
} // namespace service_traits
|
||||
} // namespace ros
|
||||
|
||||
#endif // ROSCPP_SERVICE_TRAITS_H
|
||||
20
thirdparty/ros/roscpp_core/roscpp_traits/package.xml
vendored
Normal file
20
thirdparty/ros/roscpp_core/roscpp_traits/package.xml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<package>
|
||||
<name>roscpp_traits</name>
|
||||
<version>0.7.2</version>
|
||||
<description>
|
||||
roscpp_traits contains the message traits code as described in
|
||||
<a href="http://www.ros.org/wiki/roscpp/Overview/MessagesTraits">MessagesTraits</a>.
|
||||
|
||||
This package is a component of <a href="http://www.ros.org/wiki/roscpp">roscpp</a>.
|
||||
</description>
|
||||
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
|
||||
<license>BSD</license>
|
||||
|
||||
<url type="website">http://ros.org/wiki/roscpp_traits</url>
|
||||
<author>Josh Faust</author>
|
||||
|
||||
<buildtool_depend>catkin</buildtool_depend>
|
||||
|
||||
<run_depend>cpp_common</run_depend>
|
||||
<run_depend>rostime</run_depend>
|
||||
</package>
|
||||
145
thirdparty/ros/roscpp_core/rostime/CHANGELOG.rst
vendored
Normal file
145
thirdparty/ros/roscpp_core/rostime/CHANGELOG.rst
vendored
Normal file
@@ -0,0 +1,145 @@
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Changelog for package rostime
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
0.7.2 (2020-05-28)
|
||||
------------------
|
||||
* [Windows] Using C++11 std::chrono for ros_walltime & ros_steadytime (`#121 <https://github.com/ros/roscpp_core/issues/121>`_)
|
||||
|
||||
0.7.1 (2020-01-25)
|
||||
------------------
|
||||
* only depend on the boost components needed (`#117 <https://github.com/ros/roscpp_core/issues/117>`_)
|
||||
|
||||
0.7.0 (2020-01-24)
|
||||
------------------
|
||||
* rostime: remove empty destructor of DurationBase (`#104 <https://github.com/ros/roscpp_core/issues/104>`_)
|
||||
* various code cleanup (`#116 <https://github.com/ros/roscpp_core/issues/116>`_)
|
||||
* Bump CMake version to avoid CMP0048 warning (`#115 <https://github.com/ros/roscpp_core/issues/115>`_)
|
||||
|
||||
0.6.13 (2019-10-03)
|
||||
-------------------
|
||||
* use _WIN32 for platform detection (`#110 <https://github.com/ros/roscpp_core/issues/110>`_)
|
||||
* Clarified documentation for time validity (`#109 <https://github.com/ros/roscpp_core/issues/109>`_)
|
||||
* rostime: replace c-style casts with static_casts (`#106 <https://github.com/ros/roscpp_core/issues/106>`_)
|
||||
|
||||
0.6.12 (2019-03-04)
|
||||
-------------------
|
||||
* use std::numeric_limits instead of * _MAX macros for range checking (`#103 <https://github.com/ros/roscpp_core/issues/103>`_)
|
||||
* use std::this_thread::sleep_for instead of WaitableTimer (`#101 <https://github.com/ros/roscpp_core/issues/101>`_)
|
||||
* include windows.h in time.cpp (`#100 <https://github.com/ros/roscpp_core/issues/100>`_)
|
||||
* fix duration bug and add tests. (`#98 <https://github.com/ros/roscpp_core/issues/98>`_)
|
||||
* fix for Duration::fromSec() which had rounding issues (`#93 <https://github.com/ros/roscpp_core/issues/93>`_)
|
||||
* fix bug in HAVE_CXXABI_H compiler check (`#89 <https://github.com/ros/roscpp_core/issues/89>`_)
|
||||
* add ROSTIME_DECL storage-class attribute (`#90 <https://github.com/ros/roscpp_core/issues/90>`_)
|
||||
|
||||
0.6.11 (2018-06-06)
|
||||
-------------------
|
||||
* argument to boost microseconds must be integral for Boost 1.67 and newer compatibility (`#79 <https://github.com/ros/roscpp_core/issues/79>`_)
|
||||
* remove empty destructor of TimeBase (which makes TimeBase, Time and WallTime trivially copyable) (`#82 <https://github.com/ros/roscpp_core/issues/82>`_)
|
||||
|
||||
0.6.10 (2018-05-01)
|
||||
-------------------
|
||||
* fix conversion of Duration on macOS (`#78 <https://github.com/ros/roscpp_core/issues/78>`_)
|
||||
|
||||
0.6.9 (2018-02-02)
|
||||
------------------
|
||||
* expose ros_walltime and ros_steadytime (`#73 <https://github.com/ros/roscpp_core/issues/73>`_)
|
||||
|
||||
0.6.8 (2018-01-26)
|
||||
------------------
|
||||
|
||||
0.6.7 (2017-11-03)
|
||||
------------------
|
||||
|
||||
0.6.6 (2017-10-25)
|
||||
------------------
|
||||
* only use Apple features on Apple (`#68 <https://github.com/ros/roscpp_core/issues/68>`_)
|
||||
* remove exception specification (`#64 <https://github.com/ros/roscpp_core/issues/64>`_)
|
||||
|
||||
0.6.5 (2017-07-27)
|
||||
------------------
|
||||
* add additional checks for valid time values (`#62 <https://github.com/ros/roscpp_core/pull/62>`_)
|
||||
* fix overflow bugs in Time and Duration (`#61 <https://github.com/ros/roscpp_core/pull/61>`_, `#63 <https://github.com/ros/roscpp_core/pull/63>`_)
|
||||
|
||||
0.6.4 (2017-06-06)
|
||||
------------------
|
||||
* add logic to support steady time on macOS (regression of 0.6.3) (`#59 <https://github.com/ros/roscpp_core/pull/59>`_)
|
||||
|
||||
0.6.3 (2017-05-15)
|
||||
------------------
|
||||
* add SteadyTime (`#57 <https://github.com/ros/roscpp_core/issues/57>`_)
|
||||
|
||||
0.6.2 (2017-02-14)
|
||||
------------------
|
||||
|
||||
0.6.1 (2016-09-02)
|
||||
------------------
|
||||
* fix rounding errors leading to invalid stored data in ros::TimeBase (`#48 <https://github.com/ros/roscpp_core/issues/48>`_)
|
||||
|
||||
0.6.0 (2016-03-17)
|
||||
------------------
|
||||
* change Duration:sleep return semantic (`#47 <https://github.com/ros/roscpp_core/pull/47>`_)
|
||||
|
||||
0.5.7 (2016-03-09)
|
||||
------------------
|
||||
* Adjust return value of sleep() function (`#45 <https://github.com/ros/roscpp_core/pull/45>`_)
|
||||
* fix WallRate(Duration) constructor (`#40 <https://github.com/ros/roscpp_core/pull/40>`_)
|
||||
|
||||
0.5.6 (2015-05-20)
|
||||
------------------
|
||||
|
||||
0.5.5 (2014-12-22)
|
||||
------------------
|
||||
* move implementation of Duration(Rate) constructor (`#30 <https://github.com/ros/roscpp_core/issues/30>`_)
|
||||
* fix Duration initialization from seconds for negative values (`#29 <https://github.com/ros/roscpp_core/pull/29>`_)
|
||||
|
||||
0.5.4 (2014-07-23)
|
||||
------------------
|
||||
* fix Rate initialized by Duration (`#26 <https://github.com/ros/roscpp_core/issues/26>`_)
|
||||
|
||||
0.5.3 (2014-06-28)
|
||||
------------------
|
||||
|
||||
0.5.2 (2014-06-27)
|
||||
------------------
|
||||
|
||||
0.5.1 (2014-06-24)
|
||||
------------------
|
||||
|
||||
0.5.0 (2014-02-19)
|
||||
------------------
|
||||
|
||||
0.4.2 (2014-02-11)
|
||||
------------------
|
||||
|
||||
0.4.1 (2014-02-11)
|
||||
------------------
|
||||
|
||||
0.4.0 (2014-01-29)
|
||||
------------------
|
||||
|
||||
0.3.17 (2014-01-07)
|
||||
-------------------
|
||||
* fix boost include dir
|
||||
|
||||
0.3.16 (2013-07-14)
|
||||
-------------------
|
||||
* support for CATKIN_ENABLE_TESTING
|
||||
|
||||
0.3.15 (2013-06-06)
|
||||
-------------------
|
||||
* fix install destination for dll's under Windows
|
||||
|
||||
0.3.14 (2013-03-21)
|
||||
-------------------
|
||||
|
||||
0.3.13 (2013-03-08)
|
||||
-------------------
|
||||
|
||||
0.3.12 (2013-01-13)
|
||||
-------------------
|
||||
* improve string output of negative durations (`#3309 <https://github.com/ros/roscpp_core/issues/3309>`_)
|
||||
|
||||
0.3.11 (2012-12-21)
|
||||
-------------------
|
||||
* first public release for Groovy
|
||||
44
thirdparty/ros/roscpp_core/rostime/CMakeLists.txt
vendored
Normal file
44
thirdparty/ros/roscpp_core/rostime/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
cmake_minimum_required(VERSION 3.0.2)
|
||||
project(rostime)
|
||||
|
||||
find_package(catkin REQUIRED COMPONENTS cpp_common)
|
||||
find_package(Boost REQUIRED COMPONENTS date_time system thread)
|
||||
catkin_package(
|
||||
INCLUDE_DIRS include
|
||||
LIBRARIES ${PROJECT_NAME}
|
||||
CATKIN_DEPENDS cpp_common
|
||||
DEPENDS Boost
|
||||
)
|
||||
|
||||
include_directories(include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
|
||||
|
||||
add_library(rostime
|
||||
src/duration.cpp
|
||||
src/rate.cpp
|
||||
src/time.cpp)
|
||||
|
||||
target_link_libraries(rostime ${Boost_LIBRARIES})
|
||||
if(NOT APPLE)
|
||||
target_link_libraries(rostime ${RT_LIBRARY})
|
||||
endif()
|
||||
|
||||
install(TARGETS rostime
|
||||
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION})
|
||||
|
||||
install(DIRECTORY include/
|
||||
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
|
||||
if(CATKIN_ENABLE_TESTING)
|
||||
catkin_add_gtest(${PROJECT_NAME}-test_duration test/duration.cpp)
|
||||
if(TARGET ${PROJECT_NAME}-test_duration)
|
||||
target_link_libraries(${PROJECT_NAME}-test_duration ${catkin_LIBRARIES} rostime)
|
||||
endif()
|
||||
catkin_add_gtest(${PROJECT_NAME}-test_time test/time.cpp)
|
||||
if(TARGET ${PROJECT_NAME}-test_time)
|
||||
set_property(TARGET ${PROJECT_NAME}-test_time APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++11")
|
||||
target_link_libraries(${PROJECT_NAME}-test_time ${catkin_LIBRARIES} rostime)
|
||||
endif()
|
||||
endif()
|
||||
160
thirdparty/ros/roscpp_core/rostime/include/ros/duration.h
vendored
Normal file
160
thirdparty/ros/roscpp_core/rostime/include/ros/duration.h
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
/*********************************************************************
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* Copyright (c) 2008, Willow Garage, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*********************************************************************/
|
||||
|
||||
#ifndef ROS_DURATION_H
|
||||
#define ROS_DURATION_H
|
||||
|
||||
/*********************************************************************
|
||||
** Pragmas
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Rostime has some magic interface that doesn't directly include
|
||||
// its implementation, this just disbales those warnings.
|
||||
#pragma warning(disable: 4244)
|
||||
#pragma warning(disable: 4661)
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <stdexcept>
|
||||
#include <climits>
|
||||
#include <stdint.h>
|
||||
#include "rostime_decl.h"
|
||||
|
||||
namespace boost {
|
||||
namespace posix_time {
|
||||
class time_duration;
|
||||
}
|
||||
}
|
||||
|
||||
namespace ros
|
||||
{
|
||||
ROSTIME_DECL void normalizeSecNSecSigned(int64_t& sec, int64_t& nsec);
|
||||
ROSTIME_DECL void normalizeSecNSecSigned(int32_t& sec, int32_t& nsec);
|
||||
|
||||
/**
|
||||
* \brief Base class for Duration implementations. Provides storage, common functions and operator overloads.
|
||||
* This should not need to be used directly.
|
||||
*/
|
||||
template <class T>
|
||||
class DurationBase
|
||||
{
|
||||
public:
|
||||
int32_t sec, nsec;
|
||||
DurationBase() : sec(0), nsec(0) { }
|
||||
DurationBase(int32_t _sec, int32_t _nsec);
|
||||
explicit DurationBase(double t){fromSec(t);};
|
||||
T operator+(const T &rhs) const;
|
||||
T operator-(const T &rhs) const;
|
||||
T operator-() const;
|
||||
T operator*(double scale) const;
|
||||
T& operator+=(const T &rhs);
|
||||
T& operator-=(const T &rhs);
|
||||
T& operator*=(double scale);
|
||||
bool operator==(const T &rhs) const;
|
||||
inline bool operator!=(const T &rhs) const { return !(*static_cast<const T*>(this) == rhs); }
|
||||
bool operator>(const T &rhs) const;
|
||||
bool operator<(const T &rhs) const;
|
||||
bool operator>=(const T &rhs) const;
|
||||
bool operator<=(const T &rhs) const;
|
||||
double toSec() const { return static_cast<double>(sec) + 1e-9*static_cast<double>(nsec); };
|
||||
int64_t toNSec() const {return static_cast<int64_t>(sec)*1000000000ll + static_cast<int64_t>(nsec); };
|
||||
T& fromSec(double t);
|
||||
T& fromNSec(int64_t t);
|
||||
bool isZero() const;
|
||||
boost::posix_time::time_duration toBoost() const;
|
||||
};
|
||||
|
||||
class Rate;
|
||||
|
||||
/**
|
||||
* \brief Duration representation for use with the Time class.
|
||||
*
|
||||
* ros::DurationBase provides most of its functionality.
|
||||
*/
|
||||
class ROSTIME_DECL Duration : public DurationBase<Duration>
|
||||
{
|
||||
public:
|
||||
Duration()
|
||||
: DurationBase<Duration>()
|
||||
{ }
|
||||
|
||||
Duration(int32_t _sec, int32_t _nsec)
|
||||
: DurationBase<Duration>(_sec, _nsec)
|
||||
{}
|
||||
|
||||
explicit Duration(double t) { fromSec(t); }
|
||||
explicit Duration(const Rate&);
|
||||
/**
|
||||
* \brief sleep for the amount of time specified by this Duration. If a signal interrupts the sleep, resleeps for the time remaining.
|
||||
* @return True if the desired sleep duration was met, false otherwise.
|
||||
*/
|
||||
bool sleep() const;
|
||||
};
|
||||
|
||||
extern ROSTIME_DECL const Duration DURATION_MAX;
|
||||
extern ROSTIME_DECL const Duration DURATION_MIN;
|
||||
|
||||
/**
|
||||
* \brief Duration representation for use with the WallTime class.
|
||||
*
|
||||
* ros::DurationBase provides most of its functionality.
|
||||
*/
|
||||
class ROSTIME_DECL WallDuration : public DurationBase<WallDuration>
|
||||
{
|
||||
public:
|
||||
WallDuration()
|
||||
: DurationBase<WallDuration>()
|
||||
{ }
|
||||
|
||||
WallDuration(int32_t _sec, int32_t _nsec)
|
||||
: DurationBase<WallDuration>(_sec, _nsec)
|
||||
{}
|
||||
|
||||
explicit WallDuration(double t) { fromSec(t); }
|
||||
explicit WallDuration(const Rate&);
|
||||
/**
|
||||
* \brief sleep for the amount of time specified by this Duration. If a signal interrupts the sleep, resleeps for the time remaining.
|
||||
* @return True if the desired sleep duration was met, false otherwise.
|
||||
*/
|
||||
bool sleep() const;
|
||||
};
|
||||
|
||||
ROSTIME_DECL std::ostream &operator <<(std::ostream &os, const Duration &rhs);
|
||||
ROSTIME_DECL std::ostream &operator <<(std::ostream &os, const WallDuration &rhs);
|
||||
|
||||
}
|
||||
|
||||
#endif // ROS_DURATION_H
|
||||
193
thirdparty/ros/roscpp_core/rostime/include/ros/impl/duration.h
vendored
Normal file
193
thirdparty/ros/roscpp_core/rostime/include/ros/impl/duration.h
vendored
Normal file
@@ -0,0 +1,193 @@
|
||||
/*********************************************************************
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* Copyright (c) 2010, Willow Garage, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*********************************************************************/
|
||||
#ifndef ROSTIME_IMPL_DURATION_H_INCLUDED
|
||||
#define ROSTIME_IMPL_DURATION_H_INCLUDED
|
||||
|
||||
#include <ros/duration.h>
|
||||
#include <ros/rate.h>
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
#include <boost/math/special_functions/round.hpp>
|
||||
|
||||
namespace ros {
|
||||
//
|
||||
// DurationBase template member function implementation
|
||||
//
|
||||
template<class T>
|
||||
DurationBase<T>::DurationBase(int32_t _sec, int32_t _nsec)
|
||||
: sec(_sec), nsec(_nsec)
|
||||
{
|
||||
normalizeSecNSecSigned(sec, nsec);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T& DurationBase<T>::fromSec(double d)
|
||||
{
|
||||
int64_t sec64 = static_cast<int64_t>(floor(d));
|
||||
if (sec64 < std::numeric_limits<int32_t>::min() || sec64 > std::numeric_limits<int32_t>::max())
|
||||
throw std::runtime_error("Duration is out of dual 32-bit range");
|
||||
sec = static_cast<int32_t>(sec64);
|
||||
nsec = static_cast<int32_t>(boost::math::round((d - sec) * 1e9));
|
||||
int32_t rollover = nsec / 1000000000ul;
|
||||
sec += rollover;
|
||||
nsec %= 1000000000ul;
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T& DurationBase<T>::fromNSec(int64_t t)
|
||||
{
|
||||
int64_t sec64 = t / 1000000000LL;
|
||||
if (sec64 < std::numeric_limits<int32_t>::min() || sec64 > std::numeric_limits<int32_t>::max())
|
||||
throw std::runtime_error("Duration is out of dual 32-bit range");
|
||||
sec = static_cast<int32_t>(sec64);
|
||||
nsec = static_cast<int32_t>(t % 1000000000LL);
|
||||
|
||||
normalizeSecNSecSigned(sec, nsec);
|
||||
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T DurationBase<T>::operator+(const T &rhs) const
|
||||
{
|
||||
T t;
|
||||
return t.fromNSec(toNSec() + rhs.toNSec());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T DurationBase<T>::operator*(double scale) const
|
||||
{
|
||||
return T(toSec() * scale);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T DurationBase<T>::operator-(const T &rhs) const
|
||||
{
|
||||
T t;
|
||||
return t.fromNSec(toNSec() - rhs.toNSec());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T DurationBase<T>::operator-() const
|
||||
{
|
||||
T t;
|
||||
return t.fromNSec(-toNSec());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T& DurationBase<T>::operator+=(const T &rhs)
|
||||
{
|
||||
*this = *this + rhs;
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T& DurationBase<T>::operator-=(const T &rhs)
|
||||
{
|
||||
*this += (-rhs);
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T& DurationBase<T>::operator*=(double scale)
|
||||
{
|
||||
fromSec(toSec() * scale);
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool DurationBase<T>::operator<(const T &rhs) const
|
||||
{
|
||||
if (sec < rhs.sec)
|
||||
return true;
|
||||
else if (sec == rhs.sec && nsec < rhs.nsec)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool DurationBase<T>::operator>(const T &rhs) const
|
||||
{
|
||||
if (sec > rhs.sec)
|
||||
return true;
|
||||
else if (sec == rhs.sec && nsec > rhs.nsec)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool DurationBase<T>::operator<=(const T &rhs) const
|
||||
{
|
||||
if (sec < rhs.sec)
|
||||
return true;
|
||||
else if (sec == rhs.sec && nsec <= rhs.nsec)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool DurationBase<T>::operator>=(const T &rhs) const
|
||||
{
|
||||
if (sec > rhs.sec)
|
||||
return true;
|
||||
else if (sec == rhs.sec && nsec >= rhs.nsec)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool DurationBase<T>::operator==(const T &rhs) const
|
||||
{
|
||||
return sec == rhs.sec && nsec == rhs.nsec;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool DurationBase<T>::isZero() const
|
||||
{
|
||||
return sec == 0 && nsec == 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
boost::posix_time::time_duration
|
||||
DurationBase<T>::toBoost() const
|
||||
{
|
||||
namespace bt = boost::posix_time;
|
||||
#if defined(BOOST_DATE_TIME_HAS_NANOSECONDS)
|
||||
return bt::seconds(sec) + bt::nanoseconds(nsec);
|
||||
#else
|
||||
return bt::seconds(sec) + bt::microseconds(nsec/1000);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
188
thirdparty/ros/roscpp_core/rostime/include/ros/impl/time.h
vendored
Normal file
188
thirdparty/ros/roscpp_core/rostime/include/ros/impl/time.h
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
/*********************************************************************
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* Copyright (c) 2008, Willow Garage, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*********************************************************************/
|
||||
|
||||
#ifndef ROS_TIME_IMPL_H_INCLUDED
|
||||
#define ROS_TIME_IMPL_H_INCLUDED
|
||||
|
||||
/*********************************************************************
|
||||
** Headers
|
||||
*********************************************************************/
|
||||
|
||||
#include <ros/platform.h>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <ros/exception.h>
|
||||
#include <ros/time.h>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
/*********************************************************************
|
||||
** Cross Platform Headers
|
||||
*********************************************************************/
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <sys/timeb.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
namespace ros
|
||||
{
|
||||
|
||||
template<class T, class D>
|
||||
T& TimeBase<T, D>::fromNSec(uint64_t t)
|
||||
{
|
||||
uint64_t sec64 = 0;
|
||||
uint64_t nsec64 = t;
|
||||
|
||||
normalizeSecNSec(sec64, nsec64);
|
||||
|
||||
sec = static_cast<uint32_t>(sec64);
|
||||
nsec = static_cast<uint32_t>(nsec64);
|
||||
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
template<class T, class D>
|
||||
T& TimeBase<T, D>::fromSec(double t) {
|
||||
int64_t sec64 = static_cast<int64_t>(floor(t));
|
||||
if (sec64 < 0 || sec64 > std::numeric_limits<uint32_t>::max())
|
||||
throw std::runtime_error("Time is out of dual 32-bit range");
|
||||
sec = static_cast<uint32_t>(sec64);
|
||||
nsec = static_cast<uint32_t>(boost::math::round((t-sec) * 1e9));
|
||||
// avoid rounding errors
|
||||
sec += (nsec / 1000000000ul);
|
||||
nsec %= 1000000000ul;
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
template<class T, class D>
|
||||
D TimeBase<T, D>::operator-(const T &rhs) const
|
||||
{
|
||||
D d;
|
||||
return d.fromNSec(toNSec() - rhs.toNSec());
|
||||
}
|
||||
|
||||
template<class T, class D>
|
||||
T TimeBase<T, D>::operator-(const D &rhs) const
|
||||
{
|
||||
return *static_cast<const T*>(this) + ( -rhs);
|
||||
}
|
||||
|
||||
template<class T, class D>
|
||||
T TimeBase<T, D>::operator+(const D &rhs) const
|
||||
{
|
||||
int64_t sec_sum = static_cast<uint64_t>(sec) + static_cast<uint64_t>(rhs.sec);
|
||||
int64_t nsec_sum = static_cast<uint64_t>(nsec) + static_cast<uint64_t>(rhs.nsec);
|
||||
|
||||
// Throws an exception if we go out of 32-bit range
|
||||
normalizeSecNSecUnsigned(sec_sum, nsec_sum);
|
||||
|
||||
// now, it's safe to downcast back to uint32 bits
|
||||
return T(static_cast<uint32_t>(sec_sum), static_cast<uint32_t>(nsec_sum));
|
||||
}
|
||||
|
||||
template<class T, class D>
|
||||
T& TimeBase<T, D>::operator+=(const D &rhs)
|
||||
{
|
||||
*this = *this + rhs;
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
template<class T, class D>
|
||||
T& TimeBase<T, D>::operator-=(const D &rhs)
|
||||
{
|
||||
*this += (-rhs);
|
||||
return *static_cast<T*>(this);
|
||||
}
|
||||
|
||||
template<class T, class D>
|
||||
bool TimeBase<T, D>::operator==(const T &rhs) const
|
||||
{
|
||||
return sec == rhs.sec && nsec == rhs.nsec;
|
||||
}
|
||||
|
||||
template<class T, class D>
|
||||
bool TimeBase<T, D>::operator<(const T &rhs) const
|
||||
{
|
||||
if (sec < rhs.sec)
|
||||
return true;
|
||||
else if (sec == rhs.sec && nsec < rhs.nsec)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T, class D>
|
||||
bool TimeBase<T, D>::operator>(const T &rhs) const
|
||||
{
|
||||
if (sec > rhs.sec)
|
||||
return true;
|
||||
else if (sec == rhs.sec && nsec > rhs.nsec)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T, class D>
|
||||
bool TimeBase<T, D>::operator<=(const T &rhs) const
|
||||
{
|
||||
if (sec < rhs.sec)
|
||||
return true;
|
||||
else if (sec == rhs.sec && nsec <= rhs.nsec)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T, class D>
|
||||
bool TimeBase<T, D>::operator>=(const T &rhs) const
|
||||
{
|
||||
if (sec > rhs.sec)
|
||||
return true;
|
||||
else if (sec == rhs.sec && nsec >= rhs.nsec)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class T, class D>
|
||||
boost::posix_time::ptime
|
||||
TimeBase<T, D>::toBoost() const
|
||||
{
|
||||
namespace pt = boost::posix_time;
|
||||
#if defined(BOOST_DATE_TIME_HAS_NANOSECONDS)
|
||||
return pt::from_time_t(sec) + pt::nanoseconds(nsec);
|
||||
#else
|
||||
return pt::from_time_t(sec) + pt::microseconds(nsec/1000);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ROS_IMPL_TIME_H_INCLUDED
|
||||
131
thirdparty/ros/roscpp_core/rostime/include/ros/rate.h
vendored
Normal file
131
thirdparty/ros/roscpp_core/rostime/include/ros/rate.h
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
/*********************************************************************
|
||||
*
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* Copyright (c) 2009, Willow Garage, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Willow Garage nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Author: Eitan Marder-Eppstein
|
||||
*********************************************************************/
|
||||
#ifndef ROSLIB_RATE_H
|
||||
#define ROSLIB_RATE_H
|
||||
|
||||
#include "ros/time.h"
|
||||
#include "rostime_decl.h"
|
||||
|
||||
namespace ros
|
||||
{
|
||||
class Duration;
|
||||
|
||||
/**
|
||||
* @class Rate
|
||||
* @brief Class to help run loops at a desired frequency
|
||||
*/
|
||||
class ROSTIME_DECL Rate
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor, creates a Rate
|
||||
* @param frequency The desired rate to run at in Hz
|
||||
*/
|
||||
Rate(double frequency);
|
||||
explicit Rate(const Duration&);
|
||||
|
||||
/**
|
||||
* @brief Sleeps for any leftover time in a cycle. Calculated from the last time sleep, reset, or the constructor was called.
|
||||
* @return True if the desired rate was met for the cycle, false otherwise.
|
||||
*/
|
||||
bool sleep();
|
||||
|
||||
/**
|
||||
* @brief Sets the start time for the rate to now
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* @brief Get the actual run time of a cycle from start to sleep
|
||||
* @return The runtime of the cycle
|
||||
*/
|
||||
Duration cycleTime() const;
|
||||
|
||||
/**
|
||||
* @brief Get the expected cycle time -- one over the frequency passed in to the constructor
|
||||
*/
|
||||
Duration expectedCycleTime() const { return expected_cycle_time_; }
|
||||
|
||||
private:
|
||||
Time start_;
|
||||
Duration expected_cycle_time_, actual_cycle_time_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class WallRate
|
||||
* @brief Class to help run loops at a desired frequency. This version always uses wall-clock time.
|
||||
*/
|
||||
class ROSTIME_DECL WallRate
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor, creates a Rate
|
||||
* @param frequency The desired rate to run at in Hz
|
||||
*/
|
||||
WallRate(double frequency);
|
||||
explicit WallRate(const Duration&);
|
||||
|
||||
/**
|
||||
* @brief Sleeps for any leftover time in a cycle. Calculated from the last time sleep, reset, or the constructor was called.
|
||||
* @return Passes through the return value from WallDuration::sleep() if it slept, false otherwise.
|
||||
*/
|
||||
bool sleep();
|
||||
|
||||
/**
|
||||
* @brief Sets the start time for the rate to now
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* @brief Get the actual run time of a cycle from start to sleep
|
||||
* @return The runtime of the cycle
|
||||
*/
|
||||
WallDuration cycleTime() const;
|
||||
|
||||
/**
|
||||
* @brief Get the expected cycle time -- one over the frequency passed in to the constructor
|
||||
*/
|
||||
WallDuration expectedCycleTime() const { return expected_cycle_time_; }
|
||||
|
||||
private:
|
||||
WallTime start_;
|
||||
WallDuration expected_cycle_time_, actual_cycle_time_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
55
thirdparty/ros/roscpp_core/rostime/include/ros/rostime_decl.h
vendored
Normal file
55
thirdparty/ros/roscpp_core/rostime/include/ros/rostime_decl.h
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/*********************************************************************
|
||||
*
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* Copyright (c) 2009, Willow Garage, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Willow Garage nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*********************************************************************/
|
||||
/*
|
||||
* Cross platform macros.
|
||||
*
|
||||
*/
|
||||
#ifndef ROSTIME_DECL_HPP_INCLUDED
|
||||
#define ROSTIME_DECL_HPP_INCLUDED
|
||||
|
||||
#include <ros/macros.h>
|
||||
|
||||
#ifdef ROS_BUILD_SHARED_LIBS // ros is being built around shared libraries
|
||||
#ifdef rostime_EXPORTS // we are building a shared lib/dll
|
||||
#define ROSTIME_DECL ROS_HELPER_EXPORT
|
||||
#else // we are using shared lib/dll
|
||||
#define ROSTIME_DECL ROS_HELPER_IMPORT
|
||||
#endif
|
||||
#else // ros is being built around static libraries
|
||||
#define ROSTIME_DECL
|
||||
#endif
|
||||
|
||||
#endif /* ROSTIME_DECL_HPP_INCLUDED */
|
||||
292
thirdparty/ros/roscpp_core/rostime/include/ros/time.h
vendored
Normal file
292
thirdparty/ros/roscpp_core/rostime/include/ros/time.h
vendored
Normal file
@@ -0,0 +1,292 @@
|
||||
/*********************************************************************
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* Copyright (c) 2010, Willow Garage, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*********************************************************************/
|
||||
|
||||
#ifndef ROS_TIME_H_INCLUDED
|
||||
#define ROS_TIME_H_INCLUDED
|
||||
|
||||
/*********************************************************************
|
||||
** Pragmas
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Rostime has some magic interface that doesn't directly include
|
||||
// its implementation, this just disables those warnings.
|
||||
#pragma warning(disable: 4244)
|
||||
#pragma warning(disable: 4661)
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
** Headers
|
||||
*********************************************************************/
|
||||
|
||||
#include <ros/platform.h>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <ros/exception.h>
|
||||
#include "duration.h"
|
||||
#include <boost/math/special_functions/round.hpp>
|
||||
#include "rostime_decl.h"
|
||||
|
||||
/*********************************************************************
|
||||
** Cross Platform Headers
|
||||
*********************************************************************/
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <sys/timeb.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace posix_time {
|
||||
class ptime;
|
||||
class time_duration;
|
||||
}
|
||||
}
|
||||
|
||||
namespace ros
|
||||
{
|
||||
|
||||
/*********************************************************************
|
||||
** Exceptions
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* @brief Thrown if the ros subsystem hasn't been initialised before use.
|
||||
*/
|
||||
class ROSTIME_DECL TimeNotInitializedException : public Exception
|
||||
{
|
||||
public:
|
||||
TimeNotInitializedException()
|
||||
: Exception("Cannot use ros::Time::now() before the first NodeHandle has been created or ros::start() has been called. "
|
||||
"If this is a standalone app or test that just uses ros::Time and does not communicate over ROS, you may also call ros::Time::init()")
|
||||
{}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Thrown if windows high perf. timestamping is unavailable.
|
||||
*
|
||||
* @sa getWallTime
|
||||
*/
|
||||
class ROSTIME_DECL NoHighPerformanceTimersException : public Exception
|
||||
{
|
||||
public:
|
||||
NoHighPerformanceTimersException()
|
||||
: Exception("This windows platform does not "
|
||||
"support the high-performance timing api.")
|
||||
{}
|
||||
};
|
||||
|
||||
/*********************************************************************
|
||||
** Functions
|
||||
*********************************************************************/
|
||||
|
||||
ROSTIME_DECL void normalizeSecNSec(uint64_t& sec, uint64_t& nsec);
|
||||
ROSTIME_DECL void normalizeSecNSec(uint32_t& sec, uint32_t& nsec);
|
||||
ROSTIME_DECL void normalizeSecNSecUnsigned(int64_t& sec, int64_t& nsec);
|
||||
ROSTIME_DECL void ros_walltime(uint32_t& sec, uint32_t& nsec);
|
||||
ROSTIME_DECL void ros_steadytime(uint32_t& sec, uint32_t& nsec);
|
||||
|
||||
/*********************************************************************
|
||||
** Time Classes
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* \brief Base class for Time implementations. Provides storage, common functions and operator overloads.
|
||||
* This should not need to be used directly.
|
||||
*/
|
||||
template<class T, class D>
|
||||
class TimeBase
|
||||
{
|
||||
public:
|
||||
uint32_t sec, nsec;
|
||||
|
||||
TimeBase() : sec(0), nsec(0) { }
|
||||
TimeBase(uint32_t _sec, uint32_t _nsec) : sec(_sec), nsec(_nsec)
|
||||
{
|
||||
normalizeSecNSec(sec, nsec);
|
||||
}
|
||||
explicit TimeBase(double t) { fromSec(t); }
|
||||
D operator-(const T &rhs) const;
|
||||
T operator+(const D &rhs) const;
|
||||
T operator-(const D &rhs) const;
|
||||
T& operator+=(const D &rhs);
|
||||
T& operator-=(const D &rhs);
|
||||
bool operator==(const T &rhs) const;
|
||||
inline bool operator!=(const T &rhs) const { return !(*static_cast<const T*>(this) == rhs); }
|
||||
bool operator>(const T &rhs) const;
|
||||
bool operator<(const T &rhs) const;
|
||||
bool operator>=(const T &rhs) const;
|
||||
bool operator<=(const T &rhs) const;
|
||||
|
||||
double toSec() const { return static_cast<double>(sec) + 1e-9*static_cast<double>(nsec); };
|
||||
T& fromSec(double t);
|
||||
|
||||
uint64_t toNSec() const {return static_cast<uint64_t>(sec)*1000000000ull + static_cast<uint64_t>(nsec); }
|
||||
T& fromNSec(uint64_t t);
|
||||
|
||||
inline bool isZero() const { return sec == 0 && nsec == 0; }
|
||||
inline bool is_zero() const { return isZero(); }
|
||||
boost::posix_time::ptime toBoost() const;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Time representation. May either represent wall clock time or ROS clock time.
|
||||
*
|
||||
* ros::TimeBase provides most of its functionality.
|
||||
*/
|
||||
class ROSTIME_DECL Time : public TimeBase<Time, Duration>
|
||||
{
|
||||
public:
|
||||
Time()
|
||||
: TimeBase<Time, Duration>()
|
||||
{}
|
||||
|
||||
Time(uint32_t _sec, uint32_t _nsec)
|
||||
: TimeBase<Time, Duration>(_sec, _nsec)
|
||||
{}
|
||||
|
||||
explicit Time(double t) { fromSec(t); }
|
||||
|
||||
/**
|
||||
* \brief Retrieve the current time. If ROS clock time is in use, this returns the time according to the
|
||||
* ROS clock. Otherwise returns the current wall clock time.
|
||||
*/
|
||||
static Time now();
|
||||
/**
|
||||
* \brief Sleep until a specific time has been reached.
|
||||
* @return True if the desired sleep time was met, false otherwise.
|
||||
*/
|
||||
static bool sleepUntil(const Time& end);
|
||||
|
||||
static void init();
|
||||
static void shutdown();
|
||||
static void setNow(const Time& new_now);
|
||||
static bool useSystemTime();
|
||||
static bool isSimTime();
|
||||
static bool isSystemTime();
|
||||
|
||||
/**
|
||||
* \brief Returns whether or not the current time source is valid. Simulation time is valid if it is non-zero.
|
||||
*/
|
||||
static bool isValid();
|
||||
/**
|
||||
* \brief Wait for time source to become valid
|
||||
*/
|
||||
static bool waitForValid();
|
||||
/**
|
||||
* \brief Wait for time source to become valid, with timeout
|
||||
*/
|
||||
static bool waitForValid(const ros::WallDuration& timeout);
|
||||
|
||||
static Time fromBoost(const boost::posix_time::ptime& t);
|
||||
static Time fromBoost(const boost::posix_time::time_duration& d);
|
||||
};
|
||||
|
||||
extern ROSTIME_DECL const Time TIME_MAX;
|
||||
extern ROSTIME_DECL const Time TIME_MIN;
|
||||
|
||||
/**
|
||||
* \brief Time representation. Always wall-clock time.
|
||||
*
|
||||
* ros::TimeBase provides most of its functionality.
|
||||
*/
|
||||
class ROSTIME_DECL WallTime : public TimeBase<WallTime, WallDuration>
|
||||
{
|
||||
public:
|
||||
WallTime()
|
||||
: TimeBase<WallTime, WallDuration>()
|
||||
{}
|
||||
|
||||
WallTime(uint32_t _sec, uint32_t _nsec)
|
||||
: TimeBase<WallTime, WallDuration>(_sec, _nsec)
|
||||
{}
|
||||
|
||||
explicit WallTime(double t) { fromSec(t); }
|
||||
|
||||
/**
|
||||
* \brief Returns the current wall clock time.
|
||||
*/
|
||||
static WallTime now();
|
||||
|
||||
/**
|
||||
* \brief Sleep until a specific time has been reached.
|
||||
* @return True if the desired sleep time was met, false otherwise.
|
||||
*/
|
||||
static bool sleepUntil(const WallTime& end);
|
||||
|
||||
static bool isSystemTime() { return true; }
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Time representation. Always steady-clock time.
|
||||
*
|
||||
* Not affected by ROS time.
|
||||
*
|
||||
* ros::TimeBase provides most of its functionality.
|
||||
*/
|
||||
class ROSTIME_DECL SteadyTime : public TimeBase<SteadyTime, WallDuration>
|
||||
{
|
||||
public:
|
||||
SteadyTime()
|
||||
: TimeBase<SteadyTime, WallDuration>()
|
||||
{}
|
||||
|
||||
SteadyTime(uint32_t _sec, uint32_t _nsec)
|
||||
: TimeBase<SteadyTime, WallDuration>(_sec, _nsec)
|
||||
{}
|
||||
|
||||
explicit SteadyTime(double t) { fromSec(t); }
|
||||
|
||||
/**
|
||||
* \brief Returns the current steady (monotonic) clock time.
|
||||
*/
|
||||
static SteadyTime now();
|
||||
|
||||
/**
|
||||
* \brief Sleep until a specific time has been reached.
|
||||
* @return True if the desired sleep time was met, false otherwise.
|
||||
*/
|
||||
static bool sleepUntil(const SteadyTime& end);
|
||||
|
||||
static bool isSystemTime() { return true; }
|
||||
};
|
||||
|
||||
ROSTIME_DECL std::ostream &operator <<(std::ostream &os, const Time &rhs);
|
||||
ROSTIME_DECL std::ostream &operator <<(std::ostream &os, const WallTime &rhs);
|
||||
ROSTIME_DECL std::ostream &operator <<(std::ostream &os, const SteadyTime &rhs);
|
||||
}
|
||||
|
||||
#endif // ROS_TIME_H
|
||||
24
thirdparty/ros/roscpp_core/rostime/package.xml
vendored
Normal file
24
thirdparty/ros/roscpp_core/rostime/package.xml
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<package>
|
||||
<name>rostime</name>
|
||||
<version>0.7.2</version>
|
||||
<description>
|
||||
Time and Duration implementations for C++ libraries, including roscpp.
|
||||
</description>
|
||||
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer>
|
||||
<license>BSD</license>
|
||||
|
||||
<url>http://ros.org/wiki/rostime</url>
|
||||
<author>Josh Faust</author>
|
||||
|
||||
<buildtool_depend version_gte="0.5.68">catkin</buildtool_depend>
|
||||
|
||||
<build_depend>libboost-date-time-dev</build_depend>
|
||||
<build_depend>libboost-system-dev</build_depend>
|
||||
<build_depend>libboost-thread-dev</build_depend>
|
||||
<build_depend>cpp_common</build_depend>
|
||||
|
||||
<run_depend>libboost-date-time-dev</run_depend>
|
||||
<run_depend>libboost-system-dev</run_depend>
|
||||
<run_depend>libboost-thread-dev</run_depend>
|
||||
<run_depend>cpp_common</run_depend>
|
||||
</package>
|
||||
77
thirdparty/ros/roscpp_core/rostime/src/duration.cpp
vendored
Normal file
77
thirdparty/ros/roscpp_core/rostime/src/duration.cpp
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
/*********************************************************************
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* Copyright (c) 2010, Willow Garage, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*********************************************************************/
|
||||
#include <ros/duration.h>
|
||||
#include <ros/impl/duration.h>
|
||||
|
||||
namespace ros {
|
||||
|
||||
Duration::Duration(const Rate& rate)
|
||||
: DurationBase<Duration>(rate.expectedCycleTime().sec, rate.expectedCycleTime().nsec)
|
||||
{ }
|
||||
|
||||
WallDuration::WallDuration(const Rate& rate)
|
||||
: DurationBase<WallDuration>(rate.expectedCycleTime().sec, rate.expectedCycleTime().nsec)
|
||||
{ }
|
||||
|
||||
void normalizeSecNSecSigned(int64_t& sec, int64_t& nsec)
|
||||
{
|
||||
int64_t nsec_part = nsec % 1000000000L;
|
||||
int64_t sec_part = sec + nsec / 1000000000L;
|
||||
if (nsec_part < 0)
|
||||
{
|
||||
nsec_part += 1000000000L;
|
||||
--sec_part;
|
||||
}
|
||||
|
||||
if (sec_part < std::numeric_limits<int32_t>::min() || sec_part > std::numeric_limits<int32_t>::max())
|
||||
throw std::runtime_error("Duration is out of dual 32-bit range");
|
||||
|
||||
sec = sec_part;
|
||||
nsec = nsec_part;
|
||||
}
|
||||
|
||||
void normalizeSecNSecSigned(int32_t& sec, int32_t& nsec)
|
||||
{
|
||||
int64_t sec64 = sec;
|
||||
int64_t nsec64 = nsec;
|
||||
|
||||
normalizeSecNSecSigned(sec64, nsec64);
|
||||
|
||||
sec = (int32_t)sec64;
|
||||
nsec = (int32_t)nsec64;
|
||||
}
|
||||
|
||||
template class DurationBase<Duration>;
|
||||
template class DurationBase<WallDuration>;
|
||||
}
|
||||
159
thirdparty/ros/roscpp_core/rostime/src/rate.cpp
vendored
Normal file
159
thirdparty/ros/roscpp_core/rostime/src/rate.cpp
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
/*********************************************************************
|
||||
*
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* Copyright (c) 2009, Willow Garage, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of the Willow Garage nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Author: Eitan Marder-Eppstein
|
||||
*********************************************************************/
|
||||
#include <ros/rate.h>
|
||||
|
||||
namespace ros
|
||||
{
|
||||
|
||||
Rate::Rate(double frequency)
|
||||
: start_(Time::now())
|
||||
, expected_cycle_time_(1.0 / frequency)
|
||||
, actual_cycle_time_(0.0)
|
||||
{ }
|
||||
|
||||
Rate::Rate(const Duration& d)
|
||||
: start_(Time::now())
|
||||
, expected_cycle_time_(d.sec, d.nsec)
|
||||
, actual_cycle_time_(0.0)
|
||||
{ }
|
||||
|
||||
bool Rate::sleep()
|
||||
{
|
||||
Time expected_end = start_ + expected_cycle_time_;
|
||||
|
||||
Time actual_end = Time::now();
|
||||
|
||||
// detect backward jumps in time
|
||||
if (actual_end < start_)
|
||||
{
|
||||
expected_end = actual_end + expected_cycle_time_;
|
||||
}
|
||||
|
||||
//calculate the time we'll sleep for
|
||||
Duration sleep_time = expected_end - actual_end;
|
||||
|
||||
//set the actual amount of time the loop took in case the user wants to know
|
||||
actual_cycle_time_ = actual_end - start_;
|
||||
|
||||
//make sure to reset our start time
|
||||
start_ = expected_end;
|
||||
|
||||
//if we've taken too much time we won't sleep
|
||||
if(sleep_time <= Duration(0.0))
|
||||
{
|
||||
// if we've jumped forward in time, or the loop has taken more than a full extra
|
||||
// cycle, reset our cycle
|
||||
if (actual_end > expected_end + expected_cycle_time_)
|
||||
{
|
||||
start_ = actual_end;
|
||||
}
|
||||
// return false to show that the desired rate was not met
|
||||
return false;
|
||||
}
|
||||
|
||||
return sleep_time.sleep();
|
||||
}
|
||||
|
||||
void Rate::reset()
|
||||
{
|
||||
start_ = Time::now();
|
||||
}
|
||||
|
||||
Duration Rate::cycleTime() const
|
||||
{
|
||||
return actual_cycle_time_;
|
||||
}
|
||||
|
||||
WallRate::WallRate(double frequency)
|
||||
: start_(WallTime::now())
|
||||
, expected_cycle_time_(1.0 / frequency)
|
||||
, actual_cycle_time_(0.0)
|
||||
{}
|
||||
|
||||
WallRate::WallRate(const Duration& d)
|
||||
: start_(WallTime::now())
|
||||
, expected_cycle_time_(d.sec, d.nsec)
|
||||
, actual_cycle_time_(0.0)
|
||||
{}
|
||||
|
||||
bool WallRate::sleep()
|
||||
{
|
||||
WallTime expected_end = start_ + expected_cycle_time_;
|
||||
|
||||
WallTime actual_end = WallTime::now();
|
||||
|
||||
// detect backward jumps in time
|
||||
if (actual_end < start_)
|
||||
{
|
||||
expected_end = actual_end + expected_cycle_time_;
|
||||
}
|
||||
|
||||
//calculate the time we'll sleep for
|
||||
WallDuration sleep_time = expected_end - actual_end;
|
||||
|
||||
//set the actual amount of time the loop took in case the user wants to know
|
||||
actual_cycle_time_ = actual_end - start_;
|
||||
|
||||
//make sure to reset our start time
|
||||
start_ = expected_end;
|
||||
|
||||
//if we've taken too much time we won't sleep
|
||||
if(sleep_time <= WallDuration(0.0))
|
||||
{
|
||||
// if we've jumped forward in time, or the loop has taken more than a full extra
|
||||
// cycle, reset our cycle
|
||||
if (actual_end > expected_end + expected_cycle_time_)
|
||||
{
|
||||
start_ = actual_end;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return sleep_time.sleep();
|
||||
}
|
||||
|
||||
void WallRate::reset()
|
||||
{
|
||||
start_ = WallTime::now();
|
||||
}
|
||||
|
||||
WallDuration WallRate::cycleTime() const
|
||||
{
|
||||
return actual_cycle_time_;
|
||||
}
|
||||
|
||||
}
|
||||
516
thirdparty/ros/roscpp_core/rostime/src/time.cpp
vendored
Normal file
516
thirdparty/ros/roscpp_core/rostime/src/time.cpp
vendored
Normal file
@@ -0,0 +1,516 @@
|
||||
/*********************************************************************
|
||||
* Software License Agreement (BSD License)
|
||||
*
|
||||
* Copyright (c) 2010, Willow Garage, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*********************************************************************/
|
||||
#ifdef _MSC_VER
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "ros/time.h"
|
||||
#include "ros/impl/time.h"
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
|
||||
// time related includes for macOS
|
||||
#if defined(__APPLE__)
|
||||
#include <mach/clock.h>
|
||||
#include <mach/mach.h>
|
||||
#endif // defined(__APPLE__)
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/io/ios_state.hpp>
|
||||
#include <boost/date_time/posix_time/ptime.hpp>
|
||||
|
||||
/*********************************************************************
|
||||
** Preprocessor
|
||||
*********************************************************************/
|
||||
|
||||
// Could probably do some better and more elaborate checking
|
||||
// and definition here.
|
||||
#define HAS_CLOCK_GETTIME (_POSIX_C_SOURCE >= 199309L)
|
||||
|
||||
/*********************************************************************
|
||||
** Namespaces
|
||||
*********************************************************************/
|
||||
|
||||
namespace ros
|
||||
{
|
||||
|
||||
/*********************************************************************
|
||||
** Variables
|
||||
*********************************************************************/
|
||||
|
||||
const Duration DURATION_MAX(std::numeric_limits<int32_t>::max(), 999999999);
|
||||
const Duration DURATION_MIN(std::numeric_limits<int32_t>::min(), 0);
|
||||
|
||||
const Time TIME_MAX(std::numeric_limits<uint32_t>::max(), 999999999);
|
||||
const Time TIME_MIN(0, 1);
|
||||
|
||||
// This is declared here because it's set from the Time class but read from
|
||||
// the Duration class, and need not be exported to users of either.
|
||||
static bool g_stopped(false);
|
||||
|
||||
// I assume that this is declared here, instead of time.h, to keep users
|
||||
// of time.h from including boost/thread/mutex.hpp
|
||||
static boost::mutex g_sim_time_mutex;
|
||||
|
||||
static bool g_initialized(false);
|
||||
static bool g_use_sim_time(true);
|
||||
static Time g_sim_time(0, 0);
|
||||
|
||||
/*********************************************************************
|
||||
** Cross Platform Functions
|
||||
*********************************************************************/
|
||||
void ros_walltime(uint32_t& sec, uint32_t& nsec)
|
||||
{
|
||||
#if !defined(_WIN32)
|
||||
#if HAS_CLOCK_GETTIME
|
||||
timespec start;
|
||||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
if (start.tv_sec < 0 || start.tv_sec > std::numeric_limits<uint32_t>::max())
|
||||
throw std::runtime_error("Timespec is out of dual 32-bit range");
|
||||
sec = start.tv_sec;
|
||||
nsec = start.tv_nsec;
|
||||
#else
|
||||
struct timeval timeofday;
|
||||
gettimeofday(&timeofday,NULL);
|
||||
if (timeofday.tv_sec < 0 || timeofday.tv_sec > std::numeric_limits<uint32_t>::max())
|
||||
throw std::runtime_error("Timeofday is out of dual signed 32-bit range");
|
||||
sec = timeofday.tv_sec;
|
||||
nsec = timeofday.tv_usec * 1000;
|
||||
#endif
|
||||
#else
|
||||
uint64_t now_s = 0;
|
||||
uint64_t now_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
|
||||
normalizeSecNSec(now_s, now_ns);
|
||||
|
||||
sec = (uint32_t)now_s;
|
||||
nsec = (uint32_t)now_ns;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ros_steadytime(uint32_t& sec, uint32_t& nsec)
|
||||
{
|
||||
#if !defined(_WIN32)
|
||||
timespec start;
|
||||
#if defined(__APPLE__)
|
||||
// On macOS use clock_get_time.
|
||||
clock_serv_t cclock;
|
||||
mach_timespec_t mts;
|
||||
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
|
||||
clock_get_time(cclock, &mts);
|
||||
mach_port_deallocate(mach_task_self(), cclock);
|
||||
start.tv_sec = mts.tv_sec;
|
||||
start.tv_nsec = mts.tv_nsec;
|
||||
#else // defined(__APPLE__)
|
||||
// Otherwise use clock_gettime.
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
#endif // defined(__APPLE__)
|
||||
sec = start.tv_sec;
|
||||
nsec = start.tv_nsec;
|
||||
#else
|
||||
uint64_t now_s = 0;
|
||||
uint64_t now_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||
|
||||
normalizeSecNSec(now_s, now_ns);
|
||||
|
||||
sec = (uint32_t)now_s;
|
||||
nsec = (uint32_t)now_ns;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* These have only internal linkage to this translation unit.
|
||||
* (i.e. not exposed to users of the time classes)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Simple representation of the rt library nanosleep function.
|
||||
*/
|
||||
int ros_nanosleep(const uint32_t &sec, const uint32_t &nsec)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
std::this_thread::sleep_for(std::chrono::nanoseconds(static_cast<int64_t>(sec * 1e9 + nsec)));
|
||||
return 0;
|
||||
#else
|
||||
timespec req = { sec, nsec };
|
||||
return nanosleep(&req, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Go to the wall!
|
||||
*
|
||||
* @todo Fully implement the win32 parts, currently just like a regular sleep.
|
||||
*/
|
||||
bool ros_wallsleep(uint32_t sec, uint32_t nsec)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
ros_nanosleep(sec,nsec);
|
||||
#else
|
||||
timespec req = { sec, nsec };
|
||||
timespec rem = {0, 0};
|
||||
while (nanosleep(&req, &rem) && !g_stopped)
|
||||
{
|
||||
req = rem;
|
||||
}
|
||||
#endif
|
||||
return !g_stopped;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
** Class Methods
|
||||
*********************************************************************/
|
||||
|
||||
bool Time::useSystemTime()
|
||||
{
|
||||
return !g_use_sim_time;
|
||||
}
|
||||
|
||||
bool Time::isSimTime()
|
||||
{
|
||||
return g_use_sim_time;
|
||||
}
|
||||
|
||||
bool Time::isSystemTime()
|
||||
{
|
||||
return !isSimTime();
|
||||
}
|
||||
|
||||
Time Time::now()
|
||||
{
|
||||
if (!g_initialized)
|
||||
{
|
||||
throw TimeNotInitializedException();
|
||||
}
|
||||
|
||||
if (g_use_sim_time)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(g_sim_time_mutex);
|
||||
Time t = g_sim_time;
|
||||
return t;
|
||||
}
|
||||
|
||||
Time t;
|
||||
ros_walltime(t.sec, t.nsec);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
void Time::setNow(const Time& new_now)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(g_sim_time_mutex);
|
||||
|
||||
g_sim_time = new_now;
|
||||
g_use_sim_time = true;
|
||||
}
|
||||
|
||||
void Time::init()
|
||||
{
|
||||
g_stopped = false;
|
||||
g_use_sim_time = false;
|
||||
g_initialized = true;
|
||||
}
|
||||
|
||||
void Time::shutdown()
|
||||
{
|
||||
g_stopped = true;
|
||||
}
|
||||
|
||||
bool Time::isValid()
|
||||
{
|
||||
return (!g_use_sim_time) || !g_sim_time.isZero();
|
||||
}
|
||||
|
||||
bool Time::waitForValid()
|
||||
{
|
||||
return waitForValid(ros::WallDuration());
|
||||
}
|
||||
|
||||
bool Time::waitForValid(const ros::WallDuration& timeout)
|
||||
{
|
||||
ros::WallTime start = ros::WallTime::now();
|
||||
while (!isValid() && !g_stopped)
|
||||
{
|
||||
ros::WallDuration(0.01).sleep();
|
||||
|
||||
if (timeout > ros::WallDuration(0, 0) && (ros::WallTime::now() - start > timeout))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_stopped)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Time Time::fromBoost(const boost::posix_time::ptime& t)
|
||||
{
|
||||
boost::posix_time::time_duration diff = t - boost::posix_time::from_time_t(0);
|
||||
return Time::fromBoost(diff);
|
||||
}
|
||||
|
||||
Time Time::fromBoost(const boost::posix_time::time_duration& d)
|
||||
{
|
||||
Time t;
|
||||
int64_t sec64 = d.total_seconds();
|
||||
if (sec64 < 0 || sec64 > std::numeric_limits<uint32_t>::max())
|
||||
throw std::runtime_error("time_duration is out of dual 32-bit range");
|
||||
t.sec = (uint32_t)sec64;
|
||||
#if defined(BOOST_DATE_TIME_HAS_NANOSECONDS)
|
||||
t.nsec = d.fractional_seconds();
|
||||
#else
|
||||
t.nsec = d.fractional_seconds()*1000;
|
||||
#endif
|
||||
return t;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Time &rhs)
|
||||
{
|
||||
boost::io::ios_all_saver s(os);
|
||||
os << rhs.sec << "." << std::setw(9) << std::setfill('0') << rhs.nsec;
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Duration& rhs)
|
||||
{
|
||||
boost::io::ios_all_saver s(os);
|
||||
if (rhs.sec >= 0 || rhs.nsec == 0)
|
||||
{
|
||||
os << rhs.sec << "." << std::setw(9) << std::setfill('0') << rhs.nsec;
|
||||
}
|
||||
else
|
||||
{
|
||||
os << (rhs.sec == -1 ? "-" : "") << (rhs.sec + 1) << "." << std::setw(9) << std::setfill('0') << (1000000000 - rhs.nsec);
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
bool Time::sleepUntil(const Time& end)
|
||||
{
|
||||
if (Time::useSystemTime())
|
||||
{
|
||||
Duration d(end - Time::now());
|
||||
if (d > Duration(0))
|
||||
{
|
||||
return d.sleep();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Time start = Time::now();
|
||||
while (!g_stopped && (Time::now() < end))
|
||||
{
|
||||
ros_nanosleep(0,1000000);
|
||||
if (Time::now() < start)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool WallTime::sleepUntil(const WallTime& end)
|
||||
{
|
||||
WallDuration d(end - WallTime::now());
|
||||
if (d > WallDuration(0))
|
||||
{
|
||||
return d.sleep();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SteadyTime::sleepUntil(const SteadyTime& end)
|
||||
{
|
||||
WallDuration d(end - SteadyTime::now());
|
||||
if (d > WallDuration(0))
|
||||
{
|
||||
return d.sleep();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Duration::sleep() const
|
||||
{
|
||||
if (Time::useSystemTime())
|
||||
{
|
||||
return ros_wallsleep(sec, nsec);
|
||||
}
|
||||
else
|
||||
{
|
||||
Time start = Time::now();
|
||||
Time end = start + *this;
|
||||
if (start.isZero())
|
||||
{
|
||||
end = TIME_MAX;
|
||||
}
|
||||
|
||||
bool rc = false;
|
||||
while (!g_stopped && (Time::now() < end))
|
||||
{
|
||||
ros_wallsleep(0, 1000000);
|
||||
rc = true;
|
||||
|
||||
// If we started at time 0 wait for the first actual time to arrive before starting the timer on
|
||||
// our sleep
|
||||
if (start.isZero())
|
||||
{
|
||||
start = Time::now();
|
||||
end = start + *this;
|
||||
}
|
||||
|
||||
// If time jumped backwards from when we started sleeping, return immediately
|
||||
if (Time::now() < start)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return rc && !g_stopped;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream& os, const WallTime &rhs)
|
||||
{
|
||||
boost::io::ios_all_saver s(os);
|
||||
os << rhs.sec << "." << std::setw(9) << std::setfill('0') << rhs.nsec;
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream& os, const SteadyTime &rhs)
|
||||
{
|
||||
boost::io::ios_all_saver s(os);
|
||||
os << rhs.sec << "." << std::setw(9) << std::setfill('0') << rhs.nsec;
|
||||
return os;
|
||||
}
|
||||
|
||||
WallTime WallTime::now()
|
||||
{
|
||||
WallTime t;
|
||||
ros_walltime(t.sec, t.nsec);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
SteadyTime SteadyTime::now()
|
||||
{
|
||||
SteadyTime t;
|
||||
ros_steadytime(t.sec, t.nsec);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream& os, const WallDuration& rhs)
|
||||
{
|
||||
boost::io::ios_all_saver s(os);
|
||||
if (rhs.sec >= 0 || rhs.nsec == 0)
|
||||
{
|
||||
os << rhs.sec << "." << std::setw(9) << std::setfill('0') << rhs.nsec;
|
||||
}
|
||||
else
|
||||
{
|
||||
os << (rhs.sec == -1 ? "-" : "") << (rhs.sec + 1) << "." << std::setw(9) << std::setfill('0') << (1000000000 - rhs.nsec);
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
bool WallDuration::sleep() const
|
||||
{
|
||||
return ros_wallsleep(sec, nsec);
|
||||
}
|
||||
|
||||
void normalizeSecNSec(uint64_t& sec, uint64_t& nsec)
|
||||
{
|
||||
uint64_t nsec_part = nsec % 1000000000UL;
|
||||
uint64_t sec_part = nsec / 1000000000UL;
|
||||
|
||||
if (sec + sec_part > std::numeric_limits<uint32_t>::max())
|
||||
throw std::runtime_error("Time is out of dual 32-bit range");
|
||||
|
||||
sec += sec_part;
|
||||
nsec = nsec_part;
|
||||
}
|
||||
|
||||
void normalizeSecNSec(uint32_t& sec, uint32_t& nsec)
|
||||
{
|
||||
uint64_t sec64 = sec;
|
||||
uint64_t nsec64 = nsec;
|
||||
|
||||
normalizeSecNSec(sec64, nsec64);
|
||||
|
||||
sec = (uint32_t)sec64;
|
||||
nsec = (uint32_t)nsec64;
|
||||
}
|
||||
|
||||
void normalizeSecNSecUnsigned(int64_t& sec, int64_t& nsec)
|
||||
{
|
||||
int64_t nsec_part = nsec % 1000000000L;
|
||||
int64_t sec_part = sec + nsec / 1000000000L;
|
||||
if (nsec_part < 0)
|
||||
{
|
||||
nsec_part += 1000000000L;
|
||||
--sec_part;
|
||||
}
|
||||
|
||||
if (sec_part < 0 || sec_part > std::numeric_limits<uint32_t>::max())
|
||||
throw std::runtime_error("Time is out of dual 32-bit range");
|
||||
|
||||
sec = sec_part;
|
||||
nsec = nsec_part;
|
||||
}
|
||||
|
||||
template class TimeBase<Time, Duration>;
|
||||
template class TimeBase<WallTime, WallDuration>;
|
||||
template class TimeBase<SteadyTime, WallDuration>;
|
||||
}
|
||||
167
thirdparty/ros/roscpp_core/rostime/test/duration.cpp
vendored
Normal file
167
thirdparty/ros/roscpp_core/rostime/test/duration.cpp
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Open Source Robotics Foundation, Inc..
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ros/duration.h>
|
||||
#include <ros/time.h>
|
||||
|
||||
using namespace ros;
|
||||
|
||||
TEST(Duration, sleepWithSimTime)
|
||||
{
|
||||
ros::Time::init();
|
||||
|
||||
Time start = Time::now();
|
||||
start -= Duration(2.0);
|
||||
Time::setNow(start);
|
||||
|
||||
Time::shutdown();
|
||||
|
||||
Duration d(1.0);
|
||||
bool rc = d.sleep();
|
||||
ASSERT_FALSE(rc);
|
||||
}
|
||||
|
||||
TEST(Duration, castFromDoubleExceptions)
|
||||
{
|
||||
ros::Time::init();
|
||||
|
||||
Duration d1, d2, d3, d4;
|
||||
// Valid values to cast, must not throw exceptions
|
||||
EXPECT_NO_THROW(d1.fromSec(-2147483648.0));
|
||||
EXPECT_NO_THROW(d2.fromSec(-2147483647.999999));
|
||||
EXPECT_NO_THROW(d3.fromSec(2147483647.0));
|
||||
EXPECT_NO_THROW(d4.fromSec(2147483647.999999));
|
||||
|
||||
// The next casts all incorrect.
|
||||
EXPECT_THROW(d1.fromSec(2147483648.0), std::runtime_error);
|
||||
EXPECT_THROW(d2.fromSec(6442450943.0), std::runtime_error); // It's 2^31 - 1 + 2^32, and it could pass the test.
|
||||
EXPECT_THROW(d3.fromSec(-2147483648.001), std::runtime_error);
|
||||
EXPECT_THROW(d4.fromSec(-6442450943.0), std::runtime_error);
|
||||
}
|
||||
|
||||
TEST(Duration, castFromInt64Exceptions)
|
||||
{
|
||||
ros::Time::init();
|
||||
|
||||
Duration d1, d2, d3, d4;
|
||||
// Valid values to cast, must not throw exceptions
|
||||
EXPECT_NO_THROW(d1.fromNSec(-2147483648000000000));
|
||||
EXPECT_NO_THROW(d2.fromNSec(-2147483647999999999));
|
||||
EXPECT_NO_THROW(d3.fromNSec(2147483647000000000));
|
||||
EXPECT_NO_THROW(d4.fromNSec(2147483647999999999));
|
||||
|
||||
// The next casts all incorrect.
|
||||
EXPECT_THROW(d1.fromSec(2147483648000000000), std::runtime_error);
|
||||
EXPECT_THROW(d2.fromSec(4294967296000000000), std::runtime_error);
|
||||
EXPECT_THROW(d3.fromSec(-2147483648000000001), std::runtime_error);
|
||||
EXPECT_THROW(d4.fromSec(-6442450943000000000), std::runtime_error);
|
||||
}
|
||||
|
||||
TEST(Duration, arithmeticExceptions)
|
||||
{
|
||||
ros::Time::init();
|
||||
|
||||
Duration d1(2147483647, 0);
|
||||
Duration d2(2147483647, 999999999);
|
||||
EXPECT_THROW(d1 + d2, std::runtime_error);
|
||||
|
||||
Duration d3(-2147483648, 0);
|
||||
Duration d4(2147483647, 0);
|
||||
EXPECT_THROW(d3 - d4, std::runtime_error);
|
||||
EXPECT_THROW(d4 - d3, std::runtime_error);
|
||||
|
||||
Duration d5(-2147483647, 1);
|
||||
Duration d6(-2, 999999999);
|
||||
Duration d7;
|
||||
EXPECT_NO_THROW(d7 = d5 + d6);
|
||||
EXPECT_EQ(-2147483648000000000, d7.toNSec());
|
||||
}
|
||||
|
||||
TEST(Duration, negativeSignExceptions)
|
||||
{
|
||||
ros::Time::init();
|
||||
|
||||
Duration d1(2147483647, 0);
|
||||
Duration d2(2147483647, 999999999);
|
||||
Duration d3;
|
||||
EXPECT_NO_THROW(d3 = -d1);
|
||||
EXPECT_EQ(-2147483647000000000, d3.toNSec());
|
||||
EXPECT_NO_THROW(d3 = -d2);
|
||||
EXPECT_EQ(-2147483647999999999, d3.toNSec());
|
||||
|
||||
Duration d4(-2147483647, 0);
|
||||
Duration d5(-2147483648, 999999999);
|
||||
Duration d6(-2147483648, 2);
|
||||
Duration d7;
|
||||
EXPECT_NO_THROW(d7 = -d4);
|
||||
EXPECT_EQ(2147483647000000000, d7.toNSec());
|
||||
EXPECT_NO_THROW(d7 = -d5);
|
||||
EXPECT_EQ(2147483647000000001, d7.toNSec());
|
||||
EXPECT_NO_THROW(d7 = -d6);
|
||||
EXPECT_EQ(2147483647999999998, d7.toNSec());
|
||||
}
|
||||
|
||||
TEST(Duration, rounding)
|
||||
{
|
||||
ros::Time::init();
|
||||
|
||||
Duration d1(49.0000000004);
|
||||
EXPECT_EQ(49, d1.sec);
|
||||
EXPECT_EQ(0, d1.nsec);
|
||||
Duration d2(-49.0000000004);
|
||||
EXPECT_EQ(-49, d2.sec);
|
||||
EXPECT_EQ(0, d2.nsec);
|
||||
|
||||
Duration d3(49.0000000006);
|
||||
EXPECT_EQ(49, d3.sec);
|
||||
EXPECT_EQ(1, d3.nsec);
|
||||
Duration d4(-49.0000000006);
|
||||
EXPECT_EQ(-50, d4.sec);
|
||||
EXPECT_EQ(999999999, d4.nsec);
|
||||
|
||||
Duration d5(49.9999999994);
|
||||
EXPECT_EQ(49, d5.sec);
|
||||
EXPECT_EQ(999999999, d5.nsec);
|
||||
Duration d6(-49.9999999994);
|
||||
EXPECT_EQ(-50, d6.sec);
|
||||
EXPECT_EQ(1, d6.nsec);
|
||||
|
||||
Duration d7(49.9999999996);
|
||||
EXPECT_EQ(50, d7.sec);
|
||||
EXPECT_EQ(0, d7.nsec);
|
||||
Duration d8(-49.9999999996);
|
||||
EXPECT_EQ(-50, d8.sec);
|
||||
EXPECT_EQ(0, d8.nsec);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
611
thirdparty/ros/roscpp_core/rostime/test/time.cpp
vendored
Normal file
611
thirdparty/ros/roscpp_core/rostime/test/time.cpp
vendored
Normal file
@@ -0,0 +1,611 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Willow Garage, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of Willow Garage, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ros/rate.h>
|
||||
#include <ros/time.h>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <boost/date_time/posix_time/ptime.hpp>
|
||||
|
||||
using namespace ros;
|
||||
|
||||
/// \todo All the tests in here that use randomized values are not unit tests, replace them
|
||||
|
||||
double epsilon = 1e-9;
|
||||
|
||||
void seed_rand()
|
||||
{
|
||||
//Seed random number generator with current microseond count
|
||||
#if !defined(_WIN32)
|
||||
timeval temp_time_struct;
|
||||
gettimeofday(&temp_time_struct,NULL);
|
||||
srand(temp_time_struct.tv_usec);
|
||||
#else
|
||||
srand(time(nullptr));
|
||||
#endif
|
||||
};
|
||||
|
||||
void generate_rand_times(uint32_t range, uint64_t runs, std::vector<ros::Time>& values1, std::vector<ros::Time>& values2)
|
||||
{
|
||||
seed_rand();
|
||||
values1.clear();
|
||||
values2.clear();
|
||||
values1.reserve(runs);
|
||||
values2.reserve(runs);
|
||||
for ( uint32_t i = 0; i < runs ; i++ )
|
||||
{
|
||||
values1.push_back(ros::Time( (rand() * range / RAND_MAX), (rand() * 1000000000ULL/RAND_MAX)));
|
||||
values2.push_back(ros::Time( (rand() * range / RAND_MAX), (rand() * 1000000000ULL/RAND_MAX)));
|
||||
}
|
||||
}
|
||||
|
||||
void generate_rand_durations(uint32_t range, uint64_t runs, std::vector<ros::Duration>& values1, std::vector<ros::Duration>& values2)
|
||||
{
|
||||
seed_rand();
|
||||
values1.clear();
|
||||
values2.clear();
|
||||
values1.reserve(runs * 4);
|
||||
values2.reserve(runs * 4);
|
||||
for ( uint32_t i = 0; i < runs ; i++ )
|
||||
{
|
||||
// positive durations
|
||||
values1.push_back(ros::Duration( (rand() * range / RAND_MAX), (rand() * 1000000000ULL/RAND_MAX)));
|
||||
values2.push_back(ros::Duration( (rand() * range / RAND_MAX), (rand() * 1000000000ULL/RAND_MAX)));
|
||||
EXPECT_GE(values1.back(), ros::Duration(0,0));
|
||||
EXPECT_GE(values2.back(), ros::Duration(0,0));
|
||||
|
||||
// negative durations
|
||||
values1.push_back(ros::Duration( -(rand() * range / RAND_MAX), -(rand() * 1000000000ULL/RAND_MAX)));
|
||||
values2.push_back(ros::Duration( -(rand() * range / RAND_MAX), -(rand() * 1000000000ULL/RAND_MAX)));
|
||||
EXPECT_LE(values1.back(), ros::Duration(0,0));
|
||||
EXPECT_LE(values2.back(), ros::Duration(0,0));
|
||||
|
||||
// positive and negative durations
|
||||
values1.push_back(ros::Duration( (rand() * range / RAND_MAX), (rand() * 1000000000ULL/RAND_MAX)));
|
||||
values2.push_back(ros::Duration( -(rand() * range / RAND_MAX), -(rand() * 1000000000ULL/RAND_MAX)));
|
||||
EXPECT_GE(values1.back(), ros::Duration(0,0));
|
||||
EXPECT_LE(values2.back(), ros::Duration(0,0));
|
||||
|
||||
// negative and positive durations
|
||||
values1.push_back(ros::Duration( -(rand() * range / RAND_MAX), -(rand() * 1000000000ULL/RAND_MAX)));
|
||||
values2.push_back(ros::Duration( (rand() * range / RAND_MAX), (rand() * 1000000000ULL/RAND_MAX)));
|
||||
EXPECT_LE(values1.back(), ros::Duration(0,0));
|
||||
EXPECT_GE(values2.back(), ros::Duration(0,0));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Time, size)
|
||||
{
|
||||
ASSERT_EQ(sizeof(Time), 8);
|
||||
ASSERT_EQ(sizeof(Duration), 8);
|
||||
}
|
||||
|
||||
TEST(Time, Comparitors)
|
||||
{
|
||||
std::vector<ros::Time> v1;
|
||||
std::vector<ros::Time> v2;
|
||||
generate_rand_times(100, 1000, v1,v2);
|
||||
|
||||
for (uint32_t i = 0; i < v1.size(); i++)
|
||||
{
|
||||
if (v1[i].sec * 1000000000ULL + v1[i].nsec < v2[i].sec * 1000000000ULL + v2[i].nsec)
|
||||
{
|
||||
EXPECT_LT(v1[i], v2[i]);
|
||||
// printf("%f %d ", v1[i].toSec(), v1[i].sec * 1000000000ULL + v1[i].nsec);
|
||||
//printf("vs %f %d\n", v2[i].toSec(), v2[i].sec * 1000000000ULL + v2[i].nsec);
|
||||
EXPECT_LE(v1[i], v2[i]);
|
||||
EXPECT_NE(v1[i], v2[i]);
|
||||
}
|
||||
else if (v1[i].sec * 1000000000ULL + v1[i].nsec > v2[i].sec * 1000000000ULL + v2[i].nsec)
|
||||
{
|
||||
EXPECT_GT(v1[i], v2[i]);
|
||||
EXPECT_GE(v1[i], v2[i]);
|
||||
EXPECT_NE(v1[i], v2[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
EXPECT_EQ(v1[i], v2[i]);
|
||||
EXPECT_LE(v1[i], v2[i]);
|
||||
EXPECT_GE(v1[i], v2[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(Time, ToFromDouble)
|
||||
{
|
||||
std::vector<ros::Time> v1;
|
||||
std::vector<ros::Time> v2;
|
||||
generate_rand_times(100, 1000, v1,v2);
|
||||
|
||||
for (uint32_t i = 0; i < v1.size(); i++)
|
||||
{
|
||||
EXPECT_EQ(v1[i].toSec(), v1[i].fromSec(v1[i].toSec()).toSec());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(Time, RoundingError)
|
||||
{
|
||||
double someInt = 1031.0; // some integer
|
||||
double t = std::nextafter(someInt, 0); // someint - epsilon
|
||||
// t should be 1031.000000
|
||||
|
||||
ros::Time exampleTime;
|
||||
exampleTime.fromSec(t);
|
||||
|
||||
// if rounded incorrectly, sec may be 1030
|
||||
// and nsec may be 1e9.
|
||||
EXPECT_EQ(exampleTime.sec, 1031);
|
||||
EXPECT_EQ(exampleTime.nsec, 0);
|
||||
}
|
||||
|
||||
TEST(Time, OperatorPlus)
|
||||
{
|
||||
Time t(100, 0);
|
||||
Duration d(100, 0);
|
||||
Time r = t + d;
|
||||
EXPECT_EQ(r.sec, 200UL);
|
||||
EXPECT_EQ(r.nsec, 0UL);
|
||||
|
||||
t = Time(0, 100000UL);
|
||||
d = Duration(0, 100UL);
|
||||
r = t + d;
|
||||
EXPECT_EQ(r.sec, 0UL);
|
||||
EXPECT_EQ(r.nsec, 100100UL);
|
||||
|
||||
t = Time(0, 0);
|
||||
d = Duration(10, 2000003000UL);
|
||||
r = t + d;
|
||||
EXPECT_EQ(r.sec, 12UL);
|
||||
EXPECT_EQ(r.nsec, 3000UL);
|
||||
}
|
||||
|
||||
TEST(Time, OperatorMinus)
|
||||
{
|
||||
Time t(100, 0);
|
||||
Duration d(100, 0);
|
||||
Time r = t - d;
|
||||
EXPECT_EQ(r.sec, 0UL);
|
||||
EXPECT_EQ(r.nsec, 0UL);
|
||||
|
||||
t = Time(0, 100000UL);
|
||||
d = Duration(0, 100UL);
|
||||
r = t - d;
|
||||
EXPECT_EQ(r.sec, 0UL);
|
||||
EXPECT_EQ(r.nsec, 99900UL);
|
||||
|
||||
t = Time(30, 0);
|
||||
d = Duration(10, 2000003000UL);
|
||||
r = t - d;
|
||||
EXPECT_EQ(r.sec, 17UL);
|
||||
EXPECT_EQ(r.nsec, 999997000ULL);
|
||||
}
|
||||
|
||||
TEST(Time, OperatorPlusEquals)
|
||||
{
|
||||
Time t(100, 0);
|
||||
Duration d(100, 0);
|
||||
t += d;
|
||||
EXPECT_EQ(t.sec, 200UL);
|
||||
EXPECT_EQ(t.nsec, 0UL);
|
||||
|
||||
t = Time(0, 100000UL);
|
||||
d = Duration(0, 100UL);
|
||||
t += d;
|
||||
EXPECT_EQ(t.sec, 0UL);
|
||||
EXPECT_EQ(t.nsec, 100100UL);
|
||||
|
||||
t = Time(0, 0);
|
||||
d = Duration(10, 2000003000UL);
|
||||
t += d;
|
||||
EXPECT_EQ(t.sec, 12UL);
|
||||
EXPECT_EQ(t.nsec, 3000UL);
|
||||
}
|
||||
|
||||
TEST(Time, OperatorMinusEquals)
|
||||
{
|
||||
Time t(100, 0);
|
||||
Duration d(100, 0);
|
||||
t -= d;
|
||||
EXPECT_EQ(t.sec, 0UL);
|
||||
EXPECT_EQ(t.nsec, 0UL);
|
||||
|
||||
t = Time(0, 100000UL);
|
||||
d = Duration(0, 100UL);
|
||||
t -= d;
|
||||
EXPECT_EQ(t.sec, 0UL);
|
||||
EXPECT_EQ(t.nsec, 99900UL);
|
||||
|
||||
t = Time(30, 0);
|
||||
d = Duration(10, 2000003000UL);
|
||||
t -= d;
|
||||
EXPECT_EQ(t.sec, 17UL);
|
||||
EXPECT_EQ(t.nsec, 999997000ULL);
|
||||
}
|
||||
|
||||
TEST(Time, SecNSecConstructor)
|
||||
{
|
||||
Time t(100, 2000003000UL);
|
||||
EXPECT_EQ(t.sec, 102UL);
|
||||
EXPECT_EQ(t.nsec, 3000UL);
|
||||
}
|
||||
|
||||
TEST(Time, DontMungeStreamState)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
Time t(100, 2000003000UL);
|
||||
oss << std::setfill('N');
|
||||
oss << std::setw(13);
|
||||
oss << t;
|
||||
|
||||
EXPECT_EQ(oss.width(), 13);
|
||||
EXPECT_EQ(oss.fill(), 'N');
|
||||
}
|
||||
|
||||
TEST(Time, ToFromBoost)
|
||||
{
|
||||
std::vector<ros::Time> v1;
|
||||
std::vector<ros::Time> v2;
|
||||
generate_rand_times(100, 1000, v1,v2);
|
||||
|
||||
for (uint32_t i = 0; i < v1.size(); i++)
|
||||
{
|
||||
Time t = v1[i];
|
||||
// dont assume that nanosecond are available
|
||||
t.nsec = uint32_t(t.nsec / 1000.0) * 1000;
|
||||
boost::posix_time::ptime b = t.toBoost();
|
||||
Time tt = Time::fromBoost(b);
|
||||
EXPECT_EQ(t, tt);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Time, CastFromDoubleExceptions)
|
||||
{
|
||||
ros::Time::init();
|
||||
|
||||
Time t1, t2, t3;
|
||||
// Valid values to cast, must not throw exceptions
|
||||
EXPECT_NO_THROW(t1.fromSec(4294967295.0));
|
||||
EXPECT_NO_THROW(t2.fromSec(4294967295.999));
|
||||
EXPECT_NO_THROW(t3.fromSec(0.0000001));
|
||||
|
||||
// The next casts all incorrect.
|
||||
EXPECT_THROW(t1.fromSec(4294967296.0), std::runtime_error);
|
||||
EXPECT_THROW(t2.fromSec(-0.0001), std::runtime_error);
|
||||
EXPECT_THROW(t3.fromSec(-4294967296.0), std::runtime_error);
|
||||
}
|
||||
|
||||
TEST(Time, OperatorMinusExceptions)
|
||||
{
|
||||
ros::Time::init();
|
||||
|
||||
Time t1(2147483648, 0);
|
||||
Time t2(2147483647, 999999999);
|
||||
Time t3(2147483647, 999999998);
|
||||
Time t4(4294967295, 999999999);
|
||||
Time t5(4294967295, 999999998);
|
||||
Time t6(0, 1);
|
||||
|
||||
Duration d1(2147483647, 999999999);
|
||||
Duration d2(-2147483648, 0);
|
||||
Duration d3(-2147483648, 1);
|
||||
Duration d4(0, 1);
|
||||
|
||||
EXPECT_NO_THROW(t1 - t2);
|
||||
EXPECT_NO_THROW(t3 - t2);
|
||||
EXPECT_NO_THROW(t4 - t5);
|
||||
|
||||
EXPECT_NO_THROW(t1 - d1);
|
||||
EXPECT_NO_THROW(t5 - d1);
|
||||
|
||||
EXPECT_THROW(t4 - t6, std::runtime_error);
|
||||
EXPECT_THROW(t4 - t3, std::runtime_error);
|
||||
|
||||
EXPECT_THROW(t1 - d2, std::runtime_error);
|
||||
EXPECT_THROW(t2 - d2, std::runtime_error);
|
||||
EXPECT_THROW(t4 - d3, std::runtime_error);
|
||||
}
|
||||
|
||||
TEST(Time, OperatorPlusExceptions)
|
||||
{
|
||||
ros::Time::init();
|
||||
|
||||
Time t1(2147483648, 0);
|
||||
Time t2(2147483647, 999999999);
|
||||
Time t4(4294967295, 999999999);
|
||||
Time t5(4294967295, 999999998);
|
||||
|
||||
Duration d1(2147483647, 999999999);
|
||||
Duration d2(-2147483648, 1);
|
||||
Duration d3(0, 2);
|
||||
Duration d4(0, 1);
|
||||
|
||||
EXPECT_NO_THROW(t2 + d2);
|
||||
EXPECT_NO_THROW(t1 + d1);
|
||||
|
||||
EXPECT_THROW(t4 + d4, std::runtime_error);
|
||||
EXPECT_THROW(t4 + d1, std::runtime_error);
|
||||
EXPECT_THROW(t5 + d3, std::runtime_error);
|
||||
}
|
||||
|
||||
/************************************* Duration Tests *****************/
|
||||
|
||||
TEST(Duration, Comparitors)
|
||||
{
|
||||
std::vector<ros::Duration> v1;
|
||||
std::vector<ros::Duration> v2;
|
||||
generate_rand_durations(100, 1000, v1,v2);
|
||||
|
||||
for (uint32_t i = 0; i < v1.size(); i++)
|
||||
{
|
||||
if (v1[i].sec * 1000000000LL + v1[i].nsec < v2[i].sec * 1000000000LL + v2[i].nsec)
|
||||
{
|
||||
EXPECT_LT(v1[i], v2[i]);
|
||||
// printf("%f %lld ", v1[i].toSec(), v1[i].sec * 1000000000LL + v1[i].nsec);
|
||||
// printf("vs %f %lld\n", v2[i].toSec(), v2[i].sec * 1000000000LL + v2[i].nsec);
|
||||
EXPECT_LE(v1[i], v2[i]);
|
||||
EXPECT_NE(v1[i], v2[i]);
|
||||
}
|
||||
else if (v1[i].sec * 1000000000LL + v1[i].nsec > v2[i].sec * 1000000000LL + v2[i].nsec)
|
||||
{
|
||||
EXPECT_GT(v1[i], v2[i]);
|
||||
// printf("%f %lld ", v1[i].toSec(), v1[i].sec * 1000000000LL + v1[i].nsec);
|
||||
// printf("vs %f %lld\n", v2[i].toSec(), v2[i].sec * 1000000000LL + v2[i].nsec);
|
||||
EXPECT_GE(v1[i], v2[i]);
|
||||
EXPECT_NE(v1[i], v2[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
EXPECT_EQ(v1[i], v2[i]);
|
||||
EXPECT_LE(v1[i], v2[i]);
|
||||
EXPECT_GE(v1[i], v2[i]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Duration, ToFromSec)
|
||||
{
|
||||
std::vector<ros::Duration> v1;
|
||||
std::vector<ros::Duration> v2;
|
||||
generate_rand_durations(100, 1000, v1,v2);
|
||||
|
||||
for (uint32_t i = 0; i < v1.size(); i++)
|
||||
{
|
||||
EXPECT_EQ(v1[i].toSec(), v1[i].fromSec(v1[i].toSec()).toSec());
|
||||
EXPECT_GE(ros::Duration(v1[i].toSec()).nsec, 0);
|
||||
}
|
||||
|
||||
EXPECT_EQ(ros::Duration(-0.5), ros::Duration(-1LL, 500000000LL));
|
||||
EXPECT_EQ(ros::Duration(-0.5), ros::Duration(0, -500000000LL));
|
||||
}
|
||||
|
||||
TEST(Duration, FromNSec)
|
||||
{
|
||||
ros::Duration t;
|
||||
t.fromNSec(-500000000LL);
|
||||
EXPECT_EQ(ros::Duration(-0.5), t);
|
||||
|
||||
t.fromNSec(-1500000000LL);
|
||||
EXPECT_EQ(ros::Duration(-1.5), t);
|
||||
|
||||
t.fromNSec(500000000LL);
|
||||
EXPECT_EQ(ros::Duration(0.5), t);
|
||||
|
||||
t.fromNSec(1500000000LL);
|
||||
EXPECT_EQ(ros::Duration(1.5), t);
|
||||
}
|
||||
|
||||
TEST(Duration, OperatorPlus)
|
||||
{
|
||||
std::vector<ros::Duration> v1;
|
||||
std::vector<ros::Duration> v2;
|
||||
generate_rand_durations(100, 1000, v1,v2);
|
||||
|
||||
for (uint32_t i = 0; i < v1.size(); i++)
|
||||
{
|
||||
EXPECT_NEAR(v1[i].toSec() + v2[i].toSec(), (v1[i] + v2[i]).toSec(), epsilon);
|
||||
ros::Duration temp = v1[i];
|
||||
EXPECT_NEAR(v1[i].toSec() + v2[i].toSec(), (temp += v2[i]).toSec(), epsilon);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(Duration, OperatorMinus)
|
||||
{
|
||||
std::vector<ros::Duration> v1;
|
||||
std::vector<ros::Duration> v2;
|
||||
generate_rand_durations(100, 1000, v1,v2);
|
||||
|
||||
for (uint32_t i = 0; i < v1.size(); i++)
|
||||
{
|
||||
EXPECT_NEAR(v1[i].toSec() - v2[i].toSec(), (v1[i] - v2[i]).toSec(), epsilon);
|
||||
ros::Duration temp = v1[i];
|
||||
EXPECT_NEAR(v1[i].toSec() - v2[i].toSec(), (temp -= v2[i]).toSec(), epsilon);
|
||||
|
||||
EXPECT_NEAR(- v2[i].toSec(), (-v2[i]).toSec(), epsilon);
|
||||
|
||||
}
|
||||
|
||||
ros::Time t1(1.1);
|
||||
ros::Time t2(1.3);
|
||||
ros::Duration time_diff = t1 - t2; //=-0.2
|
||||
|
||||
EXPECT_NEAR(time_diff.toSec(), -0.2, epsilon);
|
||||
EXPECT_LE(time_diff, ros::Duration(-0.19));
|
||||
EXPECT_GE(time_diff, ros::Duration(-0.21));
|
||||
}
|
||||
|
||||
TEST(Duration, OperatorTimes)
|
||||
{
|
||||
std::vector<ros::Duration> v1;
|
||||
std::vector<ros::Duration> v2;
|
||||
generate_rand_durations(100, 1000, v1,v2);
|
||||
|
||||
for (uint32_t i = 0; i < v1.size(); i++)
|
||||
{
|
||||
EXPECT_NEAR(v1[i].toSec() * v2[i].toSec(), (v1[i] * v2[i].toSec()).toSec(), epsilon);
|
||||
ros::Duration temp = v1[i];
|
||||
EXPECT_NEAR(v1[i].toSec() * v2[i].toSec(), (temp *= v2[i].toSec()).toSec(), epsilon);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(Duration, OperatorPlusEquals)
|
||||
{
|
||||
Duration t(100, 0);
|
||||
Duration d(100, 0);
|
||||
t += d;
|
||||
EXPECT_EQ(t.sec, 200L);
|
||||
EXPECT_EQ(t.nsec, 0L);
|
||||
|
||||
t = Duration(0, 100000L);
|
||||
d = Duration(0, 100L);
|
||||
t += d;
|
||||
EXPECT_EQ(t.sec, 0L);
|
||||
EXPECT_EQ(t.nsec, 100100L);
|
||||
|
||||
t = Duration(0, 0);
|
||||
d = Duration(10, 2000003000L);
|
||||
t += d;
|
||||
EXPECT_EQ(t.sec, 12L);
|
||||
EXPECT_EQ(t.nsec, 3000L);
|
||||
}
|
||||
|
||||
TEST(Duration, OperatorMinusEquals)
|
||||
{
|
||||
Duration t(100, 0);
|
||||
Duration d(100, 0);
|
||||
t -= d;
|
||||
EXPECT_EQ(t.sec, 0L);
|
||||
EXPECT_EQ(t.nsec, 0L);
|
||||
|
||||
t = Duration(0, 100000L);
|
||||
d = Duration(0, 100L);
|
||||
t -= d;
|
||||
EXPECT_EQ(t.sec, 0L);
|
||||
EXPECT_EQ(t.nsec, 99900L);
|
||||
|
||||
t = Duration(30, 0);
|
||||
d = Duration(10, 2000003000L);
|
||||
t -= d;
|
||||
EXPECT_EQ(t.sec, 17L);
|
||||
EXPECT_EQ(t.nsec, 999997000L);
|
||||
}
|
||||
|
||||
void alarmHandler(int sig)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST(Duration, sleepWithSignal)
|
||||
{
|
||||
#if !defined(_WIN32)
|
||||
signal(SIGALRM, alarmHandler);
|
||||
alarm(1);
|
||||
#endif
|
||||
|
||||
Time start = Time::now();
|
||||
Duration d(2.0);
|
||||
bool rc = d.sleep();
|
||||
Time end = Time::now();
|
||||
|
||||
ASSERT_GT(end - start, d);
|
||||
ASSERT_TRUE(rc);
|
||||
}
|
||||
|
||||
TEST(Rate, constructFromDuration){
|
||||
Duration d(4, 0);
|
||||
Rate r(d);
|
||||
EXPECT_EQ(r.expectedCycleTime(), d);
|
||||
}
|
||||
|
||||
TEST(Rate, sleep_return_value_true){
|
||||
Rate r(Duration(0.2));
|
||||
Duration(r.expectedCycleTime() * 0.5).sleep();
|
||||
EXPECT_TRUE(r.sleep());
|
||||
}
|
||||
|
||||
TEST(Rate, sleep_return_value_false){
|
||||
Rate r(Duration(0.2));
|
||||
Duration(r.expectedCycleTime() * 2).sleep();
|
||||
EXPECT_FALSE(r.sleep()); // requested rate cannot be achieved
|
||||
}
|
||||
|
||||
TEST(WallRate, constructFromDuration){
|
||||
Duration d(4, 0);
|
||||
WallRate r(d);
|
||||
WallDuration wd(4, 0);
|
||||
EXPECT_EQ(r.expectedCycleTime(), wd);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// WallTime/WallDuration
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// SteadyTime/WallDuration
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST(SteadyTime, sleep){
|
||||
SteadyTime start = SteadyTime::now();
|
||||
WallDuration d(2.0);
|
||||
bool rc = d.sleep();
|
||||
SteadyTime end = SteadyTime::now();
|
||||
|
||||
ASSERT_GT(end - start, d);
|
||||
ASSERT_TRUE(rc);
|
||||
}
|
||||
|
||||
TEST(SteadyTime, sleepUntil){
|
||||
SteadyTime start = SteadyTime::now();
|
||||
SteadyTime end = start + WallDuration(2.0);
|
||||
bool rc = SteadyTime::sleepUntil(end);
|
||||
SteadyTime finished = SteadyTime::now();
|
||||
|
||||
ASSERT_GT(finished, end);
|
||||
ASSERT_TRUE(rc);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
ros::Time::init();
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in New Issue
Block a user