Parsnip
parsing library
Loading...
Searching...
No Matches
Data Structures | Public Types | Public Member Functions | Static Public Attributes | Protected Types | Protected Attributes | Friends
Parsnip::DictionarySchema Class Reference

Schema component for validating dictionaries. More...

#include <parsnip_schema.h>

Inheritance diagram for Parsnip::DictionarySchema:
Parsnip::SchemaBase

Data Structures

class  DictionaryMember
 

Public Types

using Dependencies = std::set< std::string >
 
using size_type = unsigned int
 

Public Member Functions

 DictionarySchema (const DictionarySchema &)=default
 
 DictionarySchema (DictionarySchema &&)=default
 
DictionarySchemaoperator= (const DictionarySchema &)=default
 
DictionarySchemaoperator= (DictionarySchema &&)=default
 
 DictionarySchema (const Parsnip::Data &schema_spec)
 Construct a dictionary (object) schema from a schema specificiation.
 
virtual DictionarySchemacreateCopy () const override
 Create an identical, deep copy of the schema.
 
void addMember (const char *name, const SchemaBase &schema, bool mandatory=false, const Dependencies &dependencies=NoDependencies)
 Add a member to a dictionary schema.
 
void replaceMember (const char *name, const SchemaBase &schema)
 Replace a member in the schema, retaining original mandatory status and dependencies.
 
void removeMember (const char *name)
 Remove a member from the schema.
 
virtual void validate (const Parsnip::Data &entry) const override
 Validate a dictionary:
 
virtual bool operator== (const SchemaBase &other) const override
 Check if two schemas perform the same validation.
 
virtual void mergeSchemas (const SchemaBase &from) override
 Merge elements into the current schema.
 
virtual std::ostream & dump (std::ostream &target, int indent, bool suppress_ident=false) const override
 Render the schema in human-friendly text.
 
- Public Member Functions inherited from Parsnip::SchemaBase
bool operator!= (const SchemaBase &other) const
 

Static Public Attributes

static const Dependencies NoDependencies
 

Protected Types

enum  AdditionalMemberNames { NONE , ANY , PATTERN }
 
- Protected Types inherited from Parsnip::SchemaBase
using StringType = Data::StringType
 
using SchemaRegex = std::basic_regex< StringType::value_type >
 

Protected Attributes

std::map< std::string, DictionaryMembermembers
 
AdditionalMemberNames tolerance = AdditionalMemberNames::NONE
 Allow unrecognized members in the dictionary?
 
SchemaRegex additional_member_regex
 
SchemaBaseRef additional_member_schema
 
- Protected Attributes inherited from Parsnip::SchemaBase
bool nullable = false
 If true, element may be null.
 

Friends

class ValueEvaluator
 
class RemainingValuesEvaluator
 
class KeywordEvaluator
 
class OptionEvaluator
 

Additional Inherited Members

- Protected Member Functions inherited from Parsnip::SchemaBase
 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.
 

Detailed Description

Schema component for validating dictionaries.

Constructor & Destructor Documentation

◆ DictionarySchema()

Parsnip::DictionarySchema::DictionarySchema ( const Parsnip::Data schema_spec)

Construct a dictionary (object) schema from a schema specificiation.

Parameters
schema_specThe specification.

Member Function Documentation

◆ addMember()

void Parsnip::DictionarySchema::addMember ( const char *  name,
const SchemaBase schema,
bool  mandatory = false,
const Dependencies &  dependencies = NoDependencies 
)

Add a member to a dictionary schema.

Parameters
nameThe name of the member to add.
schemaThe schema for the new member.
mandatoryIf true, the member must be present for the dictionary to be valid.
dependenciesAny members that must be present when the new member is present.

◆ createCopy()

DictionarySchema * Parsnip::DictionarySchema::createCopy ( ) const
overridevirtual

Create an identical, deep copy of the schema.

Caller is responsible for deleting it.

Implements Parsnip::SchemaBase.

◆ dump()

std::ostream & Parsnip::DictionarySchema::dump ( std::ostream &  target,
int  indent,
bool  suppress_indent = false 
) const
overridevirtual

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.

Implements Parsnip::SchemaBase.

◆ mergeSchemas()

void Parsnip::DictionarySchema::mergeSchemas ( const SchemaBase from)
overridevirtual

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 from Parsnip::SchemaBase.

◆ operator==()

bool Parsnip::DictionarySchema::operator== ( const SchemaBase other) const
overridevirtual

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 from Parsnip::SchemaBase.

◆ removeMember()

void Parsnip::DictionarySchema::removeMember ( const char *  name)

Remove a member from the schema.

Parameters
nameThe member to remove.

◆ replaceMember()

void Parsnip::DictionarySchema::replaceMember ( const char *  name,
const SchemaBase schema 
)

Replace a member in the schema, retaining original mandatory status and dependencies.

Parameters
nameThe member to revise.
schemaThe replacement schema for the member.

◆ validate()

void Parsnip::DictionarySchema::validate ( const Parsnip::Data entry) const
overridevirtual

Validate a dictionary:

  • Check all elements conform to their respected schema.
  • Ensure all mandatory elements are present.
  • Ensure there are no unknown elements present.
  • Make sure any co-dependent keys are present.

Implements Parsnip::SchemaBase.


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