Parsnip
parsing library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Data Fields
Parsnip::SchemaSet Class Reference

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

#include <parsnip_command.h>

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

Data Fields

OptionSchemas option_schemas
 Schemas for each of the option parsers.
 

Detailed Description

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

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.

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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

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