Public Member Functions | Private Attributes

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.

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

Detailed Description

Definition at line 581 of file val.h.


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

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

val_Duration::~val_Duration (  )  [virtual]

Definition at line 600 of file val.cpp.

                            {
    //Empty
}


Member Function Documentation

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

Definition at line 659 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.

                                                {

    if (m_dur_p == NULL) {
        return;
    };

    // Make temporary conversion to get the numeric value from
    // the string a_strVal.
    UInt64_t tmp(0);
    {
        val_Integer vi(m_name, val_Limit(0, UINT_MAX));
        vi.Bind(tmp);
        vi.Conv(a_strVal);
    }
    tmp *= m_multiplier;

    if (tmp >= UINT_MAX) {
        throw ivd_Error(ie_PARSER_ERROR,
        string("Integer overflow for duration value. Value:") + a_strVal +
        string(" at variable: ") + m_name);
    };

    // Do final conversion and limit checks.
    UInt32_t final(0);
    {
        string strVal(cmn_Num2Str(tmp));
        val_Integer vi(m_name, m_limits);
        vi.Bind(final);
        // Limits are checked in val_Integer
        vi.Conv(strVal);
    }

    *m_dur_p = final;
}

Here is the call graph for this function:

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

Definition at line 604 of file val.cpp.

References m_dur_p.

Referenced by cfg_PMFileExpiration::cfg_PMFileExpiration().

                                            {
    m_dur_p = &(a_duration);
}

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

References cfg_UNLIMITED, ie_NOT_VALID, ivd_Error, m_multiplier, and val_Value::m_name.

                                                    {

    if (a_strVal.length() < 2) {
        ostringstream sstr;
        sstr
            << "Invalid duration format. String too short. Variable:" << m_name
            << " = " << a_strVal;

        throw ivd_Error(ie_NOT_VALID, sstr.str());
    }

    if (a_strVal == cfg_UNLIMITED) {
        m_multiplier = cfg_INFINITE;
        return string("1");
    }

    char lastChar = a_strVal[a_strVal.length() - 1];
    switch (lastChar) {
    case 's': // seconds
        m_multiplier = 1;
        break;
    case 'm': // minutes
        m_multiplier = cfg_MINUTE;
        break;
    case 'h': // hours
        m_multiplier = cfg_HOUR;
        break;
    case 'D': // days
        m_multiplier = cfg_DAY;
        break;
    case 'M': // months
        m_multiplier = 30*cfg_DAY;
        break;
    case 'Y': // years
        m_multiplier = cfg_YEAR;
        break;
    default:
        {
            ostringstream sstr;
            sstr
                << "Invalid duration format. Expected s, m, h or D, M, Y or UNLIMITED.  Variable:"
                << m_name << " = " << a_strVal;

            throw ivd_Error(ie_NOT_VALID, sstr.str());
            break;
        }
    };

    return a_strVal.substr(0, a_strVal.length() - 1);
}


Member Data Documentation

Reimplemented from val_Value.

Definition at line 600 of file val.h.

Definition at line 597 of file val.h.

Referenced by Assign(), and Bind().

Definition at line 598 of file val.h.

Referenced by Assign(), and Validate().


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