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