Parsnip
parsing library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Friends
Parsnip::Schema Class Reference

Schema for one JSON object. More...

#include <parsnip.h>

Public Types

using OptionSchemas = std::unordered_map< class OptionParser *, SchemaRef >
 
using Dependencies = std::set< std::string >
 

Public Member Functions

 Schema (const class OptionParser &from, const OptionSchemas &option_schemas)
 
 Schema (Schema &&)=default
 
Schemaoperator= (Schema &&)=default
 
 Schema (const Parsnip::Data &schema_spec)
 Construct a schema that has been defined in JSON.
 
void addMember (const char *name, const SchemaBase &new_schema, bool mandatory=false, const Dependencies &dependencies=NoDependencies)
 Modify a schema by adding a new dictionary member.
 
void replaceMember (const char *name, const SchemaBase &new_schema)
 Modify a schema by replacing dictionary member.
 
void removeMember (const char *name)
 Modify a schema by removing a dictionary member.
 
void validate (const Data &) const
 Validate data against the schema.
 
std::ostream & dump (const std::string &intro, std::ostream &target=std::clog) const
 Dump the schema in human-readable format.
 

Static Public Attributes

static const Dependencies NoDependencies
 

Friends

class OptionSchema
 

Detailed Description

Schema for one JSON object.

Constructor & Destructor Documentation

◆ Schema()

Parsnip::Schema::Schema ( const Parsnip::Data schema_spec)

Construct a schema that has been defined in JSON.

See also
: http://json-schema.org
Parameters
schema_specThe schema specification.

Member Function Documentation

◆ addMember()

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

Modify a schema by adding a new dictionary member.

Parameters
nameThe dictionary member to add.
new_schemaThe schema for the new member.
mandatoryIf true, the member must be present for dictionaries to be valid.
dependenciesThe names of other properties that must also be present when this one is.

◆ dump()

std::ostream & Parsnip::Schema::dump ( const std::string &  intro,
std::ostream &  target = std::clog 
) const

Dump the schema in human-readable format.

Parameters
introA label for the schema.
targetA stream to which to render.

◆ removeMember()

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

Modify a schema by removing a dictionary member.

Parameters
nameThe dictionary member to remove.

◆ replaceMember()

void Parsnip::Schema::replaceMember ( const char *  name,
const SchemaBase new_schema 
)

Modify a schema by replacing dictionary member.

Mandatory status and dependencies are unchanged.

Parameters
nameThe dictionary member to replace.
new_schemaThe replacement schema.

◆ validate()

void Parsnip::Schema::validate ( const Data data) const

Validate data against the schema.

Parameters
dataThe data to be validated. `
Exceptions
Exceptionsrepresenting the manner of data non-conformance.

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