Implementation of class
Message.
More...
#include "keyvalue/sys/message/MessageImpl.h"
Public Member Functions | |
MessageImpl () | |
MessageImpl (unsigned int level) | |
const string & | getPrefix () const |
Gets prefix associated this type of Message. | |
logger::Color | getColor () const |
Gets the color associated this type of Message. | |
unsigned int | getLevel () const |
Gets Message's level. | |
string | getString () const |
Gets Message's text. | |
template<typename DataType > | |
Message & | operator& (const DataType &data) |
Appends data to the end of message. | |
Static Protected Attributes | |
static const Traits_ | traits_ [] |
Private Member Functions | |
Message & | operator= (const MessageImpl &orig) |
Implementation of class
Message.
This template class
provides default implementations for Message methods and extends its interface.
In this template class
, parameter unsigned int
id serves to distinguish specializations. Clients, rather than directly instantiate this template
by providing id, will use provided typedef
s for the following types of Messages:
id | : (template parameter) Used to distinguish different specializations. |
MessageImpl | ( | ) | [inline] |
const string& getPrefix | ( | ) | const [virtual] |
logger::Color getColor | ( | ) | const [virtual] |
unsigned int getLevel | ( | ) | const [inherited] |
Gets Message's level.
string getString | ( | ) | const [inherited] |
Gets Message's text.
Message & operator& | ( | const DataType & | data | ) | [inline, inherited] |
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] & '\n';
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 ExceptionImpl documentation). Indeed, there is an operator& whose rhs is an exception and it just redirect its calling to this operator& defined 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. |