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