[NUI] Fix Dropdown runtime error (#1232)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / PropertyMap.cs
1 /*
2  * Copyright(c) 2019 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 using System.ComponentModel;
18
19 namespace Tizen.NUI
20 {
21     /// <summary>
22     /// A map of property values, the key type could be string or Property::Index.
23     /// </summary>
24     /// <since_tizen> 3 </since_tizen>
25     public class PropertyMap : Disposable
26     {
27
28         /// <summary>
29         /// The constructor.
30         /// </summary>
31         /// <since_tizen> 3 </since_tizen>
32         public PropertyMap() : this(Interop.PropertyMap.new_Property_Map__SWIG_0(), true)
33         {
34             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
35         }
36
37         /// <summary>
38         /// The copy constructor.
39         /// </summary>
40         /// <param name="other">The map to copy from.</param>
41         /// <since_tizen> 3 </since_tizen>
42         public PropertyMap(PropertyMap other) : this(Interop.PropertyMap.new_Property_Map__SWIG_1(PropertyMap.getCPtr(other)), true)
43         {
44             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
45         }
46
47         internal PropertyMap(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
48         {
49         }
50
51         /// <summary>
52         /// The operator to access the element with the specified string key.<br />
53         /// If an element with the key does not exist, then it is created.<br />
54         /// </summary>
55         /// <param name="key">The key whose value to access.</param>
56         /// <returns>A value for the element with the specified key.</returns>
57         /// <since_tizen> 3 </since_tizen>
58         public PropertyValue this[string key]
59         {
60             get
61             {
62                 return ValueOfIndex(key);
63             }
64         }
65
66         /// <summary>
67         /// The operator to access the element with the specified index key.<br />
68         /// If an element with the key does not exist, then it is created.<br />
69         /// </summary>
70         /// <param name="key">The key whose value to access.</param>
71         /// <returns>A value for the element with the specified key.</returns>
72         /// <since_tizen> 3 </since_tizen>
73         public PropertyValue this[int key]
74         {
75             get
76             {
77                 return ValueOfIndex(key);
78             }
79         }
80
81         /// <summary>
82         /// Retrieves the number of elements in the map.
83         /// </summary>
84         /// <returns>The number of elements in the map.</returns>
85         /// <since_tizen> 3 </since_tizen>
86         public uint Count()
87         {
88             uint ret = Interop.PropertyMap.Property_Map_Count(swigCPtr);
89             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
90             return ret;
91         }
92
93         /// <summary>
94         /// Returns whether the map is empty.
95         /// </summary>
96         /// <returns>Returns true if empty, false otherwise.</returns>
97         /// <since_tizen> 3 </since_tizen>
98         public bool Empty()
99         {
100             bool ret = Interop.PropertyMap.Property_Map_Empty(swigCPtr);
101             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102             return ret;
103         }
104
105         /// <summary>
106         /// Inserts the key-value pair in the map, with the key type as string.<br />
107         /// Does not check for duplicates.<br />
108         /// </summary>
109         /// <param name="key">The key to insert.</param>
110         /// <param name="value">The value to insert.</param>
111         /// <since_tizen> 3 </since_tizen>
112         public void Insert(string key, PropertyValue value)
113         {
114             Interop.PropertyMap.Property_Map_Insert__SWIG_0(swigCPtr, key, PropertyValue.getCPtr(value));
115             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
116         }
117
118         /// <summary>
119         /// Inserts the key-value pair in the map, with the key type as index.<br />
120         /// Does not check for duplicates.<br />
121         /// </summary>
122         /// <param name="key">The key to insert.</param>
123         /// <param name="value">The value to insert.</param>
124         /// <since_tizen> 3 </since_tizen>
125         public void Insert(int key, PropertyValue value)
126         {
127             Interop.PropertyMap.Property_Map_Insert__SWIG_2(swigCPtr, key, PropertyValue.getCPtr(value));
128             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
129         }
130
131         /// <summary>
132         /// Inserts the key-value pair in the map, with the key type as string.<br />
133         /// Does not check for duplicates.<br />
134         /// </summary>
135         /// <param name="key">The key to insert.</param>
136         /// <param name="value">The value to insert.</param>
137         /// <returns>Returns a reference to this object.</returns>
138         /// <since_tizen> 3 </since_tizen>
139         public PropertyMap Add(string key, PropertyValue value)
140         {
141             PropertyMap ret = new PropertyMap(Interop.PropertyMap.Property_Map_Add__SWIG_0(swigCPtr, key, PropertyValue.getCPtr(value)), false);
142             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143             return ret;
144         }
145
146         /// <summary>
147         /// Inserts the key-value pair in the map, with the key type as string.<br />
148         /// Does not check for duplicates.<br />
149         /// </summary>
150         /// <param name="key">The key to insert.</param>
151         /// <param name="value">The value to insert.</param>
152         /// <returns>Returns a reference to this object.</returns>
153         /// <since_tizen> 3 </since_tizen>
154         public PropertyMap Add(int key, PropertyValue value)
155         {
156             PropertyMap ret = new PropertyMap(Interop.PropertyMap.Property_Map_Add__SWIG_2(swigCPtr, key, PropertyValue.getCPtr(value)), false);
157             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158             return ret;
159         }
160
161         /// <summary>
162         /// Inserts the keyvalue to the map.<br />
163         /// Does not check for duplicates.<br />
164         /// </summary>
165         /// <param name="keyValue">The keyvalue to insert.</param>
166         /// <returns>Returns a reference to this object.</returns>
167         public PropertyMap Add(KeyValue keyValue)
168         {
169             PropertyMap ret = new PropertyMap();
170             if ( keyValue.KeyInt != null )
171             {
172                 ret = new PropertyMap(Interop.PropertyMap.Property_Map_Add__SWIG_2(swigCPtr, (int)keyValue.KeyInt, PropertyValue.getCPtr(keyValue.TrueValue)), false);
173             }
174             else if ( keyValue.KeyString != null )
175             {
176                 ret = new PropertyMap(Interop.PropertyMap.Property_Map_Add__SWIG_0(swigCPtr, keyValue.KeyString, PropertyValue.getCPtr(keyValue.TrueValue)), false);
177             }
178             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179
180             return ret;
181         }
182
183         /// <summary>
184         /// Retrieves the value at the specified position.
185         /// </summary>
186         /// <param name="position">The specified position.</param>
187         /// <returns>A reference to the value at the specified position.</returns>
188         /// <since_tizen> 3 </since_tizen>
189         public PropertyValue GetValue(uint position)
190         {
191             PropertyValue ret = new PropertyValue(Interop.PropertyMap.Property_Map_GetValue(swigCPtr, position), false);
192             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193             return ret;
194         }
195
196         /// <summary>
197         /// Retrieves the key at the specified position.
198         /// </summary>
199         /// <param name="position">The specified position.</param>
200         /// <returns>A copy of the key at the specified position.</returns>
201         /// <since_tizen> 3 </since_tizen>
202         public PropertyKey GetKeyAt(uint position)
203         {
204             PropertyKey ret = new PropertyKey(Interop.PropertyMap.Property_Map_GetKeyAt(swigCPtr, position), true);
205             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206             return ret;
207         }
208
209         /// <summary>
210         /// Finds the value for the specified key if it exists.
211         /// </summary>
212         /// <param name="key">The key to find.</param>
213         /// <returns>The value if it exists, an empty object otherwise.</returns>
214         /// <since_tizen> 3 </since_tizen>
215         public PropertyValue Find(int key)
216         {
217             global::System.IntPtr cPtr = Interop.PropertyMap.Property_Map_Find__SWIG_2(swigCPtr, key);
218             PropertyValue ret = (cPtr == global::System.IntPtr.Zero) ? null : new PropertyValue(cPtr, false);
219             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220             return ret;
221         }
222
223         /// <summary>
224         /// Finds the value for the specified keys if either exist.
225         /// </summary>
226         /// <param name="indexKey">The index key to find.</param>
227         /// <param name="stringKey">The string key to find.</param>
228         /// <returns>The value if it exists, an empty object otherwise.</returns>
229         /// <since_tizen> 3 </since_tizen>
230         public PropertyValue Find(int indexKey, string stringKey)
231         {
232             global::System.IntPtr cPtr = Interop.PropertyMap.Property_Map_Find__SWIG_3(swigCPtr, indexKey, stringKey);
233             PropertyValue ret = (cPtr == global::System.IntPtr.Zero) ? null : new PropertyValue(cPtr, false);
234             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235             return ret;
236         }
237
238         /// <summary>
239         /// Clears the map.
240         /// </summary>
241         /// <since_tizen> 3 </since_tizen>
242         public void Clear()
243         {
244             Interop.PropertyMap.Property_Map_Clear(swigCPtr);
245             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246         }
247
248         /// <summary>
249         /// Merges values from the map 'from' to the current.<br />
250         /// Any values in 'from' will overwrite the values in the current map.<br />
251         /// </summary>
252         /// <param name="from">The map to merge from.</param>
253         /// <since_tizen> 3 </since_tizen>
254         public void Merge(PropertyMap from)
255         {
256             Interop.PropertyMap.Property_Map_Merge(swigCPtr, PropertyMap.getCPtr(from));
257             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258         }
259
260         /// <summary>
261         /// Retrieves the element with the specified string key.
262         /// </summary>
263         /// <param name="key">The key whose value to retrieve.</param>
264         /// <returns>The value for the element with the specified key.</returns>
265         internal PropertyValue ValueOfIndex(string key)
266         {
267             PropertyValue ret = new PropertyValue(Interop.PropertyMap.Property_Map_ValueOfIndex__SWIG_0(swigCPtr, key), false);
268             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269             return ret;
270         }
271
272         /// <summary>
273         /// Retrieves the element with the specified index key.
274         /// </summary>
275         /// <param name="key">The key whose value to retrieve.</param>
276         /// <returns>The value for the element with the specified key.</returns>
277         internal PropertyValue ValueOfIndex(int key)
278         {
279             PropertyValue ret = new PropertyValue(Interop.PropertyMap.Property_Map_ValueOfIndex__SWIG_2(swigCPtr, key), false);
280             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281             return ret;
282         }
283
284         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PropertyMap obj)
285         {
286             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
287         }
288
289         /// This will not be public opened.
290         [EditorBrowsable(EditorBrowsableState.Never)]
291         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
292         {
293             Interop.PropertyMap.delete_Property_Map(swigCPtr);
294         }
295     }
296 }