string_utils/ros.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 // SPDX-License-Identifier: BSD-3-Clause
4 // SPDX-FileCopyrightText: Czech Technical University in Prague
5 
12 #include <sstream>
13 #include <string>
14 #include <type_traits>
15 
16 #include <ros/duration.h>
17 #include <ros/rate.h>
18 #include <ros/time.h>
19 #include <ros/message_traits.h>
20 
24 
25 namespace cras
26 {
27 
28 template<typename T, typename ::std::enable_if_t<
29  ::std::is_same<T, ::ros::Time>::value ||
30  ::std::is_same<T, ::ros::WallTime>::value ||
31  ::std::is_same<T, ::ros::SteadyTime>::value ||
32  ::std::is_same<T, ::ros::Duration>::value ||
33  ::std::is_same<T, ::ros::WallDuration>::value
34  >* = nullptr>
35 inline ::std::string to_string(const T& value)
36 {
37  ::std::stringstream ss;
38  ss << value;
39  return ss.str();
40 }
41 
48 template<typename T, typename ::std::enable_if_t<
49  ::std::is_same<T, ::ros::Time>::value ||
50  ::std::is_same<T, ::ros::WallTime>::value ||
51  ::std::is_same<T, ::ros::SteadyTime>::value
52  >* = nullptr>
53 ::std::string to_pretty_string(const T& value);
54 
55 template<typename T, typename ::std::enable_if_t<
56  ::std::is_same<T, ::ros::Rate>::value ||
57  ::std::is_same<T, ::ros::WallRate>::value
58  >* = nullptr>
59 inline ::std::string to_string(const T& value)
60 {
61  ::std::stringstream ss;
62  ss << ::cras::frequency(value, true);
63  return ss.str();
64 }
65 
66 template<typename M, ::std::enable_if_t<::ros::message_traits::IsMessage<M>::value>* = nullptr>
67 inline std::string to_string(const M& msg)
68 {
69  ::std::stringstream ss;
70  ss << msg;
71  ::std::string s = ss.str();
72  if (!s.empty() && s[s.length() - 1] == '\n')
73  s.erase(s.length()-1);
74  ::cras::replace(s, "\n", ", ");
75  return s;
76 }
77 
92 template<typename D = ::ros::Duration, typename ::std::enable_if_t<
93  ::std::is_same<D, ::ros::Duration>::value ||
94  ::std::is_same<D, ::ros::WallDuration>::value
95  >* = nullptr>
96 D parseTimezoneOffset(const ::std::string& s);
97 
124 template<typename T = ::ros::Time, typename ::std::enable_if_t<
125  ::std::is_same<T, ::ros::Time>::value ||
126  ::std::is_same<T, ::ros::WallTime>::value ||
127  ::std::is_same<T, ::ros::SteadyTime>::value
128  >* = nullptr>
129 T parseTime(const ::std::string& s,
130  const ::cras::optional<typename ::cras::DurationType<T>::value>& timezoneOffset = {}, const T& referenceDate = {});
131 
150 template<typename D = ::ros::Duration, typename ::std::enable_if_t<
151  ::std::is_same<D, ::ros::Duration>::value ||
152  ::std::is_same<D, ::ros::WallDuration>::value
153  >* = nullptr>
154 D parseDuration(const ::std::string& s);
155 
156 }
msg
msg
cras
Definition: any.hpp:15
s
XmlRpcServer s
time.h
string_utils.hpp
Utils for working with strings.
cras::parseTimezoneOffset
D parseTimezoneOffset(const ::std::string &s)
Parse timezone offset from the given string.
cras::frequency
double frequency(const ::ros::Rate &rate, bool maxCycleTimeMeansZero=false)
Return the frequency represented by the given rate.
cras::parseTime
T parseTime(const ::std::string &s, const ::cras::optional< typename ::cras::DurationType< T >::value > &timezoneOffset={}, const T &referenceDate={})
Parse the given string as time.
duration.h
cras::parseDuration
D parseDuration(const ::std::string &s)
Parse the given string as duration.
message_traits.h
rate.h
cras::to_pretty_string
::std::string to_pretty_string(const T &value)
Convert the given time to a human-readable date-time representation according to ISO 8601.
ros::Time
time_utils.hpp
Utilities for working with time.
cras::to_string
inline ::std::string to_string(const ::Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols > &value)
Definition: string_utils/eigen.hpp:21
ros::Duration
cras::replace
::std::string replace(const ::std::string &str, const ::std::string &from, const ::std::string &to, const ::cras::ReplacePosition &where=::cras::ReplacePosition::EVERYWHERE)
Replace all occurrences of from in str with to.
optional.hpp
A C++11 shim for std::optional. Uses std::optional when used in C++17 mode.


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Tue Nov 26 2024 03:49:04