Open Lighting Architecture  Latest Git
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
36 namespace ola {
37 namespace web {
38 
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);
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 
97 
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  DISALLOW_COPY_AND_ASSIGN(SchemaParser);
120 };
121 } // namespace web
122 } // namespace ola
123 #endif // COMMON_WEB_SCHEMAPARSER_H_
SchemaDefinitions * ClaimSchemaDefs()
Claim the SchemaDefinitions that were created by parsing the schema.
Definition: SchemaParser.cpp:241
Represents a JSON double value broken down as separate components.
Definition: Json.h:661
ValidatorInterface * ClaimRootValidator()
Claim the RootValidator that was created by parsing the schema.
Definition: SchemaParser.cpp:237
The interface used to handle tokens during JSON parsing.
Definition: JsonLexer.h:71
The class used to parse JSON data.
void OpenObject()
Called when an object starts.
Definition: SchemaParser.cpp:170
std::string Error() const
Get the error message.
Definition: SchemaParser.cpp:233
void End()
Called when parsing completes.
Definition: SchemaParser.cpp:49
void Number(uint32_t value)
Called when a uint32_t is encountered.
Definition: SchemaParser.cpp:70
void Null()
Called when a null token is encountered.
Definition: SchemaParser.cpp:115
Definition: JsonSchema.h:946
void SetError(const std::string &error)
Can be called at any time to indicate an error with the input data.
Definition: SchemaParser.cpp:225
void ObjectKey(const std::string &key)
Called when a new key is encountered.
Definition: SchemaParser.cpp:192
void Begin()
Called when parsing begins.
Definition: SchemaParser.cpp:41
Build the tree of validators and a SchemaDefinitions object from a JSON Schema.
Definition: SchemaParser.h:49
void OpenArray()
Called when an array starts.
Definition: SchemaParser.cpp:134
void CloseObject()
Called when an object completes.
Definition: SchemaParser.cpp:206
void String(const std::string &value)
Called when a string is encountered.
Definition: SchemaParser.cpp:51
A JSON pointer (RFC 6901) refers to a possible element in a JSON data structure.
Definition: JsonPointer.h:66
Helper macros.
The interface Json Schema Validators.
Definition: JsonSchema.h:56
void Bool(bool value)
Called when a bool is encountered.
Definition: SchemaParser.cpp:96
An implementation of Json Pointers (RFC 6901).
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
void CloseArray()
Called when an array completes.
Definition: SchemaParser.cpp:155
Maintains a Json Pointer (RFC 6901) given a set of Json parse events.
Definition: PointerTracker.h:77
~SchemaParser()
Clean up.
Definition: SchemaParser.cpp:39
SchemaParser()
Create a new SchemaParser.
Definition: SchemaParser.cpp:33
The SchemaErrorLogger captures errors while parsing the schema.
Definition: SchemaErrorLogger.h:41
bool IsValidSchema()
Check if the schema was valid.
Definition: SchemaParser.cpp:229