(TextInput) Don't show cut and copy buttons if text not selected
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / public-api / builder / tree-node.h
1 #ifndef __DALI_SCRIPT_TREE_NODE_H__
2 #define __DALI_SCRIPT_TREE_NODE_H__
3
4 /*
5  * Copyright (c) 2014 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 #include <utility> // pair
22 #include <iterator>
23 #include <vector>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/common/dali-common.h>
27
28 namespace Dali DALI_IMPORT_API
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal DALI_INTERNAL
35 {
36
37 class TreeNodeManipulator;
38
39 } // namespace Internal
40
41
42 /*
43  * TreeNode describes a tree of nodes.
44  * TreeNode does not own its string data which is held by a container eg JsonParser
45  * Modification operations should be done through a container.
46  */
47 class TreeNode
48 {
49 public:
50   /*
51    * enum typedef describing the node type
52    */
53   enum NodeType
54   {
55     IS_NULL,
56     OBJECT,
57     ARRAY,
58     STRING,
59     INTEGER,
60     FLOAT,
61     BOOLEAN,
62   };
63
64   /*
65    * Non virtual destructor; this class should not be inherited from.
66    */
67   ~TreeNode();
68
69   typedef std::pair<const char*, const TreeNode&> KeyNodePair;
70
71   /*
72    * Iterator to iterate through children
73    */
74   class ConstIterator
75   {
76   public:
77     typedef KeyNodePair          value_type;
78     typedef KeyNodePair          *pointer;
79     typedef const KeyNodePair    *const_pointer;
80     typedef KeyNodePair          &reference;
81     typedef const KeyNodePair    &const_reference;
82     typedef size_t               size_type;
83     typedef std::ptrdiff_t       difference_type;
84     typedef std::forward_iterator_tag iterator_category;
85
86     /*
87      * constructor
88      */
89     explicit ConstIterator(TreeNode* v);
90
91     /*
92      * pre increment
93      */
94     ConstIterator& operator ++();
95
96     /*
97      * post increment
98      */
99     ConstIterator operator ++(int);
100
101     /*
102      * != test
103      */
104     bool operator!=( const ConstIterator& rhs ) const;
105
106     /*
107      * pointer semantics
108      */
109     KeyNodePair operator*();
110
111     /*
112      * pointer semantics
113      */
114     KeyNodePair operator->();
115   private:
116     TreeNode* mNode;
117   };
118
119   /*
120    * Iterate begin() over the nodes children
121    * @return a const interator
122    */
123   ConstIterator CBegin() const;
124
125   /*
126    * Iterate end()
127    * @return a const interator
128    */
129   ConstIterator CEnd() const;
130
131   /*
132    * Size (number of children)
133    * @return The number of children
134    */
135   size_t Size() const;
136
137   /*
138    * Count (the number of children of a sub child node)
139    * @param childName The name of the child to find
140    * @return the number of children in the found child
141    */
142   size_t Count(const std::string& childName) const;
143
144   /*
145    * Get the nodes name
146    * @return The nodes name
147    */
148   const char* GetName() const;
149
150   /*
151    * Gets the nodes type
152    * @return The nodes type
153    */
154   NodeType GetType() const;
155
156   /*
157    * Gets the nodes string value
158    * Only valid if the type == TreeNode::STRING
159    * @return The string value
160    */
161   const char* GetString() const;
162
163   /*
164    * Gets the nodes float value
165    * Only valid if the type == TreeNode::FLOAT
166    * @return The float value
167    */
168   float GetFloat() const;
169
170   /*
171    * Gets the nodes integer value
172    * Only valid if the type == TreeNode::INTEGER
173    * @return The integer value
174    */
175   int GetInteger() const;
176
177   /*
178    * Gets the nodes boolean value
179    * Only valid if the type == TreeNode::BOOLEAN
180    * @return The boolean value
181    */
182   bool GetBoolean() const;
183
184   /*
185    * Gets the substituion flag
186    * Only valid if the type == TreeNode::STRING
187    * @return The substitution flag
188    */
189   bool HasSubstitution() const;
190
191   /*
192    * Gets a child of the node
193    * @param name The name of the child
194    * @return The child if found, else NULL
195    */
196   const TreeNode* GetChild(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   TreeNode();
212
213   // non copyable or assignable
214   TreeNode(TreeNode &);
215   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__