lestes::msg::message_stencil Class Reference

Message stencil base. More...

#include <message_stencil.hh>

Inheritance diagram for lestes::msg::message_stencil:

lestes::std::object lestes::std::mem::keystone lestes::msg::message_stencil0< T > lestes::msg::message_stencil1< P0 > lestes::msg::message_stencil2< P0, P1 > lestes::msg::message_stencil3< P0, P1, P2 > List of all members.

Public Member Functions

ulint nparams_get (void) const
 Returns the number of parameters.
ulint kind_get (void) const
 Returns the unique kind identification.
bool equals (const ptr< message_stencil > &other) const
 Tests equality.

Protected Types

typedef message::flags_type flags_type
 Type of message flags.
typedef ::lestes::std::vector<
lstring > 
args_type
 Type of argument list.

Protected Member Functions

 message_stencil (ulint a_nparams, const lstring &a_format, flags_type a_flags)
 Creates the message stencil.
ptr< messagegenerate (const ptr< args_type > &args) const
 Returns a formatted message.
void gc_mark (void)
 Marks the object.

Private Types

typedef ::lestes::std::vector<
lstring > 
texts_type
 Type of storage for message texts.
typedef ::lestes::std::vector<
ulint > 
params_type
 Type of storage for parameters.

Private Member Functions

void parse (const lstring &a_format)
 Parses the format string.
 message_stencil (const message_stencil &)
 Hides copy constructor.
message_stenciloperator= (const message_stencil &)
 Hides assignment operator.

Private Attributes

ulint nparams
 Number of parameters.
ulint kind
 The unique identification of message kind.
flags_type flags
 Message flags.
srp< texts_typetexts
 The parsed texts.
srp< params_typeparams
 The parsed parameters.

Static Private Attributes

static ulint kind_counter = 0
 The internal counter to distinguish instances.

Detailed Description

Message stencil base.

Represents base class parametrised stencil for creating formatted messages. Each instance of stencil represents one unique message family (generating the same kind of messages). Each instance is assigned an unique identification number to help expressing sets of message kinds efficiently, for example via bit vectors. It is however, not assured, that one object will get the same id each time.

The format text recognizes parameter reference in the form D where D is a decimal digit. The parameter numbering starts with 0 and only valid indexes are accepted. The reference to a single parameter can appear zero or more times, in no particular order. To express a single %, %% is used. Any other character after % is not allowed and neither is end of string.

Example: "Value %0 is invalid in %3, %0 is out of range %1 - %2 allowed for %3"

Implementation details: The parsed format text is stored as a sequence of parameter indexes with a special value (equal to the number of parameters) designating use of next part of text, stored in another sequence.

Definition at line 66 of file message_stencil.hh.


Member Typedef Documentation

typedef message::flags_type lestes::msg::message_stencil::flags_type [protected]

Type of message flags.

Definition at line 76 of file message_stencil.hh.

typedef ::lestes::std::vector<lstring> lestes::msg::message_stencil::args_type [protected]

Type of argument list.

Definition at line 78 of file message_stencil.hh.

typedef ::lestes::std::vector<lstring> lestes::msg::message_stencil::texts_type [private]

Type of storage for message texts.

Definition at line 87 of file message_stencil.hh.

typedef ::lestes::std::vector<ulint> lestes::msg::message_stencil::params_type [private]

Type of storage for parameters.

Definition at line 89 of file message_stencil.hh.


Constructor & Destructor Documentation

lestes::msg::message_stencil::message_stencil ( ulint  a_nparams,
const lstring &  a_format,
flags_type  a_flags 
) [protected]

Creates the message stencil.

Creates the stencil, initializes with number of expected parameters and values to fill into the message. Assigns a unique id number, starting from zero.

Precondition:
The format string is well-formed.
Parameters:
a_nparams Number of parameters for the stencil.
a_format The format for the message, with % designating indexed parameter slots.
a_flags The flags for the message.

Definition at line 48 of file message_stencil.cc.

References parse().

00048                                                                                             :
00049         nparams(a_nparams),
00050         kind(kind_counter++),
00051         flags(a_flags),
00052         texts(texts_type::create()),
00053         params(params_type::create())
00054 {
00055         // attempt to fill internal structures for faster message creation
00056         parse(a_format);
00057 }

lestes::msg::message_stencil::message_stencil ( const message_stencil  )  [private]

Hides copy constructor.


Member Function Documentation

ulint lestes::msg::message_stencil::nparams_get ( void   )  const

Returns the number of parameters.

Returns the number of parameters for the message.

Returns:
The number of parameters.

Definition at line 63 of file message_stencil.cc.

References nparams.

00064 {
00065         return nparams;
00066 }

ulint lestes::msg::message_stencil::kind_get ( void   )  const

Returns the unique kind identification.

Returns the assigned unique identification number. The number is only for internal use and may vary between compilations.

Returns:
The kind identification number.

Definition at line 73 of file message_stencil.cc.

References kind.

00074 {
00075         return kind;
00076 }

bool lestes::msg::message_stencil::equals ( const ptr< message_stencil > &  other  )  const

Tests equality.

Tests equality to other stencil. Each stencil object represents one message kind and is thus unique.

Parameters:
other The stencil to compare to.
Returns:
true If both stencils point to the same object.

Definition at line 84 of file message_stencil.cc.

00085 {
00086         return other && other == this;
00087 }

ptr< message > lestes::msg::message_stencil::generate ( const ptr< args_type > &  args  )  const [protected]

Returns a formatted message.

Returns message with arguments filled into the parameter slots.

Precondition:
args != NULL

args->size() == nparams_get()

Parameters:
args The arguments for the message.

Definition at line 148 of file message_stencil.cc.

References lestes::msg::message::create(), flags, kind, lassert, nparams, params, and texts.

Referenced by lestes::msg::message_stencil3< P0, P1, P2 >::format(), lestes::msg::message_stencil2< P0, P1 >::format(), lestes::msg::message_stencil1< P0 >::format(), and lestes::msg::message_stencil0< T >::format().

00149 {
00150         lassert(args);
00151         lassert(args->size() == nparams);
00152         
00153         lstring result;
00154         
00155         texts_type::iterator tit = texts->begin();
00156         texts_type::iterator tend = texts->end();
00157         
00158         for (params_type::iterator it = params->begin(), end = params->end(); it != end; ++it) {
00159                 ulint idx = *it;
00160                 if (idx == nparams) {
00161                         lassert(tit != tend);
00162                         result += *tit;
00163                         ++tit;
00164                 } else {
00165                         lassert(idx < nparams);
00166                         // operator[] does no range check
00167                         result += args->operator[](idx);
00168                 }
00169         }
00170 
00171         // pass all stored info
00172         return message::create(kind,result,flags);
00173 }

void lestes::msg::message_stencil::gc_mark ( void   )  [protected, virtual]

Marks the object.

Marks the object for garbage collection.

Reimplemented from lestes::std::mem::keystone.

Reimplemented in lestes::msg::message_stencil0< T >, lestes::msg::message_stencil1< P0 >, lestes::msg::message_stencil2< P0, P1 >, and lestes::msg::message_stencil3< P0, P1, P2 >.

Definition at line 178 of file message_stencil.cc.

References params, and texts.

Referenced by lestes::msg::message_stencil3< P0, P1, P2 >::gc_mark(), lestes::msg::message_stencil2< P0, P1 >::gc_mark(), lestes::msg::message_stencil1< P0 >::gc_mark(), and lestes::msg::message_stencil0< T >::gc_mark().

00179 {
00180         texts.gc_mark();
00181         params.gc_mark();
00182         object::gc_mark();
00183 }

void lestes::msg::message_stencil::parse ( const lstring &  a_format  )  [private]

Parses the format string.

Parses the format text.

Precondition:
The text is well-formed according to the class documentation.
Parameters:
text The text to parse.

Definition at line 94 of file message_stencil.cc.

References lassert2, nparams, params, texts, and u.

Referenced by message_stencil().

00095 {
00096         bool percent = false;
00097         // start of not yet stored part
00098         ulint start = 0;
00099         lstring out;
00100         
00101         for (ulint i = 0, len = a_format.length(); i < len; i++) {
00102                 char c = a_format[i];
00103                 if (percent) {
00104                         // add the part of a_format before the % sequence
00105                         out += a_format.substr(start,i - start - 1);
00106                         if (c == '%') {
00107                                 out += '%';
00108                         } else {
00109                                 ucn u = character::create_from_host(c);
00110                         
00111                                 lassert2(character::is_digit(u),"Invalid `%' sequence.");
00112                                 ulint x = character::extract_digit(u);
00113                                 lassert2(x < nparams,"Invalid parameter in `%' sequence.");
00114                                 
00115                                 if (out.length()) {
00116                                         // flush the a_format before the parameter
00117                                         texts->push_back(out);
00118                                         out = "";
00119                                         // signal a_format output
00120                                         params->push_back(nparams);
00121                                 }
00122                                 params->push_back(x);
00123                         }
00124                         start = i + 1;
00125                         percent = false;
00126                 } else {
00127                         percent = (c == '%');
00128                 }
00129         }
00130 
00131         lassert2(!percent,"Unterminated `%' sequence.");
00132 
00133         out += a_format.substr(start);
00134         if (out.length()) {
00135                 // flush the last a_format
00136                 texts->push_back(out);
00137                 // signal a_format output
00138                 params->push_back(nparams);
00139         }
00140 }

message_stencil& lestes::msg::message_stencil::operator= ( const message_stencil  )  [private]

Hides assignment operator.


Member Data Documentation

ulint lestes::msg::message_stencil::nparams [private]

Number of parameters.

Definition at line 93 of file message_stencil.hh.

Referenced by generate(), nparams_get(), and parse().

ulint lestes::msg::message_stencil::kind [private]

The unique identification of message kind.

Definition at line 95 of file message_stencil.hh.

Referenced by generate(), and kind_get().

flags_type lestes::msg::message_stencil::flags [private]

Message flags.

Definition at line 97 of file message_stencil.hh.

Referenced by generate().

srp<texts_type> lestes::msg::message_stencil::texts [private]

The parsed texts.

Definition at line 99 of file message_stencil.hh.

Referenced by gc_mark(), generate(), and parse().

srp<params_type> lestes::msg::message_stencil::params [private]

The parsed parameters.

Definition at line 101 of file message_stencil.hh.

Referenced by gc_mark(), generate(), and parse().

ulint lestes::msg::message_stencil::kind_counter = 0 [static, private]

The internal counter to distinguish instances.

Internal message stencil instance identification number counter.

Definition at line 107 of file message_stencil.hh.


The documentation for this class was generated from the following files:
Generated on Mon Feb 12 18:25:54 2007 for lestes by doxygen 1.5.1-20070107