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 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <utility> // pair
27 #include <dali/public-api/common/dali-common.h>
35 namespace Internal DALI_INTERNAL
38 class TreeNodeManipulator;
40 } // namespace Internal
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.
48 class DALI_IMPORT_API TreeNode
52 * enum typedef describing the node type
66 * Non virtual destructor; this class should not be inherited from.
70 typedef std::pair<const char*, const TreeNode&> KeyNodePair;
73 * Iterator to iterate through children
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;
90 explicit ConstIterator(TreeNode* v);
95 ConstIterator& operator ++();
100 ConstIterator operator ++(int);
105 bool operator!=( const ConstIterator& rhs ) const;
110 KeyNodePair operator*();
115 KeyNodePair operator->();
121 * Iterate begin() over the nodes children
122 * @return a const interator
124 ConstIterator CBegin() const;
128 * @return a const interator
130 ConstIterator CEnd() const;
133 * Size (number of children)
134 * @return The number of children
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
143 size_t Count(const std::string& childName) const;
147 * @return The nodes name
149 const char* GetName() const;
152 * Gets the nodes type
153 * @return The nodes type
155 NodeType GetType() const;
158 * Gets the nodes string value
159 * Only valid if the type == TreeNode::STRING
160 * @return The string value
162 const char* GetString() const;
165 * Gets the nodes float value
166 * Only valid if the type == TreeNode::FLOAT
167 * @return The float value
169 float GetFloat() const;
172 * Gets the nodes integer value
173 * Only valid if the type == TreeNode::INTEGER
174 * @return The integer value
176 int GetInteger() const;
179 * Gets the nodes boolean value
180 * Only valid if the type == TreeNode::BOOLEAN
181 * @return The boolean value
183 bool GetBoolean() const;
186 * Gets the substituion flag
187 * Only valid if the type == TreeNode::STRING
188 * @return The substitution flag
190 bool HasSubstitution() const;
193 * Gets a child of the node
194 * @param name The name of the child
195 * @return The child if found, else NULL
197 const TreeNode* GetChild(const std::string& name) const;
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
204 const TreeNode* Find(const std::string& name) const;
207 friend class Internal::TreeNodeManipulator;
212 DALI_INTERNAL TreeNode();
214 // non copyable or assignable
215 DALI_INTERNAL TreeNode(TreeNode &);
216 DALI_INTERNAL TreeNode& operator=(const TreeNode&);
218 const char* mName; ///< The nodes name (if any)
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
227 const char* mStringValue; ///< The node string value
228 int mIntValue; ///< The node integer value
229 float mFloatValue; ///< The node float value
232 NodeType mType; ///< The nodes type
233 bool mSubstituion; ///< String substitution flag
237 } // namespace Toolkit
241 #endif // __DALI_SCRIPT_TREE_NODE_H__