Elementa v8.0.0
Minimalistic library for any C++ application (C++11 and up)
Loading...
Searching...
No Matches
Validatable

Description


To declare classes that has a valid state.

Usage:

Author
Juan-Antonio Fernandez-Madrigal. http://jafma.net
Date
2018-2019
Collaboration diagram for Validatable:

Classes

class  elementa::patterns::Validatable
 Any class derived from this base class gets a "valid"/"invalid" state. More...
 

Macros

#define ELE_CLASS_VALIDATABLE   virtual public elementa::patterns::Validatable
 Declare a class derived from Validatable. More...
 

Class Documentation

◆ elementa::patterns::Validatable

class elementa::patterns::Validatable

Any class derived from this base class gets a "valid"/"invalid" state.

The "valid"/"invalid" state can be consulted, being "invalid" by default at the time of object creation if no argument is passed to the Validatable constructor. It can be changed further on becoming a form of the Builder pattern

Derived classes may provide public methods that admit as many args as needed to define the object as valid (it must call the setValid() method here to set the object as valid).

Note
- This class is thread-safe.
- It cannot be implemented with mixins (i.e., a template that inherits from a class to convert it into validatable) because in that case the user's class could not access the valid_ value in the mixin base.

Definition at line 99 of file validatable.h.

Public Member Functions

bool valid (void) const noexcept
 Public method to be used by users of the derived class. More...
 
virtual void checkValid (const std::string &place="") const
 Call this method if an exception is needed when in invalid state. More...
 

Protected Member Functions

 Validatable (bool initvalid=false) noexcept
 
 Validatable (const Validatable &oth)
 Derived classes must call this base ctor if they have non-default ones. More...
 
Validatableoperator= (const Validatable &oth)
 Derived classes must call this base optor if they have non-default ones. More...
 
void setValid (bool defval=true) noexcept
 Derived classes can rewrite their own (hiding this, calling this). More...
 
void setInvalid (void) noexcept
 

Constructor & Destructor Documentation

◆ Validatable() [1/2]

elementa::patterns::Validatable::Validatable ( bool  initvalid = false)
inlineprotectednoexcept

Definition at line 119 of file validatable.h.

◆ Validatable() [2/2]

elementa::patterns::Validatable::Validatable ( const Validatable oth)
inlineprotected

Derived classes must call this base ctor if they have non-default ones.

A default copy ctor in derived class automatically calls this one.

Note
No move constructor is provided, only copy one, for the reasons explained in the operator=. This means that Validatable objects are never moved, only copied.

Definition at line 126 of file validatable.h.

Member Function Documentation

◆ valid()

bool elementa::patterns::Validatable::valid ( void  ) const
inlinenoexcept

Public method to be used by users of the derived class.

The derived class itself can use the valid_ member directly, plus any other protected member.

Definition at line 106 of file validatable.h.

Referenced by elementa::base::MultItImpl< Data >::to_string().

◆ checkValid()

virtual void elementa::patterns::Validatable::checkValid ( const std::string &  place = "") const
inlinevirtual

Call this method if an exception is needed when in invalid state.

You can also override it if more info in the error is needed.

Definition at line 110 of file validatable.h.

References ELE_CODE_INVSTATE.

◆ operator=()

Validatable & elementa::patterns::Validatable::operator= ( const Validatable oth)
inlineprotected

Derived classes must call this base optor if they have non-default ones.

A default assign optor in derived class automatically calls this one.

Note
Move assignment is not provided (it will fall through to a copy-assign) because of the problem of having Validatable accessable through several paths from the derived class: that will produce several calls of the move assignment that leave the Validatable state incorrect. Actually, that produces a compiler warning [-Wmultiple-move-vbase] in g++.

Definition at line 135 of file validatable.h.

Referenced by elementa::adts::graphs::Graph< Vertex, Edge >::eenteringend().

◆ setValid()

void elementa::patterns::Validatable::setValid ( bool  defval = true)
inlineprotectednoexcept

Derived classes can rewrite their own (hiding this, calling this).

Definition at line 144 of file validatable.h.

◆ setInvalid()

void elementa::patterns::Validatable::setInvalid ( void  )
inlineprotectednoexcept

Definition at line 146 of file validatable.h.

Macro Definition Documentation

◆ ELE_CLASS_VALIDATABLE

#define ELE_CLASS_VALIDATABLE   virtual public elementa::patterns::Validatable

#include <elementa/patterns/validatable.h>

Declare a class derived from Validatable.

Definition at line 82 of file validatable.h.