Public Member Functions | Private Attributes

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.

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

Detailed Description

Definition at line 623 of file val.h.


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

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

val_Size::~val_Size (  )  [virtual]

Definition at line 750 of file val.cpp.

                    {
    //Empty
}


Member Function Documentation

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

error)

Reimplemented from val_Integer.

Definition at line 808 of file val.cpp.

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

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

    // Do final conversion and limit checks.
    val_Integer::Assign(cmn_Num2Str(tmp));
}

Here is the call graph for this function:

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

References dbg_DETAIL, ie_NOT_VALID, ivd_Error, log_DBG_m, log_FUNC_A_m, m_multiplier, val_Value::m_name, and strcasecmp.

                                                {

    if (a_strVal.length() < 2) {
        ostringstream sstr;
        sstr
            << "Invalid size format. String too short. Value: " << a_strVal
            << " at variable: " + m_name;

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

    log_FUNC_A_m(Validate , "a_strVal:" << a_strVal);
    log_DBG_m(dbg_DETAIL,"");

    string::size_type unitPos = a_strVal.length() - 2;
    log_DBG_m(dbg_DETAIL,"a_strVal.length():" << a_strVal.length() <<
                            " unitPos:" << unitPos);

    string unit = a_strVal.substr(unitPos, 2);
    log_DBG_m(dbg_DETAIL,"unit:" << unit);

    string num;

    if ( strcasecmp(unit.c_str(),  "KB") == 0) {
        m_multiplier = cfg_KILOBYTE;
        num = a_strVal.substr(0, a_strVal.length()-2);
    }
    else if ( strcasecmp(unit.c_str(), "MB") == 0 ) {
        m_multiplier = cfg_MEGABYTE;
        num = a_strVal.substr(0, a_strVal.length()-2);
    }
    else if (strcasecmp(unit.c_str(), "GB") == 0) {
        m_multiplier = cfg_GIGABYTE;
        num = a_strVal.substr(0, a_strVal.length()-2);
    }
    else if (strcasecmp(unit.c_str(), "TB") == 0) {
        m_multiplier = cfg_TERABYTE;
        num = a_strVal.substr(0, a_strVal.length()-2);
    }
    else if ( (unit[1] == 'B') || (unit[1] == 'b') ) {
        m_multiplier = 1;
        num = a_strVal.substr(0, a_strVal.length()-1);
    }
    else {
        ostringstream sstr;
        sstr
            << "Invalid size format. Expected B, KB, MB, GB or TB. "
            << "Value: " << a_strVal << " at variable: " << m_name;

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


Member Data Documentation

Reimplemented from val_Integer.

Definition at line 641 of file val.h.

Definition at line 639 of file val.h.

Referenced by Assign(), and Validate().


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