CVR-Lib last update 20 Sep 2009

cvr::status::status::statusObject Class Reference

Class for status string storing and formatting. More...

#include <cvrStatus.h>

Collaboration diagram for cvr::status::status::statusObject:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 statusObject ()
 statusObject (const statusObject &other)
 ~statusObject ()
statusObjectcopy (const statusObject &other)
statusObjectoperator= (const statusObject &other)
void set (const std::string &className, const std::string &str)
void set (const std::string &className, const char *str)
const std::string & get () const
statusObjectoperator% (const int data)
statusObjectoperator% (const double data)
statusObjectoperator% (const std::string &data)
statusObjectoperator% (const char *data)

Static Public Member Functions

static void setStatusMonitor (statusMonitor &monitor)


Detailed Description

Class for status string storing and formatting.

The status::statusObject is an abstraction that allows a flexible formatting of the status strings and a way of knowing that the string has been completed.

When you have a class that inherits from cvs::status the methods of that at class can report errors simply by calling

 setStatusString("Invalid arguments detected.");

That method returns an instance of a status::statusObject, which allows appending additional information, but only if the string set through setStatusString has the special tokens %1 to %9. These tokens are then replaced by some information you provide through the operator%.

For instance:

 int val = 5;
 std::string str = "hello";
 setStatusString("Val=%1 and the string str=%2")%val%str;
would produce the status string "Val=5 and the string str=hello".

If you wish to delay providing the parameters you can do:

 int val = 5;
 std::string str = "
 setStatusString("Val val=%1 and the string str=%2");
 getStatusObject()%val;
 getStatusObject()%str;

This is an internal class to encapsulate the operator%. Outside this object, the operator% means modulus, but in the context of error reports it can have its own meaning. If fact, the use of operator% for this task is is inspired (remotely) on one of the boost libraries.


Constructor & Destructor Documentation

cvr::status::status::statusObject::statusObject (  ) 

Constructor.

cvr::status::status::statusObject::statusObject ( const statusObject other  ) 

Copy constructor.

cvr::status::status::statusObject::~statusObject (  ) 

Destructor.


Member Function Documentation

statusObject& cvr::status::status::statusObject::copy ( const statusObject other  ) 

Copy another statusObject instance.

const std::string& cvr::status::status::statusObject::get (  )  const

Get the current status string.

statusObject& cvr::status::status::statusObject::operator% ( const char *  data  ) 

Fill a const char chain.

statusObject& cvr::status::status::statusObject::operator% ( const std::string &  data  ) 

Fill a std::string argument.

statusObject& cvr::status::status::statusObject::operator% ( const double  data  ) 

Fill a double argument.

statusObject& cvr::status::status::statusObject::operator% ( const int  data  ) 

Fill an integer argument.

statusObject& cvr::status::status::statusObject::operator= ( const statusObject other  ) 

Copy another statusObject instance (alias for copy()).

void cvr::status::status::statusObject::set ( const std::string &  className,
const char *  str 
)

Set and parse the status string.

void cvr::status::status::statusObject::set ( const std::string &  className,
const std::string &  str 
)

Set and parse the status string.

static void cvr::status::status::statusObject::setStatusMonitor ( statusMonitor monitor  )  [static]

Set Status Monitor.

All functors in the CVR-Lib share this object, which controls what to do when the status string is set or changed. You can set it to throw an exception (see cvr::statusMonitorException), you can redirect the statusString directly to the std::cerr; see cvr::statusMonitorCerr), or you can do nothing but store internally the statusString (see cvr::statusMonitorInactive), which is the default behaviour.

If you implement an own class for this (like and error-log window) ensure that you follow the interface explained in cvr::statusMonitor to avoid memory leaks.

You have to ensure that this method is called only once at a time in your application, especially if you use several threads.


The documentation for this class was generated from the following file:

Generated on Sun Sep 20 22:08:40 2009 for CVR-Lib by Doxygen 1.5.8