string_utils/ros.hpp
Go to the documentation of this file.
1 #pragma once
2 
11 #include <sstream>
12 #include <string>
13 #include <type_traits>
14 
15 #include <ros/duration.h>
16 #include <ros/rate.h>
17 #include <ros/time.h>
18 #include <ros/message_traits.h>
19 
21 
22 namespace cras
23 {
24 
25 template<typename T, typename ::std::enable_if_t<
26  ::std::is_same<T, ::ros::Time>::value ||
27  ::std::is_same<T, ::ros::WallTime>::value ||
28  ::std::is_same<T, ::ros::SteadyTime>::value ||
29  ::std::is_same<T, ::ros::Duration>::value ||
30  ::std::is_same<T, ::ros::WallDuration>::value
31  >* = nullptr>
32 inline ::std::string to_string(const T& value)
33 {
34  ::std::stringstream ss;
35  ss << value;
36  return ss.str();
37 }
38 
39 template<typename T, typename ::std::enable_if_t<
40  ::std::is_same<T, ::ros::Rate>::value ||
41  ::std::is_same<T, ::ros::WallRate>::value
42  >* = nullptr>
43 inline ::std::string to_string(const T& value)
44 {
45  ::std::stringstream ss;
46  ss << ::cras::frequency(value, true);
47  return ss.str();
48 }
49 
50 template<typename M, ::std::enable_if_t<::ros::message_traits::IsMessage<M>::value>* = nullptr>
51 inline std::string to_string(const M& msg)
52 {
53  ::std::stringstream ss;
54  ss << msg;
55  ::std::string s = ss.str();
56  if (!s.empty() && s[s.length() - 1] == '\n')
57  s.erase(s.length()-1);
58  ::cras::replace(s, "\n", ", ");
59  return s;
60 }
61 
62 }
msg
msg
cras
Definition: any.hpp:15
s
XmlRpcServer s
time.h
cras::frequency
double frequency(const ::ros::Rate &rate, bool maxCycleTimeMeansZero=false)
Return the frequency represented by the given rate.
duration.h
message_traits.h
rate.h
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
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.


cras_cpp_common
Author(s): Martin Pecka
autogenerated on Sun Jan 14 2024 03:48:14