1 #ifndef __DALI_SCRIPT_TREE_NODE_H__
2 #define __DALI_SCRIPT_TREE_NODE_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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
11 // http://floralicense.org/license/
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.
20 #include <utility> // pair
25 #include <dali/public-api/common/dali-common.h>
27 namespace Dali DALI_IMPORT_API
33 namespace Internal DALI_INTERNAL
36 class TreeNodeManipulator;
38 } // namespace Internal
42 * TreeNode describes a tree of nodes.
43 * TreeNode does not own its string data which is held by a container eg JsonParser
44 * Modification operations should be done through a container.
50 * enum typedef describing the node type
64 * Non virtual destructor; this class should not be inherited from.
68 typedef std::pair<const char*, const TreeNode&> KeyNodePair;
71 * Iterator to iterate through children
76 typedef KeyNodePair value_type;
77 typedef KeyNodePair *pointer;
78 typedef const KeyNodePair *const_pointer;
79 typedef KeyNodePair &reference;
80 typedef const KeyNodePair &const_reference;
81 typedef size_t size_type;
82 typedef std::ptrdiff_t difference_type;
83 typedef std::forward_iterator_tag iterator_category;
88 explicit ConstIterator(TreeNode* v);
93 ConstIterator& operator ++();
98 ConstIterator operator ++(int);
103 bool operator!=( const ConstIterator& rhs ) const;
108 KeyNodePair operator*();
113 KeyNodePair operator->();
119 * Iterate begin() over the nodes children
120 * @return a const interator
122 ConstIterator CBegin() const;
126 * @return a const interator
128 ConstIterator CEnd() const;
131 * Size (number of children)
132 * @return The number of children
137 * Count (the number of children of a sub child node)
138 * @param childName The name of the child to find
139 * @return the number of children in the found child
141 size_t Count(const std::string& childName) const;
145 * @return The nodes name
147 const char* GetName() const;
150 * Gets the nodes type
151 * @return The nodes type
153 NodeType GetType() const;
156 * Gets the nodes string value
157 * Only valid if the type == TreeNode::STRING
158 * @return The string value
160 const char* GetString() const;
163 * Gets the nodes float value
164 * Only valid if the type == TreeNode::FLOAT
165 * @return The float value
167 float GetFloat() const;
170 * Gets the nodes integer value
171 * Only valid if the type == TreeNode::INTEGER
172 * @return The integer value
174 int GetInteger() const;
177 * Gets the nodes boolean value
178 * Only valid if the type == TreeNode::BOOLEAN
179 * @return The boolean value
181 bool GetBoolean() const;
184 * Gets the substituion flag
185 * Only valid if the type == TreeNode::STRING
186 * @return The substitution flag
188 bool HasSubstitution() const;
191 * Gets a child of the node
192 * @param name The name of the child
193 * @return The child if found, else NULL
195 const TreeNode* GetChild(const std::string& name) const;
198 * Recursively search for a child of the node
199 * @param name The name of the child
200 * @return The child if found, else NULL
202 const TreeNode* Find(const std::string& name) const;
205 friend class Internal::TreeNodeManipulator;
212 // non copyable or assignable
213 TreeNode(TreeNode &);
214 TreeNode& operator=(const TreeNode&);
216 const char* mName; ///< The nodes name (if any)
218 TreeNode* mParent; ///< The nodes parent
219 TreeNode* mNextSibling; ///< The nodes next sibling
220 TreeNode* mFirstChild; ///< The nodes first child
221 TreeNode* mLastChild; ///< The nodes last child
225 const char* mStringValue; ///< The node string value
226 int mIntValue; ///< The node integer value
227 float mFloatValue; ///< The node float value
230 NodeType mType; ///< The nodes type
231 bool mSubstituion; ///< String substitution flag
235 } // namespace Toolkit
239 #endif // __DALI_SCRIPT_TREE_NODE_H__