Follow the include-order coding conventions
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / builder / tree-node.h
1 #ifndef __DALI_SCRIPT_TREE_NODE_H__
2 #define __DALI_SCRIPT_TREE_NODE_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 <utility> // pair
23 #include <iterator>
24 #include <vector>
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/common/dali-common.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal DALI_INTERNAL
36 {
37
38 class TreeNodeManipulator;
39
40 } // namespace Internal
41
42
43 /*
44  * TreeNode describes a tree of nodes.
45  * TreeNode does not own its string data which is held by a container eg JsonParser
46  * Modification operations should be done through a container.
47  */
48 class DALI_IMPORT_API TreeNode
49 {
50 public:
51   /*
52    * enum typedef describing the node type
53    */
54   enum NodeType
55   {
56     IS_NULL,
57     OBJECT,
58     ARRAY,
59     STRING,
60     INTEGER,
61     FLOAT,
62     BOOLEAN,
63   };
64
65   /*
66    * Non virtual destructor; this class should not be inherited from.
67    */
68   ~TreeNode();
69
70   typedef std::pair<const char*, const TreeNode&> KeyNodePair;
71
72   /*
73    * Iterator to iterate through children
74    */
75   class ConstIterator
76   {
77   public:
78     typedef KeyNodePair          value_type;
79     typedef KeyNodePair          *pointer;
80     typedef const KeyNodePair    *const_pointer;
81     typedef KeyNodePair          &reference;
82     typedef const KeyNodePair    &const_reference;
83     typedef size_t               size_type;
84     typedef std::ptrdiff_t       difference_type;
85     typedef std::forward_iterator_tag iterator_category;
86
87     /*
88      * constructor
89      */
90     explicit ConstIterator(TreeNode* v);
91
92     /*
93      * pre increment
94      */
95     ConstIterator& operator ++();
96
97     /*
98      * post increment
99      */
100     ConstIterator operator ++(int);
101
102     /*
103      * != test
104      */
105     bool operator!=( const ConstIterator& rhs ) const;
106
107     /*
108      * pointer semantics
109      */
110     KeyNodePair operator*();
111
112     /*
113      * pointer semantics
114      */
115     KeyNodePair operator->();
116   private:
117     TreeNode* mNode;
118   };
119
120   /*
121    * Iterate begin() over the nodes children
122    * @return a const interator
123    */
124   ConstIterator CBegin() const;
125
126   /*
127    * Iterate end()
128    * @return a const interator
129    */
130   ConstIterator CEnd() const;
131
132   /*
133    * Size (number of children)
134    * @return The number of children
135    */
136   size_t Size() const;
137
138   /*
139    * Count (the number of children of a sub child node)
140    * @param childName The name of the child to find
141    * @return the number of children in the found child
142    */
143   size_t Count(const std::string& childName) const;
144
145   /*
146    * Get the nodes name
147    * @return The nodes name
148    */
149   const char* GetName() const;
150
151   /*
152    * Gets the nodes type
153    * @return The nodes type
154    */
155   NodeType GetType() const;
156
157   /*
158    * Gets the nodes string value
159    * Only valid if the type == TreeNode::STRING
160    * @return The string value
161    */
162   const char* GetString() const;
163
164   /*
165    * Gets the nodes float value
166    * Only valid if the type == TreeNode::FLOAT
167    * @return The float value
168    */
169   float GetFloat() const;
170
171   /*
172    * Gets the nodes integer value
173    * Only valid if the type == TreeNode::INTEGER
174    * @return The integer value
175    */
176   int GetInteger() const;
177
178   /*
179    * Gets the nodes boolean value
180    * Only valid if the type == TreeNode::BOOLEAN
181    * @return The boolean value
182    */
183   bool GetBoolean() const;
184
185   /*
186    * Gets the substituion flag
187    * Only valid if the type == TreeNode::STRING
188    * @return The substitution flag
189    */
190   bool HasSubstitution() const;
191
192   /*
193    * Gets a child of the node
194    * @param name The name of the child
195    * @return The child if found, else NULL
196    */
197   const TreeNode* GetChild(const std::string& name) const;
198
199   /*
200    * Recursively search for a child of the node
201    * @param name The name of the child
202    * @return The child if found, else NULL
203    */
204   const TreeNode* Find(const std::string& name) const;
205
206 private:
207   friend class Internal::TreeNodeManipulator;
208
209   /*
210    * Constructor
211    */
212   DALI_INTERNAL TreeNode();
213
214   // non copyable or assignable
215   DALI_INTERNAL TreeNode(TreeNode &);
216   DALI_INTERNAL TreeNode& operator=(const TreeNode&);
217
218   const char* mName;                   ///< The nodes name (if any)
219
220   TreeNode* mParent;                   ///< The nodes parent
221   TreeNode* mNextSibling;              ///< The nodes next sibling
222   TreeNode* mFirstChild;               ///< The nodes first child
223   TreeNode* mLastChild;                ///< The nodes last child
224
225   union
226   {
227     const char* mStringValue;          ///< The node string value
228     int mIntValue;                     ///< The node integer value
229     float mFloatValue;                 ///< The node float value
230   };
231
232   NodeType mType;                      ///< The nodes type
233   bool mSubstituion;                   ///< String substitution flag
234
235 };
236
237 } // namespace Toolkit
238
239 } // namespace Dali
240
241 #endif // __DALI_SCRIPT_TREE_NODE_H__