1 #ifndef DALI_SCRIPT_TREE_NODE_H
2 #define DALI_SCRIPT_TREE_NODE_H
5 * Copyright (c) 2019 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
25 #include <dali-toolkit/public-api/dali-toolkit-common.h>
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.
46 class DALI_TOOLKIT_API TreeNode
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
73 class DALI_TOOLKIT_API ConstIterator
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*();
114 * Iterate begin() over the nodes children
115 * @return a const interator
117 ConstIterator CBegin() const;
121 * @return a const interator
123 ConstIterator CEnd() const;
126 * Size (number of children)
127 * @return The number of children
132 * Count (the number of children of a sub child node)
133 * @param childName The name of the child to find
134 * @return the number of children in the found child
136 size_t Count(const std::string& childName) const;
140 * @return The nodes name
142 const char* GetName() const;
145 * Gets the nodes type
146 * @return The nodes type
148 NodeType GetType() const;
151 * Gets the nodes string value
152 * Only valid if the type == TreeNode::STRING
153 * @return The string value
155 const char* GetString() const;
158 * Gets the nodes float value
159 * Only valid if the type == TreeNode::FLOAT
160 * @return The float value
162 float GetFloat() const;
165 * Gets the nodes integer value
166 * Only valid if the type == TreeNode::INTEGER
167 * @return The integer value
169 int GetInteger() const;
172 * Gets the nodes boolean value
173 * Only valid if the type == TreeNode::BOOLEAN
174 * @return The boolean value
176 bool GetBoolean() const;
179 * Gets the substituion flag
180 * Only valid if the type == TreeNode::STRING
181 * @return The substitution flag
183 bool HasSubstitution() const;
186 * Gets a child of the node (using case sensitive matching)
187 * @param name The name of the child.
188 * @return The child if found, else NULL
190 const TreeNode* GetChild(const std::string& name) const;
193 * Gets a child of the node (using case insensitive matching)
194 * @param name The name of the child in lower case
195 * @return The child if found, else NULL
197 const TreeNode* GetChildIgnoreCase(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