Abstract class
which defines the interface for all types of message.
More...
#include <keyvalue/sys/message/Message.h>
Public Member Functions | |
unsigned int | getLevel () const |
Gets Message's level. | |
string | getString () const |
Gets Message's text. | |
virtual const string & | getPrefix () const =0 |
Gets Message's prefix. | |
virtual logger::Color | getColor () const =0 |
Gets Message's color. | |
template<typename DataType > | |
Message & | operator& (const DataType &data) |
Appends data to the end of message. | |
Protected Member Functions | |
Message (unsigned int level) | |
Constructs a Message with a given level. | |
Message (const Message &orig) | |
Static Protected Attributes | |
static const Traits_ | traits_ [] |
Private Member Functions | |
Message & | operator= (const Message &orig) |
Private Attributes | |
unsigned int | level_ |
std::ostringstream | buf_ |
Abstract class
which defines the interface for all types of message.
Each Message has a level that defines if it will be ignored or not by the Logger which receives it. (For more details, see Logger documentation).
Message | ( | unsigned int | level | ) | [explicit, protected] |
unsigned int getLevel | ( | ) | const |
Gets Message's level.
string getString | ( | ) | const |
Gets Message's text.
virtual const string& getPrefix | ( | ) | const [pure virtual] |
virtual logger::Color getColor | ( | ) | const [pure virtual] |
Message & operator& | ( | const DataType & | data | ) |
Appends data to the end of message.
This template
method makes use of std::ostream::operator<<()
to append data to this Message. Hence, the type of data DataType must be such that std::ostream::operator<<(ostream&, const DataType&)
is well defined.
A typical use of this method is
Info info(1); // Info is derived from Message size_t i; std::vector<double> x; // ... info & "x[" & i & "] = " & x[i];
Warning: For some reason, one cannot append std::endl
to Message, despite the fact that a standard ostream
can accept it!
Remark: It would be more natural using operator<< rather than operator&. However, the main use of operator& is related to exceptions (see exception::ExceptionImpl documentation). Indeed, there exist ExceptionImpl::operator&() which just redirects its call to this operator& here. In the past, KeyValue exceptions were derived from boost::exception which defines operator<< for other purposes. Therefore, operator& was prefered rather than operator<< to avoid conflict with boost. Be aware that, in the near future, if it is proven convenient, one might change operator& to operator<< again.
DataType | : (template parameter) Type of data; | |
data | : the data to be appended. |