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

A schema built to validate JSON messages based on command line patterns. More...

#include <parsnip_command.h>

Inheritance diagram for Parsnip::SchemaSet:
Inheritance graph
[legend]

Public Types

using CommandId = int
 
using CommandSchemas = std::unordered_map< CommandId, SchemaBaseRef >
 
using OptionSchemas = Schema::OptionSchemas
 
using Dependencies = Schema::Dependencies
 

Public Member Functions

 SchemaSet (const class Parser &from)
 Construct schemas from a parser. More...
 
void validate (const CommandId, const Data &) const
 Validate data against a command's schema. More...
 
std::ostream & dump (const std::string &intro, const CommandId command_id, std::ostream &target=std::clog) const
 Dump the schema in human-readable format. More...
 
void addMember (const CommandId, const char *name, const SchemaBase &schema, bool mandatory=false, const Dependencies &dependencies=Schema::NoDependencies)
 Modify a schema by adding a new dictionary member. More...
 
void addMember (const char *name, const SchemaBase &schema, bool mandatory=false, const Dependencies &dependencies=Schema::NoDependencies)
 Add member to every schema in the schema set. More...
 
void replaceMember (const CommandId, const char *name, const SchemaBase &schema)
 Modify a schema by replacing dictionary member. More...
 
void removeMember (const CommandId, const char *name)
 Modify a schema by removing a dictionary member. More...
 

Public Attributes

OptionSchemas option_schemas
 Schemas for each of the option parsers. More...
 

Private Member Functions

void integrateSchema (const int, const class DictionarySchema &)
 Callback function, invoked when generating schemas from a Parser. More...
 
SchemaBaseRefgetSchemaForCommand (CommandId command_id)
 Get a schema by ID. More...
 
const SchemaBaseRefgetSchemaForCommand (CommandId command_id) const
 Constipated variant of this function. More...
 

Private Attributes

CommandSchemas schemas
 Schemas for each unique command ID. More...
 

Detailed Description

A schema built to validate JSON messages based on command line patterns.

Member Typedef Documentation

◆ CommandId

◆ CommandSchemas

◆ Dependencies

◆ OptionSchemas

Constructor & Destructor Documentation

◆ SchemaSet()

Parsnip::SchemaSet::SchemaSet ( const class Parser from)

Construct schemas from a parser.

This first constructs schemas for all its option parsers, then generates the schema for the parser itself.

Parameters
fromThe parser for which schemas are being generated.
Here is the call graph for this function:

Member Function Documentation

◆ addMember() [1/2]

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

Add member to every schema in the schema set.

Parameters
nameThe dictionary member to add.
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:

◆ addMember() [2/2]

void Parsnip::SchemaSet::addMember ( const CommandId  command_id,
const char *  name,
const SchemaBase schema,
bool  mandatory = false,
const Dependencies dependencies = Schema::NoDependencies 
)

Modify a schema by adding a new dictionary member.

Parameters
command_idThe command number to modify.
nameThe dictionary member to add.
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:
Here is the caller graph for this function:

◆ dump()

std::ostream & Parsnip::SchemaSet::dump ( const std::string &  intro,
const CommandId  command_id,
std::ostream &  target = std::clog 
) const

Dump the schema in human-readable format.

Parameters
introA label for the schema.
command_idThe ID of the command to render.
targetA stream to which to render.
Here is the call graph for this function:

◆ getSchemaForCommand() [1/2]

SchemaBaseRef & Parsnip::SchemaSet::getSchemaForCommand ( CommandId  command_id)
private

Get a schema by ID.

Parameters
command_idThe command ID.
Returns
The schema.
Exceptions
NoSchemaDefinedif there is no schema for command.
Here is the caller graph for this function:

◆ getSchemaForCommand() [2/2]

const SchemaBaseRef & Parsnip::SchemaSet::getSchemaForCommand ( CommandId  command_id) const
private

Constipated variant of this function.

◆ integrateSchema()

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

Callback function, invoked when generating schemas from a Parser.

Parameters
command_idThe command ID the dataset represents.
commandA dataset a valid command would generate.
Here is the caller graph for this function:

◆ removeMember()

void Parsnip::SchemaSet::removeMember ( const CommandId  command_id,
const char *  name 
)

Modify a schema by removing a dictionary member.

Parameters
command_idThe command number to modify.
nameThe dictionary member to remove.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ replaceMember()

void Parsnip::SchemaSet::replaceMember ( const CommandId  command_id,
const char *  name,
const SchemaBase schema 
)

Modify a schema by replacing dictionary member.

Mandatory status and dependencies are unchanged.

Parameters
command_idThe command number to modify.
nameThe dictionary member to replace.
schemaThe replacement schema.
Here is the call graph for this function:

◆ validate()

void Parsnip::SchemaSet::validate ( const CommandId  command_id,
const Data data 
) const

Validate data against a command's schema.

Parameters
command_idThe command the data represents.
dataThe data to be validated. `
Exceptions
Exceptionsrepresenting the manner of data non-conformance.
Here is the call graph for this function:

Member Data Documentation

◆ option_schemas

OptionSchemas Parsnip::SchemaSet::option_schemas

Schemas for each of the option parsers.

◆ schemas

CommandSchemas Parsnip::SchemaSet::schemas
private

Schemas for each unique command ID.


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