repr.h
Go to the documentation of this file.
1 #pragma once
2 #include <boost/python.hpp>
3 #include <sstream>
4 #include <string>
5 
6 namespace lanelet {
7 namespace python {
8 inline void formatHelper(std::ostream& os) {}
9 
10 template <typename... Args>
11 // NOLINTNEXTLINE(readability-identifier-naming)
12 void formatHelper(std::ostream& os, const std::string& s, const Args&... Args_) {
13  if (!s.empty()) {
14  os << ", ";
15  }
16  os << s;
17  formatHelper(os, Args_...);
18 }
19 
20 template <typename T, typename... Args>
21 // NOLINTNEXTLINE(readability-identifier-naming)
22 void formatHelper(std::ostream& os, const T& next, const Args&... Args_) {
23  os << ", ";
24  os << next;
25  formatHelper(os, Args_...);
26 }
27 
28 template <typename T, typename... Args>
29 // NOLINTNEXTLINE(readability-identifier-naming)
30 void format(std::ostream& os, const T& first, const Args&... Args_) {
31  os << first;
32  formatHelper(os, Args_...);
33 }
34 
35 template <typename... Args>
36 // NOLINTNEXTLINE(readability-identifier-naming)
37 std::string makeRepr(const char* name, const Args&... Args_) {
38  std::ostringstream os;
39  os << name << '(';
40  format(os, Args_...);
41  os << ')';
42  return os.str();
43 }
44 
45 inline std::string repr(const boost::python::object& o) {
46  using namespace boost::python;
47  object repr = import("builtins").attr("repr");
48  return call<std::string>(repr.ptr(), o);
49 }
50 } // namespace python
51 } // namespace lanelet
lanelet::python::format
void format(std::ostream &os, const T &first, const Args &... Args_)
Definition: repr.h:30
lanelet
next
Optional< ConstLaneletOrArea > next
lanelet::python::formatHelper
void formatHelper(std::ostream &os)
Definition: repr.h:8
lanelet::python::repr
std::string repr(const boost::python::object &o)
Definition: repr.h:45
lanelet::python::makeRepr
std::string makeRepr(const char *name, const Args &... Args_)
Definition: repr.h:37


lanelet2_python
Author(s): Fabian Poggenhans
autogenerated on Thu Mar 6 2025 03:26:14