8abbe6a67562a443c4b3663c030890dd84753a92
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / builder / json-parser.h
1 #ifndef __DALI_JSON_PARSER_H__
2 #define __DALI_JSON_PARSER_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 <vector>
24 #include <list>
25 #include <ostream>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/public-api/builder/tree-node.h>
29 #include <dali/public-api/object/base-handle.h>
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Internal DALI_INTERNAL
38 {
39 class JsonParser;
40 }
41
42 /*
43  * Parses JSON
44  */
45 class DALI_IMPORT_API JsonParser : public BaseHandle
46 {
47 public:
48
49   /*
50    * Create new parser
51    * @return JsonParser
52    */
53   static JsonParser New();
54
55   /*
56    * Create new parser from the given tree
57    * This method will deep copy the given tree.
58    * @return JsonParser
59    */
60   static JsonParser New(const TreeNode& tree);
61
62   /*
63    * Create empty handle
64    */
65   JsonParser();
66
67   /**
68    * @brief Destructor
69    *
70    * This is non-virtual since derived Handle types must not contain data or virtual methods.
71    */
72   ~JsonParser();
73
74   /**
75    * Downcast an Object handle to JsonParser if it is a JsonParser.
76    * @param[in] handle Handle to an object
77    * @return A handle to a JsonParser or an uninitialized handle
78    */
79   static JsonParser DownCast( BaseHandle handle );
80
81   /*
82    * Parse the source and construct a node tree.
83    * Subsequent calls to this function will merge the trees.
84    * @param source The json source to parse
85    * @return zero if parsed okay, otherwise an error.
86    */
87   int Parse(const std::string& source);
88
89   /*
90    * Optimize memory usage by packing strings
91    */
92   void Pack(void);
93
94   /*
95    * Get the tree root node
96    */
97   const TreeNode* GetRoot() const;
98
99   /*
100    * Get the parser error flag
101    * @return true if there was a parse error
102    */
103   bool ParseError() const;
104
105   /*
106    * Get the last error position
107    * @return The character position of the most recent Parse() error
108    */
109   int GetErrorPosition() const;
110
111   /*
112    * Get the last error description
113    * @return A string description of the error
114    */
115   std::string GetErrorDescription() const;
116
117   /*
118    * Get the last error line number
119    * @return the line number of the most recent Parse() error.
120    */
121   int GetErrorLineNumber() const;
122
123   /*
124    * Get the last error line number
125    * @return the line number of the most recent Parse() error.
126    */
127   int GetErrorColumn() const;
128
129   /*
130    * Write to output stream with optional indent
131    * @param output The stream to write to
132    * @param indent The indent to use
133    */
134   void Write(std::ostream& output, int indent) const;
135
136 public: // Not intended for application developers
137
138   /**
139    * This constructor is used by Dali New() methods
140    * @param [in] parser A pointer to a newly allocated Dali resource
141    */
142   explicit DALI_INTERNAL JsonParser(Internal::JsonParser* parser);
143 };
144
145 } // namespace Toolkit
146
147 } // namespace Dali
148
149
150 #endif // __DALI_JSON_PARSER_H__