Open Lighting Architecture: common/web/SchemaParser.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
SchemaParser.h
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * SchemaParser.h
17 * Constructs a JsonSchema.
18 * Copyright (C) 2014 Simon Newton
19 */
20
21#ifndef COMMON_WEB_SCHEMAPARSER_H_
22#define COMMON_WEB_SCHEMAPARSER_H_
23
24
25#include <memory>
26#include <stack>
27#include <string>
28
29#include "common/web/PointerTracker.h"
30#include "common/web/SchemaErrorLogger.h"
31#include "common/web/SchemaParseContext.h"
32#include "ola/base/Macro.h"
33#include "ola/web/JsonLexer.h"
34#include "ola/web/JsonPointer.h"
35
36namespace ola {
37namespace web {
38
49 class SchemaParser : public JsonParserInterface {
50 public:
54 SchemaParser();
55
59 ~SchemaParser();
60
61 // Methods from JsonParserInterface
62 void Begin();
63 void End();
64 void String(const std::string &value);
65 void Number(uint32_t value);
66 void Number(int32_t value);
67 void Number(uint64_t value);
68 void Number(int64_t value);
69 void Number(const JsonDouble::DoubleRepresentation &rep);
70 void Number(double value);
71 void Bool(bool value);
72 void Null();
73 void OpenArray();
74 void CloseArray();
75 void OpenObject();
76 void ObjectKey(const std::string &key);
77 void CloseObject();
78 void SetError(const std::string &error);
79
84 bool IsValidSchema();
85
89 std::string Error() const;
90
96 ValidatorInterface* ClaimRootValidator();
97
103 SchemaDefinitions* ClaimSchemaDefs();
104
105 private:
106 std::auto_ptr<SchemaDefinitions> m_schema_defs;
107 std::auto_ptr<SchemaParseContext> m_root_context;
108
109 std::auto_ptr<ValidatorInterface> m_root_validator;
110
111 std::stack<class SchemaParseContextInterface*> m_context_stack;
112 JsonPointer m_pointer;
113 PointerTracker m_pointer_tracker;
114 SchemaErrorLogger m_error_logger;
115
116 template <typename T>
117 void HandleNumber(T t);
118
119 SchemaParser(const SchemaParser &) = delete;
120 const SchemaParser &operator=(const SchemaParser &) = delete;
121};
122} // namespace web
123} // namespace ola
124#endif // COMMON_WEB_SCHEMAPARSER_H_
JsonLexer.h
The class used to parse JSON data.
JsonPointer.h
An implementation of Json Pointers (RFC 6901).
Macro.h
Helper macros.
ola::web::JsonPointer
A JSON pointer (RFC 6901) refers to a possible element in a JSON data structure.
Definition JsonPointer.h:66
ola::web::PointerTracker
Maintains a Json Pointer (RFC 6901) given a set of Json parse events.
Definition PointerTracker.h:77
ola::web::SchemaDefinitions
Definition JsonSchema.h:960
ola::web::SchemaErrorLogger
The SchemaErrorLogger captures errors while parsing the schema.
Definition SchemaErrorLogger.h:41
ola::web::SchemaParser::SetError
void SetError(const std::string &error)
Can be called at any time to indicate an error with the input data.
Definition SchemaParser.cpp:225
ola::web::SchemaParser::Bool
void Bool(bool value)
Called when a bool is encountered.
Definition SchemaParser.cpp:96
ola::web::SchemaParser::OpenArray
void OpenArray()
Called when an array starts.
Definition SchemaParser.cpp:134
ola::web::SchemaParser::Number
void Number(uint32_t value)
Called when a uint32_t is encountered.
Definition SchemaParser.cpp:70
ola::web::SchemaParser::End
void End()
Called when parsing completes.
Definition SchemaParser.cpp:49
ola::web::SchemaParser::CloseObject
void CloseObject()
Called when an object completes.
Definition SchemaParser.cpp:206
ola::web::SchemaParser::Null
void Null()
Called when a null token is encountered.
Definition SchemaParser.cpp:115
ola::web::SchemaParser::OpenObject
void OpenObject()
Called when an object starts.
Definition SchemaParser.cpp:170
ola::web::SchemaParser::ObjectKey
void ObjectKey(const std::string &key)
Called when a new key is encountered.
Definition SchemaParser.cpp:192
ola::web::SchemaParser::String
void String(const std::string &value)
Called when a string is encountered.
Definition SchemaParser.cpp:51
ola::web::SchemaParser::ClaimSchemaDefs
SchemaDefinitions * ClaimSchemaDefs()
Claim the SchemaDefinitions that were created by parsing the schema.
Definition SchemaParser.cpp:241
ola::web::SchemaParser::ClaimRootValidator
ValidatorInterface * ClaimRootValidator()
Claim the RootValidator that was created by parsing the schema.
Definition SchemaParser.cpp:237
ola::web::SchemaParser::Begin
void Begin()
Called when parsing begins.
Definition SchemaParser.cpp:41
ola::web::SchemaParser::Error
std::string Error() const
Get the error message.
Definition SchemaParser.cpp:233
ola::web::SchemaParser::CloseArray
void CloseArray()
Called when an array completes.
Definition SchemaParser.cpp:155
ola::web::SchemaParser::IsValidSchema
bool IsValidSchema()
Check if the schema was valid.
Definition SchemaParser.cpp:229
ola::web::SchemaParser::~SchemaParser
~SchemaParser()
Clean up.
Definition SchemaParser.cpp:39
ola::web::SchemaParser::SchemaParser
SchemaParser()
Create a new SchemaParser.
Definition SchemaParser.cpp:33
ola::web::ValidatorInterface
The interface Json Schema Validators.
Definition JsonSchema.h:56
ola::web
Classes to deal with web services.
Definition Json.cpp:29
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::web::JsonDouble::DoubleRepresentation
Represents a JSON double value broken down as separate components.
Definition Json.h:666