Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More repr, fix infinite loop when calling repr on a lanele->regelem->lanelet cycle #383

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions lanelet2_python/include/lanelet2_python/internal/repr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once
#include <boost/python.hpp>
#include <sstream>
#include <string>

namespace lanelet {
namespace python {
inline void formatHelper(std::ostream& os) {}

template <typename... Args>
// NOLINTNEXTLINE(readability-identifier-naming)
void formatHelper(std::ostream& os, const std::string& s, const Args&... Args_) {
if (!s.empty()) {
os << ", ";
}
os << s;
formatHelper(os, Args_...);
}

template <typename T, typename... Args>
// NOLINTNEXTLINE(readability-identifier-naming)
void formatHelper(std::ostream& os, const T& next, const Args&... Args_) {
os << ", ";
os << next;
formatHelper(os, Args_...);
}

template <typename T, typename... Args>
// NOLINTNEXTLINE(readability-identifier-naming)
void format(std::ostream& os, const T& first, const Args&... Args_) {
os << first;
formatHelper(os, Args_...);
}

template <typename... Args>
// NOLINTNEXTLINE(readability-identifier-naming)
std::string makeRepr(const char* name, const Args&... Args_) {
std::ostringstream os;
os << name << '(';
format(os, Args_...);
os << ')';
return os.str();
}

inline std::string repr(const boost::python::object& o) {
using namespace boost::python;
object repr = import("builtins").attr("repr");
return call<std::string>(repr.ptr(), o);
}
} // namespace python
} // namespace lanelet
Loading
Loading