1 #ifndef __DALI_SCRIPT_TREE_NODE_H__
2 #define __DALI_SCRIPT_TREE_NODE_H__
5 * Copyright (c) 2015 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
24 #include <dali/public-api/common/dali-common.h>
32 namespace Internal DALI_INTERNAL
35 class TreeNodeManipulator;
37 } // namespace Internal
41 * TreeNode describes a tree of nodes.
42 * TreeNode does not own its string data which is held by a container eg JsonParser
43 * Modification operations should be done through a container.
45 class DALI_IMPORT_API TreeNode
49 * enum typedef describing the node type
63 * Non virtual destructor; this class should not be inherited from.
67 typedef std::pair<const char*, const TreeNode&> KeyNodePair;
70 * Iterator to iterate through children
75 typedef KeyNodePair value_type;
76 typedef KeyNodePair *pointer;
77 typedef const KeyNodePair *const_pointer;
78 typedef KeyNodePair &reference;
79 typedef const KeyNodePair &const_reference;
80 typedef size_t size_type;
81 typedef std::ptrdiff_t difference_type;
82 typedef std::forward_iterator_tag iterator_category;
87 explicit ConstIterator(TreeNode* v);
92 ConstIterator& operator ++();
97 ConstIterator operator ++(int);
102 bool operator!=( const ConstIterator& rhs ) const;
107 KeyNodePair operator*();
112 KeyNodePair operator->();
118 * Iterate begin() over the nodes children
119 * @return a const interator
121 ConstIterator CBegin() const;
125 * @return a const interator
127 ConstIterator CEnd() const;
130 * Size (number of children)
131 * @return The number of children
136 * Count (the number of children of a sub child node)
137 * @param childName The name of the child to find
138 * @return the number of children in the found child
140 size_t Count(const std::string& childName) const;
144 * @return The nodes name
146 const char* GetName() const;
149 * Gets the nodes type
150 * @return The nodes type
152 NodeType GetType() const;
155 * Gets the nodes string value
156 * Only valid if the type == TreeNode::STRING
157 * @return The string value
159 const char* GetString() const;
162 * Gets the nodes float value
163 * Only valid if the type == TreeNode::FLOAT
164 * @return The float value
166 float GetFloat() const;
169 * Gets the nodes integer value
170 * Only valid if the type == TreeNode::INTEGER
171 * @return The integer value
173 int GetInteger() const;
176 * Gets the nodes boolean value
177 * Only valid if the type == TreeNode::BOOLEAN
178 * @return The boolean value
180 bool GetBoolean() const;
183 * Gets the substituion flag
184 * Only valid if the type == TreeNode::STRING
185 * @return The substitution flag
187 bool HasSubstitution() const;
190 * Gets a child of the node
191 * @param name The name of the child
192 * @return The child if found, else NULL
194 const TreeNode* GetChild(const std::string& name) const;
197 * Recursively search for a child of the node
198 * @param name The name of the child
199 * @return The child if found, else NULL
201 const TreeNode* Find(const std::string& name) const;
204 friend class Internal::TreeNodeManipulator;
209 DALI_INTERNAL TreeNode();
211 // non copyable or assignable
212 DALI_INTERNAL TreeNode(TreeNode &);
213 DALI_INTERNAL TreeNode& operator=(const TreeNode&);
215 const char* mName; ///< The nodes name (if any)
217 TreeNode* mParent; ///< The nodes parent
218 TreeNode* mNextSibling; ///< The nodes next sibling
219 TreeNode* mFirstChild; ///< The nodes first child
220 TreeNode* mLastChild; ///< The nodes last child
224 const char* mStringValue; ///< The node string value
225 int mIntValue; ///< The node integer value
226 float mFloatValue; ///< The node float value
229 NodeType mType; ///< The nodes type
230 bool mSubstituion; ///< String substitution flag
234 } // namespace Toolkit
238 #endif // __DALI_SCRIPT_TREE_NODE_H__