val_Size Class Reference
[Parser for config files; validation]

#include <val.h>

Inheritance diagram for val_Size:

Inheritance graph
[legend]
Collaboration diagram for val_Size:

Collaboration graph
[legend]

List of all members.


Detailed Description

Definition at line 609 of file val.h.


Public Member Functions

 val_Size (const string &a_name, const val_Limit a_limits, const UInt32_t a_minNumOfVal=1, const UInt64_t a_maxNumOfVal=cfg_INFINITE, const string &a_defaultStr="")
virtual ~val_Size ()
virtual string Validate (const string &a_strVal)
virtual void Assign (const string &a_strVal)

Private Attributes

UInt64_t m_multiplier
 log_CLASSID_m

Constructor & Destructor Documentation

val_Size::val_Size ( const string &  a_name,
const val_Limit  a_limits,
const UInt32_t  a_minNumOfVal = 1,
const UInt64_t  a_maxNumOfVal = cfg_INFINITE,
const string &  a_defaultStr = "" 
)

Definition at line 724 of file val.cpp.

00730   : val_Integer(a_name, a_limits, a_minNumOfVal, a_maxNumOfVal,  a_defaultStr ) {
00731     // Empty
00732 }

val_Size::~val_Size (  )  [virtual]

Definition at line 736 of file val.cpp.

00736                     {
00737     //Empty
00738 }


Member Function Documentation

string val_Size::Validate ( const string &  a_strVal  )  [virtual]

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

Reimplemented from val_Value.

Definition at line 740 of file val.cpp.

References cfg_GIGABYTE, cfg_KILOBYTE, cfg_MEGABYTE, cfg_TERABYTE, dbg_DETAIL, ie_NOT_VALID, ivd_Error, log_DBG_m, log_FUNC_A_m, m_multiplier, val_Value::m_name, and strcasecmp.

00740                                                 {
00741 
00742     if (a_strVal.length() < 2) {
00743         ostringstream sstr;
00744         sstr
00745             << "Invalid size format. String too short. Value: " << a_strVal
00746             << " at variable: " + m_name;
00747 
00748         throw ivd_Error(ie_NOT_VALID, sstr.str());
00749     };
00750 
00751     log_FUNC_A_m(Validate , "a_strVal:" << a_strVal);
00752     log_DBG_m(dbg_DETAIL,"");
00753 
00754     string::size_type unitPos = a_strVal.length() - 2;
00755     log_DBG_m(dbg_DETAIL,"a_strVal.length():" << a_strVal.length() <<
00756                             " unitPos:" << unitPos);
00757 
00758     string unit = a_strVal.substr(unitPos, 2);
00759     log_DBG_m(dbg_DETAIL,"unit:" << unit);
00760 
00761     string num;
00762 
00763     if ( strcasecmp(unit.c_str(),  "KB") == 0) {
00764         m_multiplier = cfg_KILOBYTE;
00765         num = a_strVal.substr(0, a_strVal.length()-2);
00766     }
00767     else if ( strcasecmp(unit.c_str(), "MB") == 0 ) {
00768         m_multiplier = cfg_MEGABYTE;
00769         num = a_strVal.substr(0, a_strVal.length()-2);
00770     }
00771     else if (strcasecmp(unit.c_str(), "GB") == 0) {
00772         m_multiplier = cfg_GIGABYTE;
00773         num = a_strVal.substr(0, a_strVal.length()-2);
00774     }
00775     else if (strcasecmp(unit.c_str(), "TB") == 0) {
00776         m_multiplier = cfg_TERABYTE;
00777         num = a_strVal.substr(0, a_strVal.length()-2);
00778     }
00779     else if ( (unit[1] == 'B') || (unit[1] == 'b') ) {
00780         m_multiplier = 1;
00781         num = a_strVal.substr(0, a_strVal.length()-1);
00782     }
00783     else {
00784         ostringstream sstr;
00785         sstr
00786             << "Invalid size format. Expected B, KB, MB, GB or TB. "
00787             << "Value: " << a_strVal << " at variable: " << m_name;
00788 
00789         throw ivd_Error(ie_NOT_VALID, sstr.str());
00790     }
00791     return num;
00792 }

void val_Size::Assign ( const string &  a_strVal  )  [virtual]

Reimplemented from val_Integer.

Definition at line 794 of file val.cpp.

References val_Integer::Assign(), val_Integer::Bind(), cmn_Num2Str(), val_Value::Conv(), LLONG_MAX, m_multiplier, and val_Value::m_name.

00794                                             {
00795     // Make temporary conversion to get the numeric value from
00796     // the string a_strVal.
00797     Int64_t tmp(0);
00798     {
00799         val_Integer vi(m_name, val_Limit(-LLONG_MAX, LLONG_MAX));
00800         vi.Bind(tmp);
00801         vi.Conv(a_strVal);
00802     }
00803     tmp *= m_multiplier;
00804 
00805     // Do final conversion and limit checks.
00806     val_Integer::Assign(cmn_Num2Str(tmp));
00807 }

Here is the call graph for this function:


Member Data Documentation

Definition at line 625 of file val.h.

Referenced by Assign(), and Validate().

Reimplemented from val_Integer.

Definition at line 627 of file val.h.


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

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