2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <string_view>
25 #include "dali-toolkit/devel-api/builder/tree-node.h"
26 #include "dali-toolkit/internal/builder/tree-node-manipulator.h"
31 * return true if the lower cased ASCII strings are equal.
33 bool CaseInsensitiveStringCompare(std::string_view a, std::string_view b)
35 return (a.length() == b.length()) && std::equal(a.begin(), a.end(), b.begin(), [](auto x, auto y) {
36 return std::tolower(x) == std::tolower(y);
49 mType(TreeNode::IS_NULL),
58 const char* TreeNode::GetName() const
63 TreeNode::NodeType TreeNode::GetType() const
68 const char* TreeNode::GetString() const
73 bool TreeNode::HasSubstitution() const
78 float TreeNode::GetFloat() const
83 int TreeNode::GetInteger() const
88 bool TreeNode::GetBoolean() const
90 return mIntValue == 1 ? true : false;
93 size_t TreeNode::Size() const
96 TreeNode* p = mFirstChild;
105 size_t TreeNode::Count(std::string_view childName) const
107 const TreeNode* c = GetChild(childName);
118 const TreeNode* TreeNode::GetChild(std::string_view childName) const
120 const TreeNode* p = mFirstChild;
123 if(p->mName && (std::string_view(p->mName) == childName))
132 const TreeNode* TreeNode::GetChildIgnoreCase(std::string_view childName) const
134 const TreeNode* p = mFirstChild;
137 if(p->mName && CaseInsensitiveStringCompare(p->mName, childName))
146 const TreeNode* TreeNode::Find(std::string_view childName) const
148 if(mName && std::string_view(mName) == childName)
154 return Internal::FindIt(childName, this);
158 TreeNode::ConstIterator TreeNode::CBegin() const
160 return ConstIterator(mFirstChild);
163 TreeNode::ConstIterator TreeNode::CEnd() const
165 return ConstIterator(NULL);
168 TreeNode::ConstIterator::ConstIterator(TreeNode* v)
173 TreeNode::ConstIterator& TreeNode::ConstIterator::operator++()
177 mNode = mNode->mNextSibling;
186 TreeNode::ConstIterator TreeNode::ConstIterator::operator++(int)
188 TreeNode::ConstIterator ret(mNode);
192 mNode = mNode->mNextSibling;
201 TreeNode::KeyNodePair TreeNode::ConstIterator::operator*()
203 return KeyNodePair(mNode->mName, *mNode);
206 bool TreeNode::ConstIterator::operator!=(const TreeNode::ConstIterator& rhs) const
208 return mNode != rhs.mNode;
211 } // namespace Toolkit