-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More repr, fix infinite loop when calling repr on a lanele->regelem->…
…lanelet cycle (#383)
- Loading branch information
1 parent
d9320cf
commit 50239be
Showing
4 changed files
with
175 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
50239be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LCOV of commit [
50239be
] during Lanelet2 CI #246File coverage rate: