If have a ton of user defined types which implement operator<<
to write to an std::ostream
. How can I uses these when logging my types with Pantheios?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
You need to provide "shims" for your own data types. Here's what seems to be the documentation on how to do this: http://www.pantheios.org/tutorials_code.html#types_without_shims. Example:
In this case, the type can be passed directly to the log statement:
Good luck!
Well there is a way you can reuse the
operator<<
but it ain't pretty. I personally use the boost::lexical_cast library to convert almost any data-type to the std::string data type, which Pantheios supports natively. So if you have theoperator<<
defined for thepoint
class then you could simply type:pantheios::log_ERROR("Point: ", boost::lexical_cast<string>(point_object))
There are some caveats with this of course. Many people complain that boost::lexical_cast is slow. You can Google it and find some articles that speak of same (http://stackoverflow.com/questions/1250795/very-poor-boostlexical-cast-performance, http://accu.org/index.php/journals/1375). Considering that Pantheios boasts superior performance, you may lose some of that advantage. And the most obvious, you could add a few hundred header files to your project when you add boost::lexical_cast. You also have to type in more letters (e.g. boost::lexical_cast) for each conversion (you could minimize this with a macro -
#define BLCS boost::lexical_cast<string>
- but thats more indirection than some people may be comfortable with).