COMMS
Template library intended to help with implementation of communication protocols.
comms::option::def::ContentsValidator< T > Struct Template Reference

#include "comms/options.h"

Detailed Description

template<typename T>
struct comms::option::def::ContentsValidator< T >

Option that specifies custom validation class.

By default, value of every field is considered to be valid (valid() member function of the field returns true). If there is a need to validate the value of the function, use this option to define custom validation logic for the field. The validation class provided as a template argument to this option must define the following member function:

struct MyValidator
{
template <typename TField>
bool operator()(const TField& field) {...}
};

For example, value of the string field considered to be valid if it's not empty and starts with '$' character. The provided validator class with the option will be instantiated and its operator() will be invoked.

struct MyStringValidator
{
template <typename TField>
bool operator()(TField& field) const
{
auto& str = field.value();
return (!str.empty()) && (str[0] == '$');
}
};
using MyField =
MyFieldBase,
>;
Base class to all the field classes.
Definition: Field.h:33
Field that represents a string.
Definition: String.h:159
Option that specifies custom validation class.
Definition: options.h:662

Note that in the example above the default constructed MyField will have invalid value. To fix that you must also use comms::option::def::DefaultValueInitialiser option to specify proper default value.

Note
Direct usage of this option in the client code is not recommended. It's should be used for internal validators like comms::option::def::BitmaskReservedBits
Template Parameters
TType of the validator class.

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