Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes

val_Value Class Reference
[Parser for config files; validation]

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

#include <val.h>

Inheritance diagram for val_Value:
Inheritance graph
[legend]
Collaboration diagram for val_Value:
Collaboration graph
[legend]

List of all members.

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

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 295 of file val.h.


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 151 of file val.cpp.

    : m_name(a_name),
      m_limits(a_limits),
      m_numParsed(0),
      m_minNumOfVal(a_minNumOfVal),
      m_maxNumOfVal(a_maxNumOfVal),
      m_default(""),
      m_useDefault(false) {
        // Empty
}

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 167 of file val.cpp.

    : m_name(a_name),
      m_limits(a_limits),
      m_numParsed(0),
      m_minNumOfVal(a_minNumOfVal),
      m_maxNumOfVal(a_maxNumOfVal),
      m_default(a_defaultStr),
      m_useDefault(true) {
        // Empty
}

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

Definition at line 314 of file val.h.

                         {
        //Empty
    };


Member Function Documentation

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

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

Definition at line 331 of file val.h.

References ie_PARSER_ERROR, and ivd_Error.

Referenced by cfg_Base::Convert().

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

Here is the caller graph for this function:

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

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

Definition at line 334 of file val.h.

References ie_PARSER_ERROR, and ivd_Error.

Referenced by cfg_Base::Convert().

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

Here is the caller graph for this function:

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

Reimplemented in val_Range< CNV, DT >.

Definition at line 351 of file val.h.

References ie_PARSER_ERROR, and ivd_Error.

Referenced by Conv().

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

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 347 of file val.h.

Referenced by Conv().

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

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 194 of file val.cpp.

References AssignRange().

                                                                     {
    AssignRange(a_strLow, a_strHigh);
}

Here is the call graph for this function:

void val_Value::Conv ( const string &  a_strVal  ) 
const string& val_Value::GetDefault (  )  const [inline]

Definition at line 324 of file val.h.

                                     {
        return m_default;
    };

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

Definition at line 327 of file val.h.

                                      {
        return m_limits;
    };

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

Definition at line 321 of file val.h.

Referenced by cfg_Base::Convert().

                                  {
        return m_name;
    };

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 342 of file val.h.

Referenced by Conv().

                                                    {
        // No validation by default
        return a_strVal;
    };

Here is the caller graph for this function:


Member Data Documentation

Definition at line 362 of file val.h.

Definition at line 361 of file val.h.

Definition at line 360 of file val.h.

string val_Value::m_name [protected]

Definition at line 359 of file val.h.

Referenced by cfg_Base::Convert().

Definition at line 363 of file val.h.


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