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.


Detailed Description

Definition at line 509 of file val.h.


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

Classes

struct  IntPtr_t

Member Enumeration Documentation

enum val_Integer::IntType [protected]

Enumerator:
IntUndef 
Int8 
Int16 
Int32 
Int64 
UInt8 
UInt16 
UInt32 
UInt64 

Definition at line 512 of file val.h.

00512                  {
00513         IntUndef,
00514         Int8, Int16, Int32, Int64,
00515         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 327 of file val.cpp.

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

00332   : val_Value(a_name, a_limits, a_minNumOfVal, a_maxNumOfVal) {
00333 
00334     m_intTgt.type = IntUndef;
00335     m_intTgt.i8_p = NULL;
00336 }

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

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

00344    : val_Value(a_name, a_limits, a_minNumOfVal, a_maxNumOfVal, a_defaultStr ) {
00345 
00346     m_intTgt.type = IntUndef;
00347     m_intTgt.i8_p = NULL;
00348 }

val_Integer::~val_Integer (  )  [virtual]

Definition at line 352 of file val.cpp.

00352                           {
00353     //Empty
00354 }


Member Function Documentation

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

Reimplemented from val_BasicValue.

Definition at line 356 of file val.cpp.

References val_Integer::IntPtr_t::i8_p, Int8, 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().

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

Here is the caller graph for this function:

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

Reimplemented from val_BasicValue.

Definition at line 360 of file val.cpp.

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

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

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

Reimplemented from val_BasicValue.

Definition at line 364 of file val.cpp.

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

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

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

Reimplemented from val_BasicValue.

Definition at line 368 of file val.cpp.

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

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

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

Reimplemented from val_BasicValue.

Definition at line 372 of file val.cpp.

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

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

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

Reimplemented from val_BasicValue.

Definition at line 376 of file val.cpp.

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

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

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

Reimplemented from val_BasicValue.

Definition at line 380 of file val.cpp.

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

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

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

Reimplemented from val_BasicValue.

Definition at line 384 of file val.cpp.

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

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

string val_Integer::IntPtrToStr (  ) 

Definition at line 499 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().

00499                                {
00500     switch (m_intTgt.type) {
00501         case Int8:
00502             return cmn_Num2Str(*(m_intTgt.i8_p));
00503         case Int16:
00504             return cmn_Num2Str(*(m_intTgt.i16_p));
00505         case Int32:
00506             return cmn_Num2Str(*(m_intTgt.i32_p));
00507         case Int64:
00508             return cmn_Num2Str(*(m_intTgt.i64_p));
00509         case UInt8:
00510             return cmn_Num2Str(*(m_intTgt.u8_p));
00511         case UInt16:
00512             return cmn_Num2Str(*(m_intTgt.u16_p));
00513         case UInt32:
00514             return cmn_Num2Str(*(m_intTgt.u32_p));
00515         case UInt64:
00516             return cmn_Num2Str(*(m_intTgt.u64_p));
00517         default:;
00518     };
00519     return string("");
00520 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements val_BasicValue.

Reimplemented in val_Size.

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

Referenced by val_Size::Assign().

00394                                                {
00395 
00396     if (m_intTgt.type == IntUndef) {
00397         return;
00398     };
00399 
00400     if (a_strVal.empty()) {
00401         throw ivd_Error(ie_PARSER_ERROR,
00402             "Can't convert empty string to a number.");
00403     }
00404 
00405     Int64_t     converted = 0;
00406     UInt64_t    uconverted = 0;
00407     char        *end = NULL;
00408     bool        overflow(false);
00409 
00410     errno = 0;
00411 
00412     // Performing conversion
00413     if (m_intTgt.type == Int8 || m_intTgt.type == Int16 ||
00414         m_intTgt.type == Int32 || m_intTgt.type == Int64) {
00415         converted = strtoll(a_strVal.c_str(), &end, 10);
00416         if (converted == LLONG_MIN || converted == LLONG_MAX) {
00417             overflow = true;
00418         }
00419     }
00420     else {
00421         uconverted = strtoull(a_strVal.c_str(), &end, 10);
00422         if (uconverted == ULLONG_MAX) {
00423             overflow = true;
00424         }
00425     }
00426 
00427     // Checking results (overflow for 64-bit, invalid input)
00428     if (errno != 0) {
00429         // overflow for 64-bit values checked with errno.
00430         if (errno == ERANGE) {
00431             overflow = true;
00432         }
00433         else {
00434             throw ivd_Error(ie_PARSER_ERROR,
00435                 string("Integer conversion error for: ") + a_strVal  +
00436                 string(" at variable: ") + m_name);
00437         }
00438     };
00439     if (overflow) {
00440         throw ivd_Error(ie_PARSER_ERROR,
00441             string("Integer overflow at conversion: ") + a_strVal  +
00442             string(" at variable: ") + m_name);
00443     }
00444 
00445     if (end != NULL && *end != '\0') {
00446         throw ivd_Error(ie_PARSER_ERROR,
00447             "String is not a number: " + a_strVal);
00448     }
00449 
00450     // Check overflow of smaller integers.
00451     switch (m_intTgt.type) {
00452 
00453         // -- signed --
00454         case Int8:
00455             if (converted > SCHAR_MAX || converted < SCHAR_MIN) overflow = true;//else
00456             *(m_intTgt.i8_p) = (Int8_t)converted;
00457             break;
00458         case Int16:
00459             if (converted > SHRT_MAX || converted < SHRT_MIN) overflow = true;//else
00460             *(m_intTgt.i16_p) = (Int16_t)converted;
00461             break;
00462         case Int32:
00463             if (converted > INT_MAX || converted < INT_MIN) overflow = true;//else
00464             *(m_intTgt.i32_p) = (Int32_t)converted;
00465             break;
00466         case Int64:
00467             // Overflow checked above
00468             *(m_intTgt.i64_p) = converted;
00469             break;
00470 
00471         // -- unsigned --
00472         case UInt8:
00473             if (uconverted > UCHAR_MAX) overflow = true;//else
00474             *(m_intTgt.u8_p) = (UInt8_t)uconverted;
00475             break;
00476         case UInt16:
00477             if (uconverted > USHRT_MAX) overflow = true; //else
00478             *(m_intTgt.u16_p) = (UInt16_t)uconverted;
00479             break;
00480         case UInt32:
00481             if (uconverted > UINT_MAX) overflow = true; //else
00482             *(m_intTgt.u32_p) = (UInt32_t)uconverted;
00483             break;
00484         case UInt64:
00485             // Overflow checked above
00486             *(m_intTgt.u64_p) = uconverted;
00487             break;
00488 
00489         default:
00490             throw ivd_Error(ie_INVALID_ARG, "Unknown target integer at variable: " + m_name);
00491     };
00492     if (overflow) {
00493         throw ivd_Error(ie_PARSER_ERROR,
00494             string("Integer overflow: ") + a_strVal +
00495             string(" at variable: ") + m_name);
00496     }
00497 }

Here is the caller graph for this function:

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

Reimplemented from val_Value.

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

00522                               {
00523     bool outofrange = false;
00524 
00525     switch (m_intTgt.type) {
00526         case Int8:
00527             if (*(m_intTgt.i8_p) < m_limits.lower || *(m_intTgt.i8_p) > m_limits.upper) outofrange = true;
00528             break;
00529         case Int16:
00530             if (*(m_intTgt.i16_p) < m_limits.lower || *(m_intTgt.i16_p) > m_limits.upper) outofrange = true;
00531             break;
00532         case Int32:
00533             if (*(m_intTgt.i32_p) < m_limits.lower || *(m_intTgt.i32_p) > m_limits.upper) outofrange = true;
00534             break;
00535         case Int64:
00536             if (*(m_intTgt.i64_p) < m_limits.lower || *(m_intTgt.i64_p) > m_limits.upper) outofrange = true;
00537             break;
00538         case UInt8:
00539             if (*(m_intTgt.u8_p) < m_limits.lower || *(m_intTgt.u8_p) > m_limits.upper) outofrange = true;
00540             break;
00541         case UInt16:
00542             if (*(m_intTgt.u16_p) < m_limits.lower || *(m_intTgt.u16_p) > m_limits.upper) outofrange = true;
00543             break;
00544         case UInt32:
00545             if (*(m_intTgt.u32_p) < m_limits.lower || *(m_intTgt.u32_p) > m_limits.upper) outofrange = true;
00546             break;
00547         case UInt64:
00548             {
00549                 UInt64_t low = (UInt64_t)(m_limits.lower);
00550                 UInt64_t high = (UInt64_t)(m_limits.upper);
00551 
00552                 if (*(m_intTgt.u64_p) < low || *(m_intTgt.u64_p) > high) outofrange = true;
00553             }
00554             break;
00555         default:
00556             throw ivd_Error(ie_INVALID_ARG, "Unknown target integer at variable:" + m_name);
00557     };
00558     if (outofrange) {
00559         ostringstream errorDescription;
00560         errorDescription
00561             << endl
00562             << "Integer value for variable:" << m_name << " = " << IntPtrToStr()
00563             << " is out of limits:" << endl
00564             << "lower limit: " << m_limits.lower << endl
00565             << "upper limit: " << m_limits.upper << endl;
00566         throw ivd_Error(ie_PARSER_ERROR, errorDescription.str());
00567     };
00568 }

Here is the call graph for this function:


Member Data Documentation

struct IntPtr_t val_Integer::m_intTgt [read, protected]

Definition at line 562 of file val.h.

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

Reimplemented from val_Value.

Reimplemented in val_Size, and val_Percentage.

Definition at line 564 of file val.h.


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

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