-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix infinite loop when running python repr on lanelets
- Loading branch information
1 parent
1d88ad2
commit 7afad88
Showing
3 changed files
with
156 additions
and
85 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 |
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
Oops, something went wrong.