Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
Public Types | Public Member Functions | Static Public Member Functions | List of all members
caffa::RangeValidator< DataType > Class Template Reference

Simple range validator. More...

#include <cafFieldValidator.h>

Inheritance diagram for caffa::RangeValidator< DataType >:
Inheritance graph
[legend]
Collaboration diagram for caffa::RangeValidator< DataType >:
Collaboration graph
[legend]

Public Types

using FailureSeverity = FieldValidatorInterface::FailureSeverity
 
- Public Types inherited from caffa::FieldValidator< DataType >
using FailureSeverity = FieldValidatorInterface::FailureSeverity
 
- Public Types inherited from caffa::FieldValidatorInterface
enum class  FailureSeverity { VALIDATOR_WARNING , VALIDATOR_ERROR , VALIDATOR_CRITICAL }
 The severity of failure. Essentially tells the application how to treat a validator failure: VALIDATOR_WARNING -> user warning VALIDATOR_ERROR -> user error VALIDATOR_CRITICAL -> critical application failure.
 

Public Member Functions

 RangeValidator (DataType minimum, DataType maximum, FailureSeverity failureSeverity=FailureSeverity::VALIDATOR_ERROR)
 
void readFromJson (const nlohmann::json &jsonFieldObject, const caffa::Serializer &serializer) override
 Read the validator from JSON. More...
 
void writeToJson (nlohmann::json &jsonFieldObject, const caffa::Serializer &serializer) const override
 Write the validator to JSON. More...
 
std::pair< bool, std::string > validate (const DataType &value) const override
 Validate the value. More...
 
- Public Member Functions inherited from caffa::FieldValidator< DataType >
 FieldValidator (FailureSeverity failureSeverity=FailureSeverity::VALIDATOR_ERROR)
 
- Public Member Functions inherited from caffa::FieldValidatorInterface
 FieldValidatorInterface (FailureSeverity failureSeverity)
 Construct a new Field Validator Interface object. More...
 
FailureSeverity failureSeverity () const
 Get the severity of a failure of the validator. More...
 

Static Public Member Functions

static std::unique_ptr< RangeValidator< DataType > > create (DataType minimum, DataType maximum, FailureSeverity failureSeverity=FailureSeverity::VALIDATOR_ERROR)
 

Detailed Description

template<typename DataType>
class caffa::RangeValidator< DataType >

Simple range validator.

Template Parameters
DataType

Member Function Documentation

◆ readFromJson()

template<typename DataType >
void caffa::RangeValidator< DataType >::readFromJson ( const nlohmann::json &  jsonFieldObject,
const caffa::Serializer serializer 
)
inlineoverridevirtual

Read the validator from JSON.

Parameters
jsonFieldObjectthe JSON value to read from
serializerthe serializer object

Implements caffa::FieldValidatorInterface.

◆ validate()

template<typename DataType >
std::pair<bool, std::string> caffa::RangeValidator< DataType >::validate ( const DataType &  value) const
inlineoverridevirtual

Validate the value.

Parameters
valueThe value to validate
Returns
true if the value is acceptable
false if not

Implements caffa::FieldValidator< DataType >.

◆ writeToJson()

template<typename DataType >
void caffa::RangeValidator< DataType >::writeToJson ( nlohmann::json &  jsonFieldObject,
const caffa::Serializer serializer 
) const
inlineoverridevirtual

Write the validator to JSON.

Parameters
jsonFieldObjectto JSON value to write to.
serializerthe serializer object

Implements caffa::FieldValidatorInterface.


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