3#include "elementa/license.inc"
4#include "elementa/checks.inc"
6#ifndef ELEMENTA_PATTERNS_VALIDATABLE_H
7#define ELEMENTA_PATTERNS_VALIDATABLE_H
82#define ELE_CLASS_VALIDATABLE virtual public elementa::patterns::Validatable
106 bool valid(
void)
const noexcept {
return(valid_); }
110 virtual void checkValid(
const std::string & place =
"")
const
113 "Unspecified operation requested on "
114 "an invalid object" :
119 Validatable(
bool initvalid =
false) noexcept: valid_{initvalid} {}
136 {
if (
this != &oth) copyFrom(oth);
return(*
this); }
144 void setValid(
bool defval =
true) noexcept { valid_ = defval; }
146 void setInvalid(
void)
noexcept { valid_ =
false; }
150 alignas(16) std::atomic<bool> valid_;
157 void copyFrom(
const Validatable & oth)
158 { valid_ = (oth.valid_ ? true :
false); }
160 void moveFrom(Validatable && oth)
161 { copyFrom(oth); oth.valid_ =
false; }
#define ELE_CODE_INVSTATE(expl)
To throw an invalid-state exception with an explanation.
Validatable(const Validatable &oth)
Derived classes must call this base ctor if they have non-default ones.
Validatable & operator=(const Validatable &oth)
Derived classes must call this base optor if they have non-default ones.
bool valid(void) const noexcept
Public method to be used by users of the derived class.
virtual void checkValid(const std::string &place="") const
Call this method if an exception is needed when in invalid state.
void setValid(bool defval=true) noexcept
Derived classes can rewrite their own (hiding this, calling this).
Any class derived from this base class gets a "valid"/"invalid" state.