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