Merge "Added Scaling and cropping properties to the image visual mask" into devel...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / builder / tree-node.h
1 #ifndef __DALI_SCRIPT_TREE_NODE_H__
2 #define __DALI_SCRIPT_TREE_NODE_H__
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <utility> // pair
23 #include <iterator>
24 #include <dali/public-api/common/dali-common.h>
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 namespace Internal DALI_INTERNAL
33 {
34
35 class TreeNodeManipulator;
36
37 } // namespace Internal
38
39
40 /*
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.
44  */
45 class DALI_IMPORT_API TreeNode
46 {
47 public:
48   /*
49    * enum typedef describing the node type
50    */
51   enum NodeType
52   {
53     IS_NULL,
54     OBJECT,
55     ARRAY,
56     STRING,
57     INTEGER,
58     FLOAT,
59     BOOLEAN
60   };
61
62   /*
63    * Non virtual destructor; this class should not be inherited from.
64    */
65   ~TreeNode();
66
67   typedef std::pair<const char*, const TreeNode&> KeyNodePair;
68
69   /*
70    * Iterator to iterate through children
71    */
72   class ConstIterator
73   {
74   public:
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;
83
84     /*
85      * constructor
86      */
87     explicit ConstIterator(TreeNode* v);
88
89     /*
90      * pre increment
91      */
92     ConstIterator& operator ++();
93
94     /*
95      * post increment
96      */
97     ConstIterator operator ++(int);
98
99     /*
100      * != test
101      */
102     bool operator!=( const ConstIterator& rhs ) const;
103
104     /*
105      * pointer semantics
106      */
107     KeyNodePair operator*();
108   private:
109     TreeNode* mNode;
110   };
111
112   /*
113    * Iterate begin() over the nodes children
114    * @return a const interator
115    */
116   ConstIterator CBegin() const;
117
118   /*
119    * Iterate end()
120    * @return a const interator
121    */
122   ConstIterator CEnd() const;
123
124   /*
125    * Size (number of children)
126    * @return The number of children
127    */
128   size_t Size() const;
129
130   /*
131    * Count (the number of children of a sub child node)
132    * @param childName The name of the child to find
133    * @return the number of children in the found child
134    */
135   size_t Count(const std::string& childName) const;
136
137   /*
138    * Get the nodes name
139    * @return The nodes name
140    */
141   const char* GetName() const;
142
143   /*
144    * Gets the nodes type
145    * @return The nodes type
146    */
147   NodeType GetType() const;
148
149   /*
150    * Gets the nodes string value
151    * Only valid if the type == TreeNode::STRING
152    * @return The string value
153    */
154   const char* GetString() const;
155
156   /*
157    * Gets the nodes float value
158    * Only valid if the type == TreeNode::FLOAT
159    * @return The float value
160    */
161   float GetFloat() const;
162
163   /*
164    * Gets the nodes integer value
165    * Only valid if the type == TreeNode::INTEGER
166    * @return The integer value
167    */
168   int GetInteger() const;
169
170   /*
171    * Gets the nodes boolean value
172    * Only valid if the type == TreeNode::BOOLEAN
173    * @return The boolean value
174    */
175   bool GetBoolean() const;
176
177   /*
178    * Gets the substituion flag
179    * Only valid if the type == TreeNode::STRING
180    * @return The substitution flag
181    */
182   bool HasSubstitution() const;
183
184   /*
185    * Gets a child of the node (using case sensitive matching)
186    * @param name The name of the child.
187    * @return The child if found, else NULL
188    */
189   const TreeNode* GetChild(const std::string& name) const;
190
191   /*
192    * Gets a child of the node (using case insensitive matching)
193    * @param name The name of the child in lower case
194    * @return The child if found, else NULL
195    */
196   const TreeNode* GetChildIgnoreCase(const std::string& name) const;
197
198   /*
199    * Recursively search for a child of the node
200    * @param name The name of the child
201    * @return The child if found, else NULL
202    */
203   const TreeNode* Find(const std::string& name) const;
204
205 private:
206   friend class Internal::TreeNodeManipulator;
207
208   /*
209    * Constructor
210    */
211   DALI_INTERNAL TreeNode();
212
213   // non copyable or assignable
214   DALI_INTERNAL TreeNode(TreeNode &);
215   DALI_INTERNAL TreeNode& operator=(const TreeNode&);
216
217   const char* mName;                   ///< The nodes name (if any)
218
219   TreeNode* mParent;                   ///< The nodes parent
220   TreeNode* mNextSibling;              ///< The nodes next sibling
221   TreeNode* mFirstChild;               ///< The nodes first child
222   TreeNode* mLastChild;                ///< The nodes last child
223
224   union
225   {
226     const char* mStringValue;          ///< The node string value
227     int mIntValue;                     ///< The node integer value
228     float mFloatValue;                 ///< The node float value
229   };
230
231   NodeType mType;                      ///< The nodes type
232   bool mSubstituion;                   ///< String substitution flag
233
234 };
235
236 } // namespace Toolkit
237
238 } // namespace Dali
239
240 #endif // __DALI_SCRIPT_TREE_NODE_H__