Open Lighting Architecture  0.9.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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_