Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
GenericSchemaDocument< ValueT, Allocator > Class Template Reference

JSON schema document. More...

#include <schema.h>

Public Types

typedef ValueT ValueType
 
typedef IGenericRemoteSchemaDocumentProvider< GenericSchemaDocumentIRemoteSchemaDocumentProviderType
 
typedef Allocator AllocatorType
 
typedef ValueType::EncodingType EncodingType
 
typedef EncodingType::Ch Ch
 
typedef internal::Schema< GenericSchemaDocumentSchemaType
 
typedef GenericPointer< ValueType, AllocatorPointerType
 
typedef GenericValue< EncodingType, AllocatorURIType
 

Public Member Functions

 GenericSchemaDocument (const ValueType &document, const Ch *uri=0, SizeType uriLength=0, IRemoteSchemaDocumentProviderType *remoteProvider=0, Allocator *allocator=0)
 Constructor.
 
 ~GenericSchemaDocument ()
 Destructor.
 
const URITypeGetURI () const
 
const SchemaTypeGetRoot () const
 Get the root schema.
 

Friends

class internal::Schema< GenericSchemaDocument >
 
template<typename , typename , typename >
class GenericSchemaValidator
 

Detailed Description

template<typename ValueT, typename Allocator = CrtAllocator>
class GenericSchemaDocument< ValueT, Allocator >

A JSON schema document is a compiled version of a JSON schema. It is basically a tree of internal::Schema.

Note
This is an immutable class (i.e. its instance cannot be modified after construction).
Template Parameters
ValueTType of JSON value (e.g. Value ), which also determine the encoding.
AllocatorAllocator type for allocating memory of this document.

Definition at line 1501 of file schema.h.

Member Typedef Documentation

◆ AllocatorType

template<typename ValueT , typename Allocator = CrtAllocator>
Allocator GenericSchemaDocument< ValueT, Allocator >::AllocatorType

Definition at line 1505 of file schema.h.

◆ Ch

template<typename ValueT , typename Allocator = CrtAllocator>
EncodingType::Ch GenericSchemaDocument< ValueT, Allocator >::Ch

Definition at line 1507 of file schema.h.

◆ EncodingType

template<typename ValueT , typename Allocator = CrtAllocator>
ValueType::EncodingType GenericSchemaDocument< ValueT, Allocator >::EncodingType

Definition at line 1506 of file schema.h.

◆ IRemoteSchemaDocumentProviderType

template<typename ValueT , typename Allocator = CrtAllocator>
IGenericRemoteSchemaDocumentProvider<GenericSchemaDocument> GenericSchemaDocument< ValueT, Allocator >::IRemoteSchemaDocumentProviderType

Definition at line 1504 of file schema.h.

◆ PointerType

template<typename ValueT , typename Allocator = CrtAllocator>
GenericPointer<ValueType, Allocator> GenericSchemaDocument< ValueT, Allocator >::PointerType

Definition at line 1509 of file schema.h.

◆ SchemaType

template<typename ValueT , typename Allocator = CrtAllocator>
internal::Schema<GenericSchemaDocument> GenericSchemaDocument< ValueT, Allocator >::SchemaType

Definition at line 1508 of file schema.h.

◆ URIType

template<typename ValueT , typename Allocator = CrtAllocator>
GenericValue<EncodingType, Allocator> GenericSchemaDocument< ValueT, Allocator >::URIType

Definition at line 1510 of file schema.h.

◆ ValueType

template<typename ValueT , typename Allocator = CrtAllocator>
ValueT GenericSchemaDocument< ValueT, Allocator >::ValueType

Definition at line 1503 of file schema.h.

Constructor & Destructor Documentation

◆ GenericSchemaDocument()

template<typename ValueT , typename Allocator = CrtAllocator>
GenericSchemaDocument< ValueT, Allocator >::GenericSchemaDocument ( const ValueType & document,
const Ch * uri = 0,
SizeType uriLength = 0,
IRemoteSchemaDocumentProviderType * remoteProvider = 0,
Allocator * allocator = 0 )
inlineexplicit

Compile a JSON document into schema document.

Parameters
documentA JSON document as source.
uriThe base URI of this schema document for purposes of violation reporting.
uriLengthLength of name, in code points.
remoteProviderAn optional remote schema document provider for resolving remote reference. Can be null.
allocatorAn optional allocator instance for allocating memory. Can be null.

Definition at line 1525 of file schema.h.

1526 :
1527 remoteProvider_(remoteProvider),
1528 allocator_(allocator),
1529 ownAllocator_(),
1530 root_(),
1531 typeless_(),
1532 schemaMap_(allocator, kInitialSchemaMapSize),
1533 schemaRef_(allocator, kInitialSchemaRefSize)
1534 {
1535 if (!allocator_)
1536 ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
1537
1538 Ch noUri[1] = {0};
1539 uri_.SetString(uri ? uri : noUri, uriLength, *allocator_);
1540
1541 typeless_ = static_cast<SchemaType*>(allocator_->Malloc(sizeof(SchemaType)));
1542 new (typeless_) SchemaType(this, PointerType(), ValueType(kObjectType).Move(), ValueType(kObjectType).Move(), allocator_);
1543
1544 // Generate root schema, it will call CreateSchema() to create sub-schemas,
1545 // And call AddRefSchema() if there are $ref.
1546 CreateSchemaRecursive(&root_, PointerType(), document, document);
1547
1548 // Resolve $ref
1549 while (!schemaRef_.Empty()) {
1550 SchemaRefEntry* refEntry = schemaRef_.template Pop<SchemaRefEntry>(1);
1551 if (const SchemaType* s = GetSchema(refEntry->target)) {
1552 if (refEntry->schema)
1553 *refEntry->schema = s;
1554
1555 // Create entry in map if not exist
1556 if (!GetSchema(refEntry->source)) {
1557 new (schemaMap_.template Push<SchemaEntry>()) SchemaEntry(refEntry->source, const_cast<SchemaType*>(s), false, allocator_);
1558 }
1559 }
1560 else if (refEntry->schema)
1561 *refEntry->schema = typeless_;
1562
1563 refEntry->~SchemaRefEntry();
1564 }
1565
1566 RAPIDJSON_ASSERT(root_ != 0);
1567
1568 schemaRef_.ShrinkToFit(); // Deallocate all memory for ref
1569 }
internal::Schema< GenericSchemaDocument > SchemaType
Definition schema.h:1508
GenericPointer< ValueType, Allocator > PointerType
Definition schema.h:1509
EncodingType::Ch Ch
Definition schema.h:1507
Concept for allocating, resizing and freeing memory block.
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:406
@ kObjectType
object
Definition rapidjson.h:648
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition rapidjson.h:627
char * s

◆ ~GenericSchemaDocument()

template<typename ValueT , typename Allocator = CrtAllocator>
GenericSchemaDocument< ValueT, Allocator >::~GenericSchemaDocument ( )
inline

Definition at line 1591 of file schema.h.

1591 {
1592 while (!schemaMap_.Empty())
1593 schemaMap_.template Pop<SchemaEntry>(1)->~SchemaEntry();
1594
1595 if (typeless_) {
1596 typeless_->~SchemaType();
1597 Allocator::Free(typeless_);
1598 }
1599
1600 RAPIDJSON_DELETE(ownAllocator_);
1601 }
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition rapidjson.h:631

Member Function Documentation

◆ GetRoot()

template<typename ValueT , typename Allocator = CrtAllocator>
const SchemaType & GenericSchemaDocument< ValueT, Allocator >::GetRoot ( ) const
inline

Definition at line 1606 of file schema.h.

1606{ return *root_; }

◆ GetURI()

template<typename ValueT , typename Allocator = CrtAllocator>
const URIType & GenericSchemaDocument< ValueT, Allocator >::GetURI ( ) const
inline

Definition at line 1603 of file schema.h.

1603{ return uri_; }

Friends And Related Symbol Documentation

◆ GenericSchemaValidator

template<typename ValueT , typename Allocator = CrtAllocator>
template<typename , typename , typename >
friend class GenericSchemaValidator
friend

Definition at line 1513 of file schema.h.

◆ internal::Schema< GenericSchemaDocument >

template<typename ValueT , typename Allocator = CrtAllocator>
friend class internal::Schema< GenericSchemaDocument >
friend

Definition at line 1510 of file schema.h.


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