val_Duration Class Reference
[Parser for config files; validation]

#include <val.h>

Inheritance diagram for val_Duration:

Inheritance graph
[legend]
Collaboration diagram for val_Duration:

Collaboration graph
[legend]

List of all members.


Detailed Description

Definition at line 567 of file val.h.


Public Member Functions

 val_Duration (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_Duration ()
virtual void Bind (UInt32_t &a_duration)
virtual string Validate (const string &a_strVal)
virtual void Assign (const string &a_strVal)

Private Attributes

UInt32_tm_dur_p
UInt64_t m_multiplier
 log_CLASSID_m

Constructor & Destructor Documentation

val_Duration::val_Duration ( 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 574 of file val.cpp.

00580   : val_Value(a_name, a_limits, a_minNumOfVal, a_maxNumOfVal, a_defaultStr ),
00581     m_dur_p(NULL) {
00582     // Empty
00583 }

val_Duration::~val_Duration (  )  [virtual]

Definition at line 586 of file val.cpp.

00586                             {
00587     //Empty
00588 }


Member Function Documentation

void val_Duration::Bind ( UInt32_t a_duration  )  [virtual]

Reimplemented from val_BasicValue.

Definition at line 590 of file val.cpp.

References m_dur_p.

Referenced by cfg_PMFileExpiration::cfg_PMFileExpiration().

00590                                             {
00591     m_dur_p = &(a_duration);
00592 }

Here is the caller graph for this function:

string val_Duration::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 594 of file val.cpp.

References cfg_DAY, cfg_HOUR, cfg_INFINITE, cfg_MINUTE, cfg_UNLIMITED, cfg_YEAR, ie_NOT_VALID, ivd_Error, m_multiplier, and val_Value::m_name.

00594                                                     {
00595 
00596     if (a_strVal.length() < 2) {
00597         ostringstream sstr;
00598         sstr
00599             << "Invalid duration format. String too short. Variable:" << m_name
00600             << " = " << a_strVal;
00601 
00602         throw ivd_Error(ie_NOT_VALID, sstr.str());
00603     }
00604 
00605     if (a_strVal == cfg_UNLIMITED) {
00606         m_multiplier = cfg_INFINITE;
00607         return string("1");
00608     }
00609 
00610     char lastChar = a_strVal[a_strVal.length() - 1];
00611     switch (lastChar) {
00612     case 's': // seconds
00613         m_multiplier = 1;
00614         break;
00615     case 'm': // minutes
00616         m_multiplier = cfg_MINUTE;
00617         break;
00618     case 'h': // hours
00619         m_multiplier = cfg_HOUR;
00620         break;
00621     case 'D': // days
00622         m_multiplier = cfg_DAY;
00623         break;
00624     case 'M': // months
00625         m_multiplier = 30*cfg_DAY;
00626         break;
00627     case 'Y': // years
00628         m_multiplier = cfg_YEAR;
00629         break;
00630     default:
00631         {
00632             ostringstream sstr;
00633             sstr
00634                 << "Invalid duration format. Expected s, m, h or D, M, Y or UNLIMITED.  Variable:"
00635                 << m_name << " = " << a_strVal;
00636 
00637             throw ivd_Error(ie_NOT_VALID, sstr.str());
00638             break;
00639         }
00640     };
00641 
00642     return a_strVal.substr(0, a_strVal.length() - 1);
00643 }

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

Implements val_BasicValue.

Definition at line 645 of file val.cpp.

References val_Integer::Bind(), cmn_Num2Str(), val_Value::Conv(), ie_PARSER_ERROR, ivd_Error, m_dur_p, val_Value::m_limits, m_multiplier, val_Value::m_name, and NULL.

00645                                                 {
00646 
00647     if (m_dur_p == NULL) {
00648         return;
00649     };
00650 
00651     // Make temporary conversion to get the numeric value from
00652     // the string a_strVal.
00653     UInt64_t tmp(0);
00654     {
00655         val_Integer vi(m_name, val_Limit(0, UINT_MAX));
00656         vi.Bind(tmp);
00657         vi.Conv(a_strVal);
00658     }
00659     tmp *= m_multiplier;
00660 
00661     if (tmp >= UINT_MAX) {
00662         throw ivd_Error(ie_PARSER_ERROR,
00663         string("Integer overflow for duration value. Value:") + a_strVal +
00664         string(" at variable: ") + m_name);
00665     };
00666 
00667     // Do final conversion and limit checks.
00668     UInt32_t final(0);
00669     {
00670         string strVal(cmn_Num2Str(tmp));
00671         val_Integer vi(m_name, m_limits);
00672         vi.Bind(final);
00673         // Limits are checked in val_Integer
00674         vi.Conv(strVal);
00675     }
00676 
00677     *m_dur_p = final;
00678 }

Here is the call graph for this function:


Member Data Documentation

Definition at line 583 of file val.h.

Referenced by Assign(), and Bind().

Definition at line 584 of file val.h.

Referenced by Assign(), and Validate().

Reimplemented from val_Value.

Definition at line 586 of file val.h.


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

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