Electroneum
GenericSchemaDocument< ValueT, Allocator > Class Template Reference

JSON schema document. More...

#include <fwd.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, Allocator > PointerType
 
typedef GenericValue< EncodingType, Allocator > URIType
 

Public Member Functions

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

Friends

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

Detailed Description

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

JSON schema document.

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 136 of file fwd.h.

Member Typedef Documentation

◆ AllocatorType

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

Definition at line 1503 of file schema.h.

◆ Ch

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

Definition at line 1505 of file schema.h.

◆ EncodingType

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

Definition at line 1504 of file schema.h.

◆ IRemoteSchemaDocumentProviderType

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

Definition at line 1502 of file schema.h.

◆ PointerType

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

Definition at line 1507 of file schema.h.

◆ SchemaType

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

Definition at line 1506 of file schema.h.

◆ URIType

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

Definition at line 1508 of file schema.h.

◆ ValueType

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

Definition at line 1501 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

Constructor.

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 1523 of file schema.h.

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

◆ ~GenericSchemaDocument()

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

Destructor.

Definition at line 1589 of file schema.h.

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

Member Function Documentation

◆ GetRoot()

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

Get the root schema.

Definition at line 1604 of file schema.h.

1604 { return *root_; }

◆ GetURI()

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

Definition at line 1601 of file schema.h.

1601 { return uri_; }

Friends And Related Function Documentation

◆ GenericSchemaValidator

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

Definition at line 1511 of file schema.h.

◆ internal::Schema< GenericSchemaDocument >

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

Definition at line 1509 of file schema.h.


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