Program Listing for File utilities.hpp

Return to documentation for file (include/rclcpp/utilities.hpp)

// Copyright 2014 Open Source Robotics Foundation, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef RCLCPP__UTILITIES_HPP_
#define RCLCPP__UTILITIES_HPP_

#include <chrono>
#include <functional>
#include <limits>
#include <string>
#include <vector>

#include "rclcpp/context.hpp"
#include "rclcpp/init_options.hpp"
#include "rclcpp/visibility_control.hpp"

#ifdef ANDROID
#include <sstream>

namespace std
{
template<typename T>
std::string to_string(T value)
{
  std::ostringstream os;
  os << value;
  return os.str();
}
}
#endif

namespace rclcpp
{

enum class SignalHandlerOptions
{
  All,
  SigInt,
  SigTerm,
  None,
};


RCLCPP_PUBLIC
void
init(
  int argc,
  char const * const * argv,
  const InitOptions & init_options = InitOptions(),
  SignalHandlerOptions signal_handler_options = SignalHandlerOptions::All);


RCLCPP_PUBLIC
bool
install_signal_handlers(SignalHandlerOptions signal_handler_options = SignalHandlerOptions::All);

RCLCPP_PUBLIC
bool
signal_handlers_installed();


RCLCPP_PUBLIC
SignalHandlerOptions
get_current_signal_handler_options();


RCLCPP_PUBLIC
bool
uninstall_signal_handlers();


RCLCPP_PUBLIC
std::vector<std::string>
init_and_remove_ros_arguments(
  int argc,
  char const * const * argv,
  const InitOptions & init_options = InitOptions());


RCLCPP_PUBLIC
std::vector<std::string>
remove_ros_arguments(int argc, char const * const * argv);


RCLCPP_PUBLIC
bool
ok(rclcpp::Context::SharedPtr context = nullptr);


RCLCPP_PUBLIC
bool
shutdown(
  rclcpp::Context::SharedPtr context = nullptr,
  const std::string & reason = "user called rclcpp::shutdown()");


RCLCPP_PUBLIC
void
on_shutdown(std::function<void()> callback, rclcpp::Context::SharedPtr context = nullptr);


RCLCPP_PUBLIC
bool
sleep_for(
  const std::chrono::nanoseconds & nanoseconds,
  rclcpp::Context::SharedPtr context = nullptr);


template<typename T>
bool
add_will_overflow(const T x, const T y)
{
  return (y > 0) && (x > (std::numeric_limits<T>::max() - y));
}


template<typename T>
bool
add_will_underflow(const T x, const T y)
{
  return (y < 0) && (x < (std::numeric_limits<T>::min() - y));
}


template<typename T>
bool
sub_will_overflow(const T x, const T y)
{
  return (y < 0) && (x > (std::numeric_limits<T>::max() + y));
}


template<typename T>
bool
sub_will_underflow(const T x, const T y)
{
  return (y > 0) && (x < (std::numeric_limits<T>::min() + y));
}


RCLCPP_PUBLIC
const char *
get_c_string(const char * string_in);


RCLCPP_PUBLIC
const char *
get_c_string(const std::string & string_in);


RCLCPP_PUBLIC
std::vector<const char *>
get_c_vector_string(const std::vector<std::string> & strings_in);

}  // namespace rclcpp

#endif  // RCLCPP__UTILITIES_HPP_