1b3adcf60953da5c3619cda8c3236cdd8a7c753d
[platform/core/uifw/dali-toolkit.git] / base / 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) 2014 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 #include <string>
22 #include <vector>
23 #include <list>
24
25 //
26 #include <dali/public-api/object/base-object.h>
27 #include <dali-toolkit/public-api/builder/json-parser.h>
28 #include <dali-toolkit/public-api/builder/tree-node.h>
29
30 #include <dali-toolkit/internal/builder/builder-get-is.inl.h>
31
32 namespace Dali DALI_IMPORT_API
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Internal DALI_INTERNAL
39 {
40
41 /*
42  * Parses JSON
43  */
44 class JsonParser : public BaseObject
45 {
46 public:
47   /*
48    * @copydoc Toolkit::JsonParser::JsonParser()
49    */
50   JsonParser();
51
52   /*
53    * @copydoc Toolkit::JsonParser::JsonParser(const TreeNode& tree)
54    */
55   explicit JsonParser(const TreeNode& tree);
56
57   /*
58    */
59   ~JsonParser();
60
61   /*
62    * @copydoc Toolkit::JsonParser::Parse()
63    */
64   int Parse(const std::string& source);
65
66   /*
67    * @copydoc Toolkit::JsonParser::Pack()
68    */
69   void Pack(void);
70
71   /*
72    * @copydoc Toolkit::JsonParser::GetRoot()
73    */
74   const TreeNode* GetRoot() const;
75
76   /*
77    * @copydoc Toolkit::JsonParser::ParseError()
78    */
79   bool ParseError() const;
80
81   /*
82    * @copydoc Toolkit::JsonParser::GetErrorPosition()
83    */
84   int GetErrorPosition() const;
85
86   /*
87    * @copydoc Toolkit::JsonParser::GetErrorDescription()
88    */
89   std::string GetErrorDescription() const;
90
91   /*
92    * @copydoc Toolkit::JsonParser::GetErrorLineNumber()
93    */
94   int GetErrorLineNumber() const;
95
96   /*
97    * @copydoc Toolkit::JsonParser::GetErrorColumn()
98    */
99   int GetErrorColumn() const;
100
101   /*
102    * @copydoc Toolkit::JsonParser::Write()
103    */
104   void Write(std::ostream& output, int indent) const;
105
106 private:
107   typedef std::vector<char> VectorChar;
108   typedef VectorChar::iterator VectorCharIter;
109
110   typedef std::list<VectorChar> SourceContainer;
111   typedef std::list<VectorChar>::iterator SourceContainerIter;
112
113   JsonParser(JsonParser &);
114   JsonParser& operator=(const JsonParser&);
115
116   SourceContainer mSources;         ///< List of strings from Parse() merge operations
117
118   TreeNode* mRoot;                  ///< Tree root
119
120   const char *mErrorDescription;    ///< Last parse error description
121   int mErrorPosition;               ///< Last parse error position
122   int mErrorLine;                   ///< Last parse error line
123   int mErrorColumn;                 ///< Last parse error column
124
125   int mNumberOfChars;               ///< The size of string data for all nodes
126   int mNumberOfNodes;               ///< Node count
127
128 };
129
130 } // namespace Internal
131
132
133 inline const Internal::JsonParser& GetImplementation(const Toolkit::JsonParser& parser)
134 {
135   DALI_ASSERT_ALWAYS( parser && "JsonParser handle is empty" );
136
137   const BaseObject& handle = parser.GetBaseObject();
138
139   return static_cast<const Internal::JsonParser&>(handle);
140 }
141
142
143 inline Internal::JsonParser& GetImplementation(Toolkit::JsonParser& parser)
144 {
145   DALI_ASSERT_ALWAYS( parser && "JsonParser handle is empty" );
146
147   BaseObject& handle = parser.GetBaseObject();
148
149   return static_cast<Internal::JsonParser&>(handle);
150 }
151
152 } // namespace Toolkit
153
154 } // namespace Dali
155
156
157 #endif // __DALI_JSON_PARSER_IMPL_H__