 |
Belle II Software
release-05-02-19
|
17 #include <type_traits>
18 #include <boost/lexical_cast.hpp>
32 template<
class TVarType>
33 LogVar(
const std::string& name,
const TVarType& v) :
35 m_value(boost::lexical_cast<std::string>(v))
91 typedef std::basic_ostream<std::stringstream::char_type, std::stringstream::traits_type >
__basic_ostream_type;
113 explicit LogVariableStream(std::string
const& text, std::map<std::string, std::string> variables = {})
116 for (
auto const& kv : variables) {
147 template<
class TText>
159 template<
class PODTYPE>
189 std::string
str(
bool showVariables =
true)
const
197 std::stringstream tmpBuffer;
201 tmpBuffer << std::endl <<
"\t" << v.getName() <<
" = " << v.getValue();
203 return tmpBuffer.str();
std::string getMessage() const
Return the constant message part without the variables.
std::stringstream m_stringStream
All non-LogVar items are directly forwarded to this stringstream.
Specialized implementation of an ostream-like class where the << operator can be used to insert value...
LogVariableStream & operator<<(__basic_ostream_type &(*__pf)(__basic_ostream_type &))
operator override for ostream modifier functions like std::endl who are directly applied to the under...
std::string getValue() const
Returns the value stored for this variable.
LogVariableStream(const LogVariableStream &other)
Implement custom copy-constructor, because stringstream's one is deleted.
bool operator==(const LogVariableStream &lvs) const
Custom comparison operator.
LogVariableStream(std::string const &text, std::map< std::string, std::string > variables={})
Constructor which sets an initial text for this stream.
std::enable_if< std::is_fundamental< PODTYPE >::value, LogVariableStream & >::type operator<<(PODTYPE pod)
Templated operator which will be used for POD types (especially integers) and uses by-value.
std::string str(bool showVariables=true) const
Return the content of the stream as string.
std::string getName() const
Returns the name stored for this variable.
LogVariableStream & operator=(const LogVariableStream &lvs)
Custom assignment-operator, thanks to stringsream's non-copy policy.
bool operator==(const LogVar &lv) const
Custom comparison operator.
std::string m_value
String conversion of the value.
const std::vector< LogVar > & getVariables() const
Return the list of all defined variables.
Class to store variables with their name which were sent to the logging service.
LogVariableStream()=default
Default constructor with empty text and no variables.
std::vector< LogVar > m_variables
List of LogVars which were accepted so far.
std::basic_ostream< std::stringstream::char_type, std::stringstream::traits_type > __basic_ostream_type
basic_ofstream which is used with ostream's utility functions
std::string m_name
Stores the name of the variable.
std::enable_if< not std::is_fundamental< TText >::value, LogVariableStream & >::type operator<<(TText const &text)
Templated operator which will be used for all non-fundamental types.
LogVar(const std::string &name, const TVarType &v)
Constructor which accepts any type as value and relies on boost lexical cast.
LogVariableStream & operator<<(LogVar const &var)
Operator override which stores the LogVar information instead of putting it directly in the sstream.