Split dali-toolkit into Base & Optional
[platform/core/uifw/dali-toolkit.git] / optional / dali-toolkit / public-api / builder / tree-node.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 // EXTERNAL INCLUDES
18 #include <cstring>
19
20 // INTERNAL INCLUDES
21 #include "dali-toolkit/public-api/builder/tree-node.h"
22 #include "dali-toolkit/internal/builder/tree-node-manipulator.h"
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 TreeNode::TreeNode()
31   : mName(NULL),
32     mParent(NULL),
33     mNextSibling(NULL),
34     mFirstChild(NULL),
35     mLastChild(NULL),
36     mStringValue(NULL),
37     mType(TreeNode::IS_NULL),
38     mSubstituion(false)
39 {
40 }
41
42 TreeNode::~TreeNode()
43 {
44
45 }
46
47 const char* TreeNode::GetName() const
48 {
49   return mName;
50 }
51
52 TreeNode::NodeType TreeNode::GetType() const
53 {
54   return mType;
55 }
56
57 const char* TreeNode::GetString() const
58 {
59   return mStringValue;
60 }
61
62 bool TreeNode::HasSubstitution() const
63 {
64   return mSubstituion;
65 }
66
67 float TreeNode::GetFloat() const
68 {
69   return mFloatValue;
70 }
71
72 int TreeNode::GetInteger() const
73 {
74   return mIntValue;
75 }
76
77 bool TreeNode::GetBoolean() const
78 {
79   return mIntValue == 1 ? true : false;
80 }
81
82
83 size_t TreeNode::Size() const
84 {
85   size_t c = 0;
86   TreeNode* p = mFirstChild;
87   while(p)
88   {
89     c++;
90     p = p->mNextSibling;
91   }
92   return c;
93 }
94
95 size_t TreeNode::Count(const std::string& childName) const
96 {
97   const TreeNode* c = GetChild(childName);
98   if(c)
99   {
100     return c->Size();
101   }
102   else
103   {
104     return 0;
105   }
106 }
107
108 const TreeNode* TreeNode::GetChild(const std::string& childName) const
109 {
110   const TreeNode* p = mFirstChild;
111   while(p)
112   {
113     if(p->mName && (std::string(p->mName) == childName) )
114     {
115       return p;
116     }
117     p = p->mNextSibling;
118   }
119   return NULL;
120 }
121
122 const TreeNode* TreeNode::Find(const std::string& childName) const
123 {
124   if(mName && std::string(mName) == childName)
125   {
126     return this;
127   }
128   else
129   {
130     return Internal::FindIt(childName, this);
131   }
132 }
133
134 TreeNode::ConstIterator TreeNode::CBegin() const
135 {
136   return ConstIterator(mFirstChild);
137 }
138
139
140 TreeNode::ConstIterator TreeNode::CEnd() const
141 {
142   return ConstIterator(NULL);
143 }
144
145
146 TreeNode::ConstIterator::ConstIterator(TreeNode* v) : mNode(v)
147 {
148
149 }
150
151 TreeNode::ConstIterator& TreeNode::ConstIterator::operator ++()
152 {
153   if(mNode)
154   {
155     mNode = mNode->mNextSibling;
156   }
157   else
158   {
159     mNode = NULL;
160   }
161   return *this;
162 }
163
164 TreeNode::ConstIterator TreeNode::ConstIterator::operator ++(int)
165 {
166   TreeNode::ConstIterator ret(mNode);
167
168   if(mNode)
169   {
170     mNode = mNode->mNextSibling;
171   }
172   else
173   {
174     mNode = NULL;
175   }
176   return ret;
177 }
178
179 TreeNode::KeyNodePair TreeNode::ConstIterator::operator *()
180 {
181   return KeyNodePair(mNode->mName, *mNode);
182 }
183
184 TreeNode::KeyNodePair TreeNode::ConstIterator::operator ->()
185 {
186   return KeyNodePair(mNode->mName, *mNode);
187 }
188
189 bool TreeNode::ConstIterator::operator!=( const TreeNode::ConstIterator& rhs ) const
190 {
191   return mNode != rhs.mNode;
192 }
193
194 } // namespace Toolkit
195
196 } // namespace Dali
197