libcamgm
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ca_mgm::ValueCheck Class Reference

Expression chain for checking values. More...

#include <ValueCheck.hpp>

Inheritance diagram for ca_mgm::ValueCheck:
ca_mgm::ValueCheckBase ca_mgm::ReferenceCounted

Public Member Functions

 ValueCheck ()
 
 ValueCheck (ValueCheckBase *check)
 
ValueCheckoperator= (ValueCheckBase *check)
 
 ValueCheck (const ValueCheck &ref)
 
ValueCheckoperator= (const ValueCheck &ref)
 
virtual ~ValueCheck ()
 
virtual bool isValid (const std::string &value) const
 
virtual std::string explain (const std::string &value) const
 
ValueCheckAnd (const ValueCheck &ref)
 
ValueCheckAnd (ValueCheckBase *check)
 
ValueCheckOr (const ValueCheck &ref)
 
ValueCheckOr (ValueCheckBase *check)
 
ValueCheckNot ()
 
- Public Member Functions inherited from ca_mgm::ValueCheckBase
virtual ~ValueCheckBase ()
 
- Public Member Functions inherited from ca_mgm::ReferenceCounted
 ReferenceCounted ()
 
 ReferenceCounted (const ReferenceCounted &rhs)
 
virtual ~ReferenceCounted ()
 
ReferenceCountedoperator= (const ReferenceCounted &)
 
unsigned refCount () const
 
void ref () const
 
void unref () const
 

Private Types

enum  ECheckOp { E_AND, E_OR }
 

Private Member Functions

 ValueCheck (const ValueCheck &ref, ECheckOp op)
 
void incRCnt (ValueCheckBase *ptr)
 
void delRCnt (ValueCheckBase *ptr)
 

Private Attributes

ECheckOp m_cop
 
bool m_neg
 
ValueCheckBasem_self
 
std::list< ValueCheckm_list
 

Additional Inherited Members

- Static Public Member Functions inherited from ca_mgm::ReferenceCounted
static void add_ref (const ReferenceCounted *ptr_r)
 
static void release (const ReferenceCounted *ptr_r)
 
- Protected Member Functions inherited from ca_mgm::ValueCheckBase
 ValueCheckBase ()
 
- Protected Member Functions inherited from ca_mgm::ReferenceCounted
virtual std::ostream & dumpOn (std::ostream &str) const
 
virtual void ref_to (unsigned) const
 
virtual void unref_to (unsigned) const
 

Detailed Description

Expression chain for checking values.

The ValueCheck class allows to construct a simple expression. It contains one or more single checks derived from ValueCheckBase or also sub-expressions, that are combined with And, Or and Not operators.

The check can be evaluated for a value using the isValid() method, showed as string with the explain() method and of course stored in a variable and used to check values multiple times.

* //
* // Construct a check:
* //
* // (val =~ /^[-]?[0-9]{1,}$/)
* // And
* // (
* // (val >= 0 And val <= 99)
* // Or
* // (val >= -5 Or val <= 5)
* // And
* // Not(val == 7)
* // )
* //
* new ValueRegExCheck("^[-]?[0-9]{1,}$")
* ).And(
* new ValueIntCheck(Int64(0), Int64(99))
* ).Or(
* new ValueIntCheck(Int64(-5), Int64(5))
* ).And(
* new ValueIntCheck(Int64(7), Int64(7))
* ).Not()
* )
* );
*
* // Print out what the check does for value "42":
* std::cout << check.explain("42") << endl;
*
* // Evaluate the value "-3" and print out the result:
* std::cout << check.isValid("-3") << endl;
*
*
See Also
ValueRegExCheck, ValueIntCheck classes.

Member Enumeration Documentation

Enumerator
E_AND 
E_OR 

Constructor & Destructor Documentation

ca_mgm::ValueCheck::ValueCheck ( )

Default constructor. Since it does not contain any check, the isValid() and and explain() will throw an error until a check is assigned using the operator=().

ca_mgm::ValueCheck::ValueCheck ( ValueCheckBase check)

Single check assignment constructor.

Parameters
checkPointer to a single check.
ca_mgm::ValueCheck::ValueCheck ( const ValueCheck ref)

Check expression copy constructor.

Parameters
refReference to a check expression.
virtual ca_mgm::ValueCheck::~ValueCheck ( )
virtual

Destructor.

ca_mgm::ValueCheck::ValueCheck ( const ValueCheck ref,
ECheckOp  op 
)
private

Private constructor used to add the value check reference to the current expression list.

Parameters
refReference to a value check.
opRelation to the current or last expression in the list.

Member Function Documentation

ValueCheck& ca_mgm::ValueCheck::And ( const ValueCheck ref)

Append a sub-expression to the list of checks using the E_OR relationship operator.

Parameters
refReference to the sub-expression.
Returns
Reference to the current object.
ValueCheck& ca_mgm::ValueCheck::And ( ValueCheckBase check)

Append a single check to the list of checks using the E_AND relationship operator.

Parameters
checkPointer to a single value check.
Returns
Reference to the current object.
void ca_mgm::ValueCheck::delRCnt ( ValueCheckBase ptr)
private

Decrement the reference counter of the check and delete the object if needed.

Parameters
ptrPointer to a value check.
virtual std::string ca_mgm::ValueCheck::explain ( const std::string &  value) const
virtual

Returns a string explaining / showing the checks that will be done for the specified string value parameter.

Parameters
valueA string value.
Returns
A string showing the check (list).

Implements ca_mgm::ValueCheckBase.

void ca_mgm::ValueCheck::incRCnt ( ValueCheckBase ptr)
private

Increment the reference counter of the check.

Parameters
ptrPointer to a value check.
virtual bool ca_mgm::ValueCheck::isValid ( const std::string &  value) const
virtual

Evaluates a the specified string value parameter to a boolean using the single checks and sub-expressions it contains.

Parameters
valueThe string value to evaluate.
Returns
The boolean result of the check.

Implements ca_mgm::ValueCheckBase.

ValueCheck& ca_mgm::ValueCheck::Not ( )

Negate the result of the current expression.

Note
There is no difference between:
* ValueCheck(...).Not().And(...)
*
and
* ValueCheck(...).And(...).Not()
*
Both are negating the complete expression like: Not( (...) And (...) )
Returns
Reference to the current object.
ValueCheck& ca_mgm::ValueCheck::operator= ( ValueCheckBase check)

Single check assignment operator.

Parameters
checkPointer to a single check.
Returns
Reference to the current object.
ValueCheck& ca_mgm::ValueCheck::operator= ( const ValueCheck ref)

Check expression assignment operator.

Parameters
refReference to a check expression.
Returns
Reference to the current object.
ValueCheck& ca_mgm::ValueCheck::Or ( const ValueCheck ref)

Append a sub-expression to the list of checks using the E_OR relationship operator.

Parameters
refReference to the sub-expression.
Returns
Reference to the current object.
ValueCheck& ca_mgm::ValueCheck::Or ( ValueCheckBase check)

Append a single check to the list of checks using the E_OR relationship operator.

Parameters
checkPointer to a single value check.
Returns
Reference to the current object.

Member Data Documentation

ECheckOp ca_mgm::ValueCheck::m_cop
private

Check relationship operator to the parent check.

std::list<ValueCheck> ca_mgm::ValueCheck::m_list
private

List of further checks in the chain.

bool ca_mgm::ValueCheck::m_neg
private

Whether to negate the result of the current chain.

ValueCheckBase* ca_mgm::ValueCheck::m_self
private

Pointer to the current (reference counted) check.


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