Back to index

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

#include <DoubleValidator.h>

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

List of all members.

Public Types

enum  State { Invalid = 0, Intermediate, Acceptable }

Public Member Functions

 DoubleValidator (double Minimum=-1.7E308, double Maximum=1.7E308)
 DoubleValidator (const DoubleValidator &validator)
DoubleValidatoroperator= (const DoubleValidator &rhs)
virtual ~DoubleValidator ()
virtual ValidatorClone () const
double GetClampedValue (double d) const
virtual void Alternative (const char *str)
void SetDecimals (int dec)
void SetMinimum (double value)
double GetMinimum () const
void SetMaximum (double value)
double GetMaximum () const
NString ToString (double d)
double ToDouble (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

double m_Minimum
double m_Maximum
int m_Decimals

Detailed Description

Definition at line 31 of file DoubleValidator.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::DoubleValidator::DoubleValidator ( double  Minimum = -1.7E308,
double  Maximum = 1.7E308 
)

Definition at line 29 of file DoubleValidator.cpp.

    :   m_Minimum(Minimum)
    ,   m_Maximum(Maximum)
    ,   m_Decimals(3)
  {
    _regexp_str = "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$";

    InitRegExp();

    if (m_Minimum > m_Maximum)
    {
      double 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 46 of file DoubleValidator.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 67 of file DoubleValidator.cpp.

  {
  }

Member Function Documentation

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

Reimplemented from nux::Validator.

Definition at line 121 of file DoubleValidator.cpp.

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

Implements nux::Validator.

Definition at line 71 of file DoubleValidator.cpp.

  {
    return new DoubleValidator(*this);
  }

Here is the call graph for this function:

double nux::DoubleValidator::GetClampedValue ( double  d) const
Returns:
The input value clamped to the range [m_Minimum, m_Maximum].

Definition at line 110 of file DoubleValidator.cpp.

  {
    if (d < m_Minimum)
      return m_Minimum;

    if (d > m_Maximum)
      return m_Maximum;

    return d;
  }

Here is the caller graph for this function:

Definition at line 105 of file DoubleValidator.cpp.

  {
    return m_Maximum;
  }

Here is the caller graph for this function:

Definition at line 88 of file DoubleValidator.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:

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

Definition at line 54 of file DoubleValidator.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:

Definition at line 126 of file DoubleValidator.cpp.

  {
    m_Decimals = Clamp<int> (dec, 0, 13);
  }

Here is the caller graph for this function:

void nux::DoubleValidator::SetMaximum ( double  value)

Definition at line 93 of file DoubleValidator.cpp.

  {
    m_Maximum = value;

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

Here is the caller graph for this function:

void nux::DoubleValidator::SetMinimum ( double  value)

Definition at line 76 of file DoubleValidator.cpp.

  {
    m_Minimum = value;

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

Here is the caller graph for this function:

double nux::DoubleValidator::ToDouble ( const char *  str)

Definition at line 137 of file DoubleValidator.cpp.

  {
    if (Validate(str) == Acceptable)
      return CharToDouble(str);
    else
      return 0.0;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 131 of file DoubleValidator.cpp.

  {
    NString Prec = NString("%.") + NString::Printf("%d", m_Decimals) + NString("f");
    return NString::Printf(Prec.GetTCharPtr(), d);
  }

Here is the call graph for this function:

Here is the caller 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 61 of file DoubleValidator.h.

Definition at line 60 of file DoubleValidator.h.

Definition at line 59 of file DoubleValidator.h.


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