License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-toolkit.git] / optional / 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 #include <string>
22 #include <vector>
23 #include <list>
24 #include <ostream>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/builder/tree-node.h>
28 #include <dali/public-api/object/base-handle.h>
29
30 namespace Dali DALI_IMPORT_API
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 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    * virtual Destructor
68    */
69   virtual ~JsonParser();
70
71   /**
72    * Downcast an Object handle to JsonParser if it is a JsonParser.
73    * @param[in] handle Handle to an object
74    * @return A handle to a JsonParser or an uninitialized handle
75    */
76   static JsonParser DownCast( BaseHandle handle );
77
78   /*
79    * Parse the source and construct a node tree.
80    * Subsequent calls to this function will merge the trees.
81    * @param source The json source to parse
82    * @return zero if parsed okay, otherwise an error.
83    */
84   int Parse(const std::string& source);
85
86   /*
87    * Optimize memory usage by packing strings
88    */
89   void Pack(void);
90
91   /*
92    * Get the tree root node
93    */
94   const TreeNode* GetRoot() const;
95
96   /*
97    * Get the parser error flag
98    * @return true if there was a parse error
99    */
100   bool ParseError() const;
101
102   /*
103    * Get the last error position
104    * @return The character position of the most recent Parse() error
105    */
106   int GetErrorPosition() const;
107
108   /*
109    * Get the last error description
110    * @return A string description of the error
111    */
112   std::string GetErrorDescription() const;
113
114   /*
115    * Get the last error line number
116    * @return the line number of the most recent Parse() error.
117    */
118   int GetErrorLineNumber() const;
119
120   /*
121    * Get the last error line number
122    * @return the line number of the most recent Parse() error.
123    */
124   int GetErrorColumn() const;
125
126   /*
127    * Write to output stream with optional indent
128    * @param output The stream to write to
129    * @param indent The indent to use
130    */
131   void Write(std::ostream& output, int indent) const;
132
133 public: // Not intended for application developers
134
135   /**
136    * This constructor is used by Dali New() methods
137    * @param [in] parser A pointer to a newly allocated Dali resource
138    */
139   explicit DALI_INTERNAL JsonParser(Internal::JsonParser* parser);
140 };
141
142 } // namespace Toolkit
143
144 } // namespace Dali
145
146
147 #endif // __DALI_JSON_PARSER_H__