Commit 9e0bec39 authored by Matthias Vallentin's avatar Matthias Vallentin

Make logger more flexible

New overloads let the logger stream any object which can stream via
operator<< into a std::stringstream.
parent a0b58f45
...@@ -87,6 +87,17 @@ public: ...@@ -87,6 +87,17 @@ public:
public: public:
line_builder(); line_builder();
template <class T>
line_builder& operator<<(const T& x) {
if (! str_.empty())
str_ += " ";
std::stringstream ss;
ss << x;
str_ += ss.str();
behind_arg_ = false;
return *this;
}
template <class T> template <class T>
line_builder& operator<<(const arg_wrapper<T>& x) { line_builder& operator<<(const arg_wrapper<T>& x) {
if (behind_arg_) if (behind_arg_)
...@@ -100,6 +111,8 @@ public: ...@@ -100,6 +111,8 @@ public:
return *this; return *this;
} }
line_builder& operator<<(const std::string& str);
line_builder& operator<<(const char* str); line_builder& operator<<(const char* str);
std::string get() const; std::string get() const;
......
...@@ -136,6 +136,14 @@ logger::line_builder::line_builder() : behind_arg_(false) { ...@@ -136,6 +136,14 @@ logger::line_builder::line_builder() : behind_arg_(false) {
// nop // nop
} }
logger::line_builder& logger::line_builder::operator<<(const std::string& str) {
if (! str_.empty())
str_ += " ";
str_ += str;
behind_arg_ = false;
return *this;
}
logger::line_builder& logger::line_builder::operator<<(const char* str) { logger::line_builder& logger::line_builder::operator<<(const char* str) {
if (! str_.empty()) if (! str_.empty())
str_ += " "; str_ += " ";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment