#include <val.h>


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_t * | m_dur_p |
| UInt64_t | m_multiplier |
| log_CLASSID_m | |
| val_Duration::~val_Duration | ( | ) | [virtual] |
| 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 }

| string val_Duration::Validate | ( | const string & | a_strVal | ) | [virtual] |
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 }

UInt32_t* val_Duration::m_dur_p [private] |
UInt64_t val_Duration::m_multiplier [private] |
val_Duration::log_CLASSID_m [private] |
1.5.6