Updated all header files to new format
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / builder / json-parser-impl.h
1 #ifndef DALI_JSON_PARSER_IMPL_H
2 #define DALI_JSON_PARSER_IMPL_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <list>
25 #include <string>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/devel-api/builder/json-parser.h>
29 #include <dali-toolkit/devel-api/builder/tree-node.h>
30
31 #include <dali-toolkit/internal/builder/builder-get-is.inl.h>
32
33 namespace Dali
34 {
35 namespace Toolkit
36 {
37 namespace Internal
38 {
39 /*
40  * Parses JSON
41  */
42 class JsonParser : public BaseObject
43 {
44 public:
45   /*
46    * @copydoc Toolkit::JsonParser::JsonParser()
47    */
48   JsonParser();
49
50   /*
51    * @copydoc Toolkit::JsonParser::JsonParser(const TreeNode& tree)
52    */
53   explicit JsonParser(const TreeNode& tree);
54
55   /*
56    */
57   ~JsonParser() override;
58
59   /*
60    * @copydoc Toolkit::JsonParser::Parse()
61    */
62   bool Parse(const std::string& source);
63
64   /*
65    * @copydoc Toolkit::JsonParser::Pack()
66    */
67   void Pack(void);
68
69   /*
70    * @copydoc Toolkit::JsonParser::GetRoot()
71    */
72   const TreeNode* GetRoot() const;
73
74   /*
75    * @copydoc Toolkit::JsonParser::ParseError()
76    */
77   bool ParseError() const;
78
79   /*
80    * @copydoc Toolkit::JsonParser::GetErrorPosition()
81    */
82   int GetErrorPosition() const;
83
84   /*
85    * @copydoc Toolkit::JsonParser::GetErrorDescription()
86    */
87   std::string GetErrorDescription() const;
88
89   /*
90    * @copydoc Toolkit::JsonParser::GetErrorLineNumber()
91    */
92   int GetErrorLineNumber() const;
93
94   /*
95    * @copydoc Toolkit::JsonParser::GetErrorColumn()
96    */
97   int GetErrorColumn() const;
98
99   /*
100    * @copydoc Toolkit::JsonParser::Write()
101    */
102   void Write(std::ostream& output, int indent) const;
103
104 private:
105   typedef std::vector<char>    VectorChar;
106   typedef VectorChar::iterator VectorCharIter;
107
108   typedef std::list<VectorChar>           SourceContainer;
109   typedef std::list<VectorChar>::iterator SourceContainerIter;
110
111   JsonParser(JsonParser&);
112   JsonParser& operator=(const JsonParser&);
113
114   SourceContainer mSources; ///< List of strings from Parse() merge operations
115
116   TreeNode* mRoot; ///< Tree root
117
118   const char* mErrorDescription; ///< Last parse error description
119   int         mErrorPosition;    ///< Last parse error position
120   int         mErrorLine;        ///< Last parse error line
121   int         mErrorColumn;      ///< Last parse error column
122
123   int mNumberOfChars; ///< The size of string data for all nodes
124   int mNumberOfNodes; ///< Node count
125 };
126
127 } // namespace Internal
128
129 inline const Internal::JsonParser& GetImplementation(const Toolkit::JsonParser& parser)
130 {
131   DALI_ASSERT_ALWAYS(parser && "JsonParser handle is empty");
132
133   const BaseObject& handle = parser.GetBaseObject();
134
135   return static_cast<const Internal::JsonParser&>(handle);
136 }
137
138 inline Internal::JsonParser& GetImplementation(Toolkit::JsonParser& parser)
139 {
140   DALI_ASSERT_ALWAYS(parser && "JsonParser handle is empty");
141
142   BaseObject& handle = parser.GetBaseObject();
143
144   return static_cast<Internal::JsonParser&>(handle);
145 }
146
147 } // namespace Toolkit
148
149 } // namespace Dali
150
151 #endif // DALI_JSON_PARSER_IMPL_H