Demangle the type when printing
parent
a76c0a20ee
commit
95e7eea4b7
|
@ -31,6 +31,33 @@
|
|||
|
||||
namespace gtsam {
|
||||
|
||||
#ifdef __GNUG__
|
||||
#include <cstdlib>
|
||||
#include <cxxabi.h>
|
||||
#include <string>
|
||||
|
||||
/// Pretty print Value type name
|
||||
static std::string demangle(const char* name) {
|
||||
int status = -4; // some arbitrary value to eliminate the compiler warning
|
||||
// enable c++11 by passing the flag -std=c++11 to g++
|
||||
std::unique_ptr<char, void(*)(void*)> res {
|
||||
abi::__cxa_demangle(name, NULL, NULL, &status),
|
||||
std::free
|
||||
};
|
||||
return (status==0) ? res.get() : name ;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// does nothing if not g++
|
||||
static std::string demangle(const char* name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Wraps any type T so it can play as a Value
|
||||
*/
|
||||
|
@ -83,7 +110,7 @@ public:
|
|||
|
||||
/// Virtual print function, uses traits
|
||||
virtual void print(const std::string& str) const {
|
||||
std::cout << "(" << typeid(T).name() << ") ";
|
||||
std::cout << "(" << demangle(typeid(T).name()) << ") ";
|
||||
traits<T>::Print(value_, str);
|
||||
}
|
||||
|
||||
|
|
|
@ -235,7 +235,7 @@ namespace gtsam {
|
|||
if(message_.empty())
|
||||
message_ =
|
||||
"Attempting to retrieve value with key \"" + DefaultKeyFormatter(key_) + "\", type stored in Values is " +
|
||||
std::string(storedTypeId_.name()) + " but requested type was " + std::string(requestedTypeId_.name());
|
||||
std::string(demangle(storedTypeId_.name())) + " but requested type was " + std::string(demangle(requestedTypeId_.name()));
|
||||
return message_.c_str();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue