val_Value Class Reference
[Parser for config files; validation]

#include <val.h>

Inheritance diagram for val_Value:

Inheritance graph
[legend]
Collaboration diagram for val_Value:

Collaboration graph
[legend]

List of all members.


Detailed Description

Base class for all of the conversion (or rule) classes that convert any string to a basic type.

This kind of infrastructure ensures that types are checked at compile time as much as possible. Furthermore, it throws an exception at runtime if something unpredicted happens.

Basic principle of conversion:

  1. Bind rule class with target value of a basic type using Bind().
  2. Use conversion function Conv() to convert string to target value through rule.

Example:

    val_String  strrule("Name", cfg_Limit(0, 20)); // rule
    string      str;                               // target value

    strrule.Bind(str);          // bind rule to target
    strrule.Conv("ABCDEDEF");   // convert string to str through strrule
    

What Conv() does?

  1. Calls virtual function Validate(), which tests the input string vor validity. Validate() must return a string that will be converted. By default, Validate() just returns the string that was passed as input.

    If an implementation of Validate() detects invalid input to be converted, it must throw ivd_Error(ie_NOT_VALID).

  2. Calls virtual function Assign(), which does the actual conversion from a string to target value (whatever it is) and writes it to the target. Function is pure virtual and must be implemented by derived classes. Default Assign() in val_Value just throws ivd_Error.
  3. Calls virtual function CheckLimits(), that checks the converted value with the limits specified at construction.

Conv(low, high) calls only AssignRange(), which uses one of the basic converters to do the conversion of low and high values separately.

cfg_Value is just an interface to all conversion classes.

Templated class val_List is designed to convert a list-type input (e.g. PF_LIST) value to a vector of target values. It uses one of the basic converters to convert each of the input elements to new element in the vector.

Templated class val_Range is designed to convert a range (low, high) input (e.g. PF_RANGE) value to an instance of cfg_Element.

Author:
Matej Kenda, Hermes SoftLab
See also:
val_List

Definition at line 281 of file val.h.


Public Member Functions

 val_Value (const string &a_name, const val_Limit a_limits, const UInt64_t a_minNumOfVal=1, const UInt64_t a_maxNumOfVal=cfg_INFINITE)
 val_Value (const string &a_name, const val_Limit a_limits, const UInt64_t a_minNumOfVal, const UInt64_t a_maxNumOfVal, const string &a_defaultStr)
virtual ~val_Value ()
void Conv (const string &a_strVal)
void Conv (const string &a_strLow, const string &a_strHigh)
 This version of Conv() is used by templated class for ranges.
const string & GetName () const
const string & GetDefault () const
const val_Limit GetLimits () const
virtual void Add (const string &a_strVal)
virtual void AddRange (const string &a_strLow, const string &a_strHigh)

Public Attributes

UInt32_t m_numParsed
UInt64_t m_minNumOfVal
UInt64_t m_maxNumOfVal
string m_default
bool m_useDefault

Protected Member Functions

virtual string Validate (const string &a_strVal)
virtual void CheckLimits ()
virtual void AssignRange (const string &a_strLow, const string &a_strHigh)

Protected Attributes

string m_name
val_Limit m_limits

Private Attributes

 log_CLASSID_m

Constructor & Destructor Documentation

val_Value::val_Value ( const string &  a_name,
const val_Limit  a_limits,
const UInt64_t  a_minNumOfVal = 1,
const UInt64_t  a_maxNumOfVal = cfg_INFINITE 
)

Definition at line 137 of file val.cpp.

00142     : m_name(a_name),
00143       m_limits(a_limits),
00144       m_numParsed(0),
00145       m_minNumOfVal(a_minNumOfVal),
00146       m_maxNumOfVal(a_maxNumOfVal),
00147       m_default(""),
00148       m_useDefault(false) {
00149         // Empty
00150 }

val_Value::val_Value ( const string &  a_name,
const val_Limit  a_limits,
const UInt64_t  a_minNumOfVal,
const UInt64_t  a_maxNumOfVal,
const string &  a_defaultStr 
)

Definition at line 153 of file val.cpp.

00159     : m_name(a_name),
00160       m_limits(a_limits),
00161       m_numParsed(0),
00162       m_minNumOfVal(a_minNumOfVal),
00163       m_maxNumOfVal(a_maxNumOfVal),
00164       m_default(a_defaultStr),
00165       m_useDefault(true) {
00166         // Empty
00167 }

virtual val_Value::~val_Value (  )  [inline, virtual]

Definition at line 300 of file val.h.

00300                          {
00301         //Empty
00302     };


Member Function Documentation

void val_Value::Conv ( const string &  a_strVal  ) 

Definition at line 169 of file val.cpp.

References val_BasicValue::Assign(), CheckLimits(), and Validate().

Referenced by val_SlotList::Add(), val_List< val_FileNamePattern, string >::AddRange(), val_SlotList::AddRange(), val_Size::Assign(), val_Duration::Assign(), cfg_PMClient::cfg_PMClient(), cfg_PMFileExpiration::cfg_PMFileExpiration(), cfg_RMHost::cfg_RMHost(), cfg_Base::Convert(), ParseDiskMediumVolume(), and bea_DiskVolume::ReparseFiles().

00169                                            {
00170     string validated = Validate(a_strVal);
00171     Assign(validated);
00172     CheckLimits();
00173 }

Here is the call graph for this function:

Here is the caller graph for this function:

void val_Value::Conv ( const string &  a_strLow,
const string &  a_strHigh 
)

This version of Conv() is used by templated class for ranges.

Validate() and CheckLimits() are not called, because they are implicitely called by val_Range::Assign() (temporary converters for basic types do that).

Definition at line 180 of file val.cpp.

References AssignRange().

00180                                                                      {
00181     AssignRange(a_strLow, a_strHigh);
00182 }

Here is the call graph for this function:

const string& val_Value::GetName ( void   )  const [inline]

Definition at line 307 of file val.h.

Referenced by cfg_Base::Convert().

00307                                   {
00308         return m_name;
00309     };

Here is the caller graph for this function:

const string& val_Value::GetDefault (  )  const [inline]

Definition at line 310 of file val.h.

00310                                      {
00311         return m_default;
00312     };

const val_Limit val_Value::GetLimits (  )  const [inline]

Definition at line 313 of file val.h.

00313                                       {
00314         return m_limits;
00315     };

virtual void val_Value::Add ( const string &  a_strVal  )  [inline, virtual]

Implements val_ValueList.

Reimplemented in val_List< CNV, DT >, val_SlotList, val_List< val_StrictString, string >, and val_List< val_FileNamePattern, string >.

Definition at line 317 of file val.h.

References ie_PARSER_ERROR, and ivd_Error.

Referenced by cfg_Base::Convert().

00317                                              {
00318         throw ivd_Error(ie_PARSER_ERROR, "Undefined member function Add(str).");
00319     };

Here is the caller graph for this function:

virtual void val_Value::AddRange ( const string &  a_strLow,
const string &  a_strHigh 
) [inline, virtual]

Implements val_ValueList.

Reimplemented in val_List< CNV, DT >, val_SlotList, val_FileNamePatternList, val_List< val_StrictString, string >, and val_List< val_FileNamePattern, string >.

Definition at line 320 of file val.h.

References ie_PARSER_ERROR, and ivd_Error.

Referenced by cfg_Base::Convert().

00320                                                                            {
00321         throw ivd_Error(ie_PARSER_ERROR, "Undefined member function Add(str, str).");
00322     };

Here is the caller graph for this function:

virtual string val_Value::Validate ( const string &  a_strVal  )  [inline, protected, virtual]

Warning:
Validate() must return a string which is then used in Assign(). By default the argument is just returned.

Reimplemented in val_Path, val_Duration, val_Size, val_Percentage, val_ObjectName, val_Hostname, val_DbgLevel, val_DbgFlags, and val_FileNamePattern.

Definition at line 328 of file val.h.

Referenced by Conv().

00328                                                     {
00329         // No validation by default
00330         return a_strVal;
00331     };

Here is the caller graph for this function:

virtual void val_Value::CheckLimits (  )  [inline, protected, virtual]

Reimplemented in val_String, and val_Integer.

Definition at line 333 of file val.h.

Referenced by Conv().

00333                                {
00334         // Empty: No checking of limits by default
00335     };

Here is the caller graph for this function:

virtual void val_Value::AssignRange ( const string &  a_strLow,
const string &  a_strHigh 
) [inline, protected, virtual]

Implements val_RangeValue.

Reimplemented in val_Range< CNV, DT >.

Definition at line 337 of file val.h.

References ie_PARSER_ERROR, and ivd_Error.

Referenced by Conv().

00337                                                                               {
00338         throw ivd_Error(ie_PARSER_ERROR, "Undefined member function Assign(str, str).");
00339     };

Here is the caller graph for this function:


Member Data Documentation

string val_Value::m_name [protected]

Definition at line 345 of file val.h.

Referenced by cfg_Base::Convert().

Definition at line 346 of file val.h.

Definition at line 347 of file val.h.

Definition at line 348 of file val.h.

Definition at line 349 of file val.h.


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

Generated on Mon Feb 27 19:52:19 2012 for OPENARCHIVE by  doxygen 1.5.6