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