Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes

val_Integer Class Reference
[Parser for config files; validation]

#include <val.h>

Inheritance diagram for val_Integer:
Inheritance graph
[legend]
Collaboration diagram for val_Integer:
Collaboration graph
[legend]

List of all members.

Classes

struct  IntPtr_t

Public Member Functions

 val_Integer (const string &a_name, const val_Limit a_limits, const UInt32_t a_minNumOfVal=1, const UInt64_t a_maxNumOfVal=cfg_INFINITE)
 val_Integer (const string &a_name, const val_Limit a_limits, const UInt32_t a_minNumOfVal, const UInt64_t a_maxNumOfVal, const string &a_defaultStr)
virtual ~val_Integer ()
virtual void Bind (Int8_t &a_dest)
virtual void Bind (Int16_t &a_dest)
virtual void Bind (Int32_t &a_dest)
virtual void Bind (Int64_t &a_dest)
virtual void Bind (UInt8_t &a_dest)
virtual void Bind (UInt16_t &a_dest)
virtual void Bind (UInt32_t &a_dest)
virtual void Bind (UInt64_t &a_dest)
string IntPtrToStr ()

Protected Types

enum  IntType {
  IntUndef, Int8,
  Int16, Int32,
  Int64, UInt8,
  UInt16, UInt32,
  UInt64
}

Protected Member Functions

virtual void Assign (const string &a_strVal)
virtual void CheckLimits ()

Protected Attributes

struct IntPtr_t m_intTgt
 log_CLASSID_m

Detailed Description

Definition at line 523 of file val.h.


Member Enumeration Documentation

enum val_Integer::IntType [protected]
Enumerator:
IntUndef 
Int8 
Int16 
Int32 
Int64 
UInt8 
UInt16 
UInt32 
UInt64 

Definition at line 526 of file val.h.

                 {
        IntUndef,
        Int8, Int16, Int32, Int64,
        UInt8, UInt16, UInt32, UInt64};


Constructor & Destructor Documentation

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

Definition at line 341 of file val.cpp.

References val_Integer::IntPtr_t::i8_p, m_intTgt, and val_Integer::IntPtr_t::type.

  : val_Value(a_name, a_limits, a_minNumOfVal, a_maxNumOfVal) {

    m_intTgt.type = IntUndef;
    m_intTgt.i8_p = NULL;
}

val_Integer::val_Integer ( const string &  a_name,
const val_Limit  a_limits,
const UInt32_t  a_minNumOfVal,
const UInt64_t  a_maxNumOfVal,
const string &  a_defaultStr 
)

Definition at line 352 of file val.cpp.

References val_Integer::IntPtr_t::i8_p, m_intTgt, and val_Integer::IntPtr_t::type.

   : val_Value(a_name, a_limits, a_minNumOfVal, a_maxNumOfVal, a_defaultStr ) {

    m_intTgt.type = IntUndef;
    m_intTgt.i8_p = NULL;
}

val_Integer::~val_Integer (  )  [virtual]

Definition at line 366 of file val.cpp.

                          {
    //Empty
}


Member Function Documentation

void val_Integer::Assign ( const string &  a_strVal  )  [protected, virtual]

error)

Reimplemented in val_Size.

Definition at line 408 of file val.cpp.

References errno, val_Integer::IntPtr_t::i16_p, val_Integer::IntPtr_t::i32_p, val_Integer::IntPtr_t::i64_p, val_Integer::IntPtr_t::i8_p, ie_INVALID_ARG, ie_PARSER_ERROR, Int16, Int32, Int64, Int8, IntUndef, ivd_Error, LLONG_MAX, LLONG_MIN, m_intTgt, val_Value::m_name, NULL, strtoll, strtoull, val_Integer::IntPtr_t::type, val_Integer::IntPtr_t::u16_p, val_Integer::IntPtr_t::u32_p, val_Integer::IntPtr_t::u64_p, val_Integer::IntPtr_t::u8_p, UInt16, UInt32, UInt64, UInt8, and ULLONG_MAX.

                                               {

    if (m_intTgt.type == IntUndef) {
        return;
    };

    if (a_strVal.empty()) {
        throw ivd_Error(ie_PARSER_ERROR,
            "Can't convert empty string to a number.");
    }

    Int64_t     converted = 0;
    UInt64_t    uconverted = 0;
    char        *end = NULL;
    bool        overflow(false);

    errno = 0;

    // Performing conversion
    if (m_intTgt.type == Int8 || m_intTgt.type == Int16 ||
        m_intTgt.type == Int32 || m_intTgt.type == Int64) {
        converted = strtoll(a_strVal.c_str(), &end, 10);
        if (converted == LLONG_MIN || converted == LLONG_MAX) {
            overflow = true;
        }
    }
    else {
        uconverted = strtoull(a_strVal.c_str(), &end, 10);
        if (uconverted == ULLONG_MAX) {
            overflow = true;
        }
    }

    // Checking results (overflow for 64-bit, invalid input)
    if (errno != 0) {
        // overflow for 64-bit values checked with errno.
        if (errno == ERANGE) {
            overflow = true;
        }
        else {
            throw ivd_Error(ie_PARSER_ERROR,
                string("Integer conversion error for: ") + a_strVal  +
                string(" at variable: ") + m_name);
        }
    };
    if (overflow) {
        throw ivd_Error(ie_PARSER_ERROR,
            string("Integer overflow at conversion: ") + a_strVal  +
            string(" at variable: ") + m_name);
    }

    if (end != NULL && *end != '\0') {
        throw ivd_Error(ie_PARSER_ERROR,
            "String is not a number: " + a_strVal);
    }

    // Check overflow of smaller integers.
    switch (m_intTgt.type) {

        // -- signed --
        case Int8:
            if (converted > SCHAR_MAX || converted < SCHAR_MIN) overflow = true;//else
            *(m_intTgt.i8_p) = (Int8_t)converted;
            break;
        case Int16:
            if (converted > SHRT_MAX || converted < SHRT_MIN) overflow = true;//else
            *(m_intTgt.i16_p) = (Int16_t)converted;
            break;
        case Int32:
            if (converted > INT_MAX || converted < INT_MIN) overflow = true;//else
            *(m_intTgt.i32_p) = (Int32_t)converted;
            break;
        case Int64:
            // Overflow checked above
            *(m_intTgt.i64_p) = converted;
            break;

        // -- unsigned --
        case UInt8:
            if (uconverted > UCHAR_MAX) overflow = true;//else
            *(m_intTgt.u8_p) = (UInt8_t)uconverted;
            break;
        case UInt16:
            if (uconverted > USHRT_MAX) overflow = true; //else
            *(m_intTgt.u16_p) = (UInt16_t)uconverted;
            break;
        case UInt32:
            if (uconverted > UINT_MAX) overflow = true; //else
            *(m_intTgt.u32_p) = (UInt32_t)uconverted;
            break;
        case UInt64:
            // Overflow checked above
            *(m_intTgt.u64_p) = uconverted;
            break;

        default:
            throw ivd_Error(ie_INVALID_ARG, "Unknown target integer at variable: " + m_name);
    };
    if (overflow) {
        throw ivd_Error(ie_PARSER_ERROR,
            string("Integer overflow: ") + a_strVal +
            string(" at variable: ") + m_name);
    }
}

void val_Integer::Bind ( Int8_t a_dest  )  [virtual]

Definition at line 370 of file val.cpp.

References val_Integer::IntPtr_t::i8_p, m_intTgt, and val_Integer::IntPtr_t::type.

Referenced by val_SlotList::Add(), val_SlotList::AddRange(), val_Size::Assign(), val_Duration::Assign(), ParseDiskMediumVolume(), and bea_DiskVolume::ReparseFiles().

                                        {
    m_intTgt.i8_p = &(a_dest); m_intTgt.type = Int8;
}

Here is the caller graph for this function:

void val_Integer::Bind ( UInt8_t a_dest  )  [virtual]

Definition at line 386 of file val.cpp.

References m_intTgt, val_Integer::IntPtr_t::type, and val_Integer::IntPtr_t::u8_p.

                                        {
    m_intTgt.u8_p = &(a_dest); m_intTgt.type = UInt8;
}

void val_Integer::Bind ( Int64_t a_dest  )  [virtual]

Definition at line 382 of file val.cpp.

References val_Integer::IntPtr_t::i64_p, m_intTgt, and val_Integer::IntPtr_t::type.

                                        {
    m_intTgt.i64_p = &(a_dest); m_intTgt.type = Int64;
}

void val_Integer::Bind ( UInt64_t a_dest  )  [virtual]

Definition at line 398 of file val.cpp.

References m_intTgt, val_Integer::IntPtr_t::type, and val_Integer::IntPtr_t::u64_p.

                                        {
    m_intTgt.u64_p = &(a_dest); m_intTgt.type = UInt64;
}

void val_Integer::Bind ( UInt32_t a_dest  )  [virtual]

Definition at line 394 of file val.cpp.

References m_intTgt, val_Integer::IntPtr_t::type, and val_Integer::IntPtr_t::u32_p.

                                        {
    m_intTgt.u32_p = &(a_dest); m_intTgt.type = UInt32;
}

void val_Integer::Bind ( UInt16_t a_dest  )  [virtual]

Definition at line 390 of file val.cpp.

References m_intTgt, val_Integer::IntPtr_t::type, and val_Integer::IntPtr_t::u16_p.

                                        {
    m_intTgt.u16_p = &(a_dest); m_intTgt.type = UInt16;
}

void val_Integer::Bind ( Int16_t a_dest  )  [virtual]

Definition at line 374 of file val.cpp.

References val_Integer::IntPtr_t::i16_p, m_intTgt, and val_Integer::IntPtr_t::type.

                                        {
    m_intTgt.i16_p = &(a_dest); m_intTgt.type = Int16;
}

void val_Integer::Bind ( Int32_t a_dest  )  [virtual]

Definition at line 378 of file val.cpp.

References val_Integer::IntPtr_t::i32_p, m_intTgt, and val_Integer::IntPtr_t::type.

                                        {
    m_intTgt.i32_p = &(a_dest); m_intTgt.type = Int32;
}

void val_Integer::CheckLimits (  )  [protected, virtual]

Reimplemented from val_Value.

Definition at line 536 of file val.cpp.

References val_Integer::IntPtr_t::i16_p, val_Integer::IntPtr_t::i32_p, val_Integer::IntPtr_t::i64_p, val_Integer::IntPtr_t::i8_p, ie_INVALID_ARG, ie_PARSER_ERROR, Int16, Int32, Int64, Int8, IntPtrToStr(), ivd_Error, val_Limit::lower, m_intTgt, val_Value::m_limits, val_Value::m_name, val_Integer::IntPtr_t::type, val_Integer::IntPtr_t::u16_p, val_Integer::IntPtr_t::u32_p, val_Integer::IntPtr_t::u64_p, val_Integer::IntPtr_t::u8_p, UInt16, UInt32, UInt64, UInt8, and val_Limit::upper.

                              {
    bool outofrange = false;

    switch (m_intTgt.type) {
        case Int8:
            if (*(m_intTgt.i8_p) < m_limits.lower || *(m_intTgt.i8_p) > m_limits.upper) outofrange = true;
            break;
        case Int16:
            if (*(m_intTgt.i16_p) < m_limits.lower || *(m_intTgt.i16_p) > m_limits.upper) outofrange = true;
            break;
        case Int32:
            if (*(m_intTgt.i32_p) < m_limits.lower || *(m_intTgt.i32_p) > m_limits.upper) outofrange = true;
            break;
        case Int64:
            if (*(m_intTgt.i64_p) < m_limits.lower || *(m_intTgt.i64_p) > m_limits.upper) outofrange = true;
            break;
        case UInt8:
            if (*(m_intTgt.u8_p) < m_limits.lower || *(m_intTgt.u8_p) > m_limits.upper) outofrange = true;
            break;
        case UInt16:
            if (*(m_intTgt.u16_p) < m_limits.lower || *(m_intTgt.u16_p) > m_limits.upper) outofrange = true;
            break;
        case UInt32:
            if (*(m_intTgt.u32_p) < m_limits.lower || *(m_intTgt.u32_p) > m_limits.upper) outofrange = true;
            break;
        case UInt64:
            {
                UInt64_t low = (UInt64_t)(m_limits.lower);
                UInt64_t high = (UInt64_t)(m_limits.upper);

                if (*(m_intTgt.u64_p) < low || *(m_intTgt.u64_p) > high) outofrange = true;
            }
            break;
        default:
            throw ivd_Error(ie_INVALID_ARG, "Unknown target integer at variable:" + m_name);
    };
    if (outofrange) {
        ostringstream errorDescription;
        errorDescription
            << endl
            << "Integer value for variable:" << m_name << " = " << IntPtrToStr()
            << " is out of limits:" << endl
            << "lower limit: " << m_limits.lower << endl
            << "upper limit: " << m_limits.upper << endl;
        throw ivd_Error(ie_PARSER_ERROR, errorDescription.str());
    };
}

Here is the call graph for this function:

string val_Integer::IntPtrToStr (  ) 

Definition at line 513 of file val.cpp.

References cmn_Num2Str(), val_Integer::IntPtr_t::i16_p, val_Integer::IntPtr_t::i32_p, val_Integer::IntPtr_t::i64_p, val_Integer::IntPtr_t::i8_p, Int16, Int32, Int64, Int8, m_intTgt, val_Integer::IntPtr_t::type, val_Integer::IntPtr_t::u16_p, val_Integer::IntPtr_t::u32_p, val_Integer::IntPtr_t::u64_p, val_Integer::IntPtr_t::u8_p, UInt16, UInt32, UInt64, and UInt8.

Referenced by CheckLimits().

                               {
    switch (m_intTgt.type) {
        case Int8:
            return cmn_Num2Str(*(m_intTgt.i8_p));
        case Int16:
            return cmn_Num2Str(*(m_intTgt.i16_p));
        case Int32:
            return cmn_Num2Str(*(m_intTgt.i32_p));
        case Int64:
            return cmn_Num2Str(*(m_intTgt.i64_p));
        case UInt8:
            return cmn_Num2Str(*(m_intTgt.u8_p));
        case UInt16:
            return cmn_Num2Str(*(m_intTgt.u16_p));
        case UInt32:
            return cmn_Num2Str(*(m_intTgt.u32_p));
        case UInt64:
            return cmn_Num2Str(*(m_intTgt.u64_p));
        default:;
    };
    return string("");
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from val_Value.

Reimplemented in val_Size, and val_Percentage.

Definition at line 578 of file val.h.

struct IntPtr_t val_Integer::m_intTgt [protected]

Definition at line 576 of file val.h.

Referenced by Assign(), Bind(), CheckLimits(), IntPtrToStr(), and val_Integer().


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