Back to index

nux  3.0.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
nux::IntegerValidator Class Reference

#include <IntegerValidator.h>

Inheritance diagram for nux::IntegerValidator:
Inheritance graph
[legend]
Collaboration diagram for nux::IntegerValidator:
Collaboration graph
[legend]

List of all members.

Public Types

enum  State { Invalid = 0, Intermediate, Acceptable }

Public Member Functions

 IntegerValidator (int Minimum=INT_MIN, int Maximum=INT_MAX)
 IntegerValidator (const IntegerValidator &validator)
IntegerValidatoroperator= (const IntegerValidator &rhs)
virtual ~IntegerValidator ()
virtual ValidatorClone () const
int GetClampedValue (int i) const
virtual void Alternative (const char *str)
void SetMinimum (int value)
int GetMinimum () const
void SetMaximum (int value)
int GetMaximum () const
NString ToString (int i)
int ToInteger (const char *str)
virtual Validator::State Validate (const char *str) const

Protected Member Functions

bool InitRegExp ()

Protected Attributes

NString _regexp_str
pcre * _regexp

Private Attributes

int m_Minimum
int m_Maximum

Detailed Description

Definition at line 30 of file IntegerValidator.h.


Member Enumeration Documentation

enum nux::Validator::State [inherited]
Enumerator:
Invalid 
Intermediate 
Acceptable 

Definition at line 38 of file Validator.h.


Constructor & Destructor Documentation

nux::IntegerValidator::IntegerValidator ( int  Minimum = INT_MIN,
int  Maximum = INT_MAX 
)

Definition at line 29 of file IntegerValidator.cpp.

    :   m_Minimum(Minimum)
    ,   m_Maximum(Maximum)
  {
    _regexp_str = "^[-+]?[0-9]+$";

    InitRegExp();

    if (m_Minimum > m_Maximum)
    {
      int temp = m_Minimum;
      m_Minimum = m_Maximum;
      m_Maximum = temp;
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 45 of file IntegerValidator.cpp.

  {
    m_Minimum   = copy.m_Minimum;
    m_Minimum   = copy.m_Maximum;
    _regexp_str    = copy._regexp_str;
    InitRegExp();
  }

Here is the call graph for this function:

Definition at line 66 of file IntegerValidator.cpp.

  {

  }

Member Function Documentation

void nux::IntegerValidator::Alternative ( const char *  str) [virtual]

Reimplemented from nux::Validator.

Definition at line 121 of file IntegerValidator.cpp.

  {
    str = "0";
  }
Validator * nux::IntegerValidator::Clone ( ) const [virtual]

Implements nux::Validator.

Definition at line 71 of file IntegerValidator.cpp.

  {
    return new IntegerValidator(*this);
  }

Here is the call graph for this function:

Returns:
The input value clamped to the range [m_Minimum, m_Maximum].

Definition at line 110 of file IntegerValidator.cpp.

  {
    if (i < m_Minimum)
      return m_Minimum;

    if (i > m_Maximum)
      return m_Maximum;

    return i;
  }

Here is the caller graph for this function:

Definition at line 105 of file IntegerValidator.cpp.

  {
    return m_Maximum;
  }

Here is the caller graph for this function:

Definition at line 88 of file IntegerValidator.cpp.

  {
    return m_Minimum;
  }

Here is the caller graph for this function:

bool nux::Validator::InitRegExp ( ) [protected, inherited]

Definition at line 38 of file Validator.cpp.

  {
#if defined(NUX_OS_WINDOWS)
    regex_ = _regexp_str.GetTCharPtr();
    return true;
#else
    const char *error;
    int   erroffset;
    _regexp = pcre_compile(
      _regexp_str.GetTCharPtr(),    /* the pattern */
      PCRE_MULTILINE,
      &error,         /* for error message */
      &erroffset,     /* for error offset */
      0);             /* use default character tables */

    if (!_regexp)
    {
      nuxDebugMsg("[IntegerValidator::IntegerValidator] Invalid regular expression: %s", _regexp_str.GetTCharPtr());
      return false;
    }    
    return true;
#endif
  }

Here is the call graph for this function:

Here is the caller graph for this function:

IntegerValidator & nux::IntegerValidator::operator= ( const IntegerValidator rhs)

Definition at line 53 of file IntegerValidator.cpp.

  {
    if (&rhs != this)
    {
      m_Minimum   = rhs.m_Minimum;
      m_Minimum   = rhs.m_Maximum;
      _regexp_str    = rhs._regexp_str;
      InitRegExp();
    }

    return *this;
  }

Here is the call graph for this function:

void nux::IntegerValidator::SetMaximum ( int  value)

Definition at line 93 of file IntegerValidator.cpp.

  {
    m_Maximum = value;

    if (m_Minimum > m_Maximum)
    {
      int temp = m_Minimum;
      m_Minimum = m_Maximum;
      m_Maximum = temp;
    }
  }

Here is the caller graph for this function:

void nux::IntegerValidator::SetMinimum ( int  value)

Definition at line 76 of file IntegerValidator.cpp.

  {
    m_Minimum = value;

    if (m_Minimum > m_Maximum)
    {
      int temp = m_Minimum;
      m_Minimum = m_Maximum;
      m_Maximum = temp;
    }
  }

Here is the caller graph for this function:

int nux::IntegerValidator::ToInteger ( const char *  str)

Definition at line 132 of file IntegerValidator.cpp.

  {
    if (Validate(str) == Acceptable)
      return CharToInteger(str);
    else
      return 0;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 126 of file IntegerValidator.cpp.

  {
    NString Prec("%d");
    return NString::Printf(Prec.GetTCharPtr(), i);
  }

Here is the call graph for this function:

Validator::State nux::Validator::Validate ( const char *  str) const [virtual, inherited]

Definition at line 62 of file Validator.cpp.

  {
#if defined(NUX_OS_WINDOWS)
    if (str == NULL)
      return Validator::Invalid;
    std::string search_string = str;

    if (std::regex_match(search_string.begin(), search_string.end(), regex_))
    {
      return Validator::Acceptable;
    }
    return Validator::Acceptable;
#else
    if (_regexp == 0)
      return Validator::Invalid;

    int out_vector [10];
    unsigned int offset = 0;
    int len = (int) strlen(str);

    // See the "PCRE DISCUSSION OF STACK USAGE" and why it maybe necessary to limit the stack usage.
    pcre_extra extra;
    extra.flags = PCRE_EXTRA_MATCH_LIMIT_RECURSION;
    extra.match_limit_recursion = 2000; 

    int rc = pcre_exec(_regexp, &extra, str, len, offset, 0, out_vector, 10);
    if (rc <= -1)
    {
      return Validator::Invalid;
    }
    return Validator::Acceptable;
#endif
  }

Here is the caller graph for this function:


Member Data Documentation

pcre* nux::Validator::_regexp [protected, inherited]

Definition at line 60 of file Validator.h.

NString nux::Validator::_regexp_str [protected, inherited]

Definition at line 55 of file Validator.h.

Definition at line 57 of file IntegerValidator.h.

Definition at line 56 of file IntegerValidator.h.


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