Public Member Functions | Static Protected Attributes | Private Member Functions

MessageImpl< id > Class Template Reference

Implementation of class Message. More...

#include <keyvalue/sys/message/MessageImpl.h>

Inheritance diagram for MessageImpl< id >:
Inheritance graph
[legend]

List of all members.

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 >
Messageoperator& (const DataType &data)
 Appends data to the end of message.

Static Protected Attributes

static const Traits_ traits_ []

Private Member Functions

Messageoperator= (const MessageImpl &orig)

Detailed Description

template<unsigned int id>
class keyvalue::MessageImpl< id >

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 typedefs for the following types of Messages:

Parameters:
id : (template parameter) Used to distinguish different specializations.

Constructor & Destructor Documentation

MessageImpl (  )  [inline]

ATTENTION: If you get a compiler error here about

'boostSTATIC_ASSERTION_FAILURE<x>'

this means that you have illegally construct an Info, Warning, Report, or Debug without providing its level.


Member Function Documentation

const string& getPrefix (  )  const [virtual]

Gets prefix associated this type of Message.

Returns:
The prefix.

Implements Message.

logger::Color getColor (  )  const [virtual]

Gets the color associated this type of Message.

Returns:
The prefix.

Implements Message.

unsigned int getLevel (  )  const [inherited]

Gets Message's level.

Returns:
The level.
string getString (  )  const [inherited]

Gets Message's text.

Returns:
The text.
Message & operator& ( const DataType &  data  )  [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];

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.

Parameters:
DataType : (template parameter) Type of data;
data : the data to be appended.