Parsnip
parsing library
Loading...
Searching...
No Matches
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends
Parsnip::SchemaBase Class Referenceabstract
Inheritance diagram for Parsnip::SchemaBase:
Parsnip::RangeSchema< long > Parsnip::ConjunctionSchema Parsnip::DictionarySchema Parsnip::KeywordSchema Parsnip::ListSchema Parsnip::OptionSchema Parsnip::RangeSchema< NumericType > Parsnip::StringSchema Parsnip::TypeSchema Parsnip::UncheckedSchema

Public Member Functions

virtual SchemaBasecreateCopy () const =0
 Create an identical, deep copy of the schema.
 
virtual void validate (const Parsnip::Data &entry) const =0
 Verify that Data matches the schema.
 
virtual bool operator== (const SchemaBase &other) const
 Check if two schemas perform the same validation.
 
bool operator!= (const SchemaBase &other) const
 
virtual void mergeSchemas (const SchemaBase &from)
 Merge elements into the current schema.
 
virtual std::ostream & dump (std::ostream &target, int indent, bool suppress_indent=false) const =0
 Render the schema in human-friendly text.
 

Protected Types

using StringType = Data::StringType
 
using SchemaRegex = std::basic_regex< StringType::value_type >
 

Protected Member Functions

 SchemaBase (const SchemaBase &)=default
 
 SchemaBase (SchemaBase &&)=default
 
SchemaBaseoperator= (const SchemaBase &)=default
 
SchemaBaseoperator= (SchemaBase &&)=default
 
 SchemaBase (const Parsnip::Data &schema_spec)
 Construct a schema from a JSON specification.
 
void checkType (Data::Type expected, const Parsnip::Data &entry) const
 Check that Data item is an allowed type.
 
bool isValidlyNull (const Parsnip::Data &entry) const
 Determine if the data is Null and if that is allowed.
 
bool isType (Data::Type expected, const Parsnip::Data &entry) const
 Check if a data object is a particular type.
 

Protected Attributes

bool nullable = false
 If true, element may be null.
 

Friends

class ListSchema
 

Constructor & Destructor Documentation

◆ SchemaBase()

Parsnip::SchemaBase::SchemaBase ( const Parsnip::Data schema_spec)
protected

Construct a schema from a JSON specification.

Parameters
schema_specThe schema specification.

Member Function Documentation

◆ checkType()

void Parsnip::SchemaBase::checkType ( Data::Type  expected,
const Parsnip::Data entry 
) const
inlineprotected

Check that Data item is an allowed type.

If nullable, it must be the expected type or null. If not nullable it must be the expected type.

Parameters
expectedThe expected datatype.
entryThe Data item to check.

◆ createCopy()

virtual SchemaBase * Parsnip::SchemaBase::createCopy ( ) const
pure virtual

◆ dump()

virtual std::ostream & Parsnip::SchemaBase::dump ( std::ostream &  target,
int  indent,
bool  suppress_indent = false 
) const
pure virtual

Render the schema in human-friendly text.

Parameters
targetWhere to write the schema.
indentAmount of indent to use.
suppress_indentFlag indicating indent was already performed.

Implemented in Parsnip::UncheckedSchema, Parsnip::TypeSchema, Parsnip::StringSchema, Parsnip::RegExSchema, Parsnip::KeywordSchema, Parsnip::RangeSchema< NumericType >, Parsnip::RangeSchema< long >, Parsnip::OptionSchema, Parsnip::ListSchema, Parsnip::DictionarySchema, and Parsnip::ConjunctionSchema.

◆ isType()

bool Parsnip::SchemaBase::isType ( Data::Type  expected,
const Parsnip::Data entry 
) const
inlineprotected

Check if a data object is a particular type.

Parameters
expectedThe type to compare to.
entryThe data item to check.
Returns
True if entry's datatype is expected, false otherwise.

◆ isValidlyNull()

bool Parsnip::SchemaBase::isValidlyNull ( const Parsnip::Data entry) const
inlineprotected

Determine if the data is Null and if that is allowed.

Parameters
entryThe data to validate.
Returns
True if the data is null, and the schema allows it.

◆ mergeSchemas()

void Parsnip::SchemaBase::mergeSchemas ( const SchemaBase from)
virtual

Merge elements into the current schema.

Merge elements managed by this class.

  • Elements seen every time are mandatory.
  • Elements seen only sometime are optional.
  • Elements always seen together are codependent.
  • Elements must always expect similar types, except they may vary as element and list-of-same-element.
    Parameters
    fromA schema for a valid command command line.
    Exceptions
    Variousexceptions.

Reimplemented in Parsnip::TypeSchema, Parsnip::KeywordSchema, Parsnip::RangeSchema< NumericType >, Parsnip::RangeSchema< long >, Parsnip::OptionSchema, Parsnip::ListSchema, and Parsnip::DictionarySchema.

◆ operator==()

bool Parsnip::SchemaBase::operator== ( const SchemaBase other) const
virtual

Check if two schemas perform the same validation.

Compare two schemas to see if they determine validity in the same manner.

Parameters
otherThe schema to compare to.
Returns
True if the schemas match, false otherwise.

Reimplemented in Parsnip::TypeSchema, Parsnip::StringSchema, Parsnip::RegExSchema, Parsnip::KeywordSchema, Parsnip::RangeSchema< NumericType >, Parsnip::RangeSchema< long >, Parsnip::IntegerSchema, Parsnip::OptionSchema, Parsnip::ListSchema, Parsnip::DictionarySchema, and Parsnip::ConjunctionSchema.

◆ validate()

virtual void Parsnip::SchemaBase::validate ( const Parsnip::Data entry) const
pure virtual

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