pianod2
multisource multiuser scriptable networked music player
Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
Parsnip::Schema Class Reference

Schema for one JSON object. More...

#include <parsnip.h>

Collaboration diagram for Parsnip::Schema:
Collaboration graph
[legend]

Public Types

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

Public Member Functions

 Schema ()=default
 
 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. More...
 
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. More...
 
void replaceMember (const char *name, const SchemaBase &new_schema)
 Modify a schema by replacing dictionary member. More...
 
void removeMember (const char *name)
 Modify a schema by removing a dictionary member. More...
 
void validate (const Data &) const
 Validate data against the schema. More...
 
std::ostream & dump (const std::string &intro, std::ostream &target=std::clog) const
 Dump the schema in human-readable format. More...
 

Static Public Attributes

static const Dependencies NoDependencies
 

Private Member Functions

void integrateSchema (const int, const class DictionarySchema &)
 Callback function, invoked when generating schemas from an OptionParser. More...
 
std::ostream & dump (std::ostream &target, int indent, bool suppress_indent) const
 
 Schema (SchemaBase *from)
 Construct a schema manually. More...
 

Private Attributes

SchemaBaseRef schema
 

Friends

class OptionSchema
 

Detailed Description

Schema for one JSON object.

Member Typedef Documentation

◆ Dependencies

using Parsnip::Schema::Dependencies = std::set <std::string>

◆ OptionSchemas

using Parsnip::Schema::OptionSchemas = std::unordered_map <class OptionParser *, SchemaRef>

Constructor & Destructor Documentation

◆ Schema() [1/5]

Parsnip::Schema::Schema ( SchemaBase from)
private

Construct a schema manually.

Parameters
fromManually assembled schema components.

◆ Schema() [2/5]

Parsnip::Schema::Schema ( )
default

◆ Schema() [3/5]

Parsnip::Schema::Schema ( const class OptionParser from,
const OptionSchemas option_schemas 
)

◆ Schema() [4/5]

Parsnip::Schema::Schema ( Schema &&  )
default

◆ Schema() [5/5]

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.
Here is the call graph for this function:

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.
Here is the call graph for this function:

◆ dump() [1/2]

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.

◆ dump() [2/2]

std::ostream & Parsnip::Schema::dump ( std::ostream &  target,
int  indent,
bool  suppress_indent 
) const
private

Dump the schema in human-readable format.

Parameters
targetA stream to which to render.
indentThe amount of indentation to use.
suppress_indentIf true, indentation is not done on the first line.
Here is the caller graph for this function:

◆ integrateSchema()

void Parsnip::Schema::integrateSchema ( const int  ,
const class DictionarySchema command 
)
private

Callback function, invoked when generating schemas from an OptionParser.

Parameters
commandA dataset a valid command would generate.

◆ operator=()

Schema& Parsnip::Schema::operator= ( Schema &&  )
default

◆ removeMember()

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

Modify a schema by removing a dictionary member.

Parameters
nameThe dictionary member to remove.
Here is the call graph for this function:

◆ 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.
Here is the call graph for this function:

◆ 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.
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ OptionSchema

friend class OptionSchema
friend

Member Data Documentation

◆ NoDependencies

const Schema::Dependencies Parsnip::Schema::NoDependencies
static

◆ schema

SchemaBaseRef Parsnip::Schema::schema
private

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