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