[NUI] Fixing the emtpy finalizers(CA1821)
[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.NewPropertyMap(), 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.NewPropertyMap(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             internal set
65             {
66                 SetValue(key, value);
67             }
68         }
69
70         /// <summary>
71         /// The operator to access the element with the specified index key.<br />
72         /// If an element with the key does not exist, then it is created.<br />
73         /// </summary>
74         /// <param name="key">The key whose value to access.</param>
75         /// <returns>A value for the element with the specified key.</returns>
76         /// <since_tizen> 3 </since_tizen>
77         public PropertyValue this[int key]
78         {
79             get
80             {
81                 return ValueOfIndex(key);
82             }
83             internal set
84             {
85                 SetValue(key, value);
86             }
87         }
88
89         /// <summary>
90         /// Retrieves the number of elements in the map.
91         /// </summary>
92         /// <returns>The number of elements in the map.</returns>
93         /// <since_tizen> 3 </since_tizen>
94         public uint Count()
95         {
96             uint ret = Interop.PropertyMap.Count(SwigCPtr);
97             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
98             return ret;
99         }
100
101         /// <summary>
102         /// Returns whether the map is empty.
103         /// </summary>
104         /// <returns>Returns true if empty, false otherwise.</returns>
105         /// <since_tizen> 3 </since_tizen>
106         public bool Empty()
107         {
108             bool ret = Interop.PropertyMap.Empty(SwigCPtr);
109             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110             return ret;
111         }
112
113         /// <summary>
114         /// Inserts the key-value pair in the map, with the key type as string.<br />
115         /// Does not check for duplicates.<br />
116         /// </summary>
117         /// <param name="key">The key to insert.</param>
118         /// <param name="value">The value to insert.</param>
119         /// <since_tizen> 3 </since_tizen>
120         public void Insert(string key, PropertyValue value)
121         {
122             Interop.PropertyMap.Insert(SwigCPtr, key, PropertyValue.getCPtr(value));
123             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124         }
125
126         /// <summary>
127         /// Inserts the key-value pair in the map, with the key type as index.<br />
128         /// Does not check for duplicates.<br />
129         /// </summary>
130         /// <param name="key">The key to insert.</param>
131         /// <param name="value">The value to insert.</param>
132         /// <since_tizen> 3 </since_tizen>
133         public void Insert(int key, PropertyValue value)
134         {
135             Interop.PropertyMap.Insert(SwigCPtr, key, PropertyValue.getCPtr(value));
136             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137         }
138
139         /// <summary>
140         /// Inserts the key-value pair in the map, with the key type as string.<br />
141         /// Does not check for duplicates.<br />
142         /// </summary>
143         /// <param name="key">The key to insert.</param>
144         /// <param name="value">The value to insert.</param>
145         /// <returns>Returns a reference to this object.</returns>
146         /// <since_tizen> 3 </since_tizen>
147         public PropertyMap Add(string key, PropertyValue value)
148         {
149             Interop.PropertyMap.Add(SwigCPtr, key, PropertyValue.getCPtr(value));
150             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
151             return this;
152         }
153
154         /// <summary>
155         /// Inserts the key-value pair in the map, with the key type as string.<br />
156         /// Does not check for duplicates.<br />
157         /// </summary>
158         /// <param name="key">The key to insert.</param>
159         /// <param name="value">The value to insert.</param>
160         /// <returns>Returns a reference to this object.</returns>
161         /// <since_tizen> 3 </since_tizen>
162         public PropertyMap Add(int key, PropertyValue value)
163         {
164             Interop.PropertyMap.Add(SwigCPtr, key, PropertyValue.getCPtr(value));
165             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
166             return this;
167         }
168
169         /// <summary>
170         /// Inserts the keyvalue to the map.<br />
171         /// Does not check for duplicates.<br />
172         /// </summary>
173         /// <param name="keyValue">The keyvalue to insert.</param>
174         /// <returns>Returns a reference to this object.</returns>
175         /// <exception cref="global::System.ArgumentNullException"> Thrown when keyValue is null. </exception>
176         public PropertyMap Add(KeyValue keyValue)
177         {
178             if (null == keyValue)
179             {
180                 throw new global::System.ArgumentNullException(nameof(keyValue));
181             }
182             if (keyValue.KeyInt != null)
183             {
184                 Interop.PropertyMap.Add(SwigCPtr, (int)keyValue.KeyInt, PropertyValue.getCPtr(keyValue.TrueValue));
185             }
186             else if (keyValue.KeyString != null)
187             {
188                 Interop.PropertyMap.Add(SwigCPtr, keyValue.KeyString, PropertyValue.getCPtr(keyValue.TrueValue));
189             }
190             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191
192             return this;
193         }
194
195         /// <summary>
196         /// Retrieves the value at the specified position.
197         /// </summary>
198         /// <param name="position">The specified position.</param>
199         /// <returns>A reference to the value at the specified position.</returns>
200         /// <since_tizen> 3 </since_tizen>
201         public PropertyValue GetValue(uint position)
202         {
203             PropertyValue ret = new PropertyValue(Interop.PropertyMap.GetValue(SwigCPtr, position), false);
204             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205             return ret;
206         }
207
208         /// <summary>
209         /// Retrieves the key at the specified position.
210         /// </summary>
211         /// <param name="position">The specified position.</param>
212         /// <returns>A copy of the key at the specified position.</returns>
213         /// <since_tizen> 3 </since_tizen>
214         public PropertyKey GetKeyAt(uint position)
215         {
216             PropertyKey ret = new PropertyKey(Interop.PropertyMap.GetKeyAt(SwigCPtr, position), true);
217             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
218             return ret;
219         }
220
221         /// <summary>
222         /// Finds the value for the specified key if it exists.
223         /// </summary>
224         /// <param name="key">The key to find.</param>
225         /// <returns>The value if it exists, an empty object otherwise.</returns>
226         /// <since_tizen> 3 </since_tizen>
227         public PropertyValue Find(int key)
228         {
229             global::System.IntPtr cPtr = Interop.PropertyMap.Find(SwigCPtr, key);
230             PropertyValue ret = (cPtr == global::System.IntPtr.Zero) ? null : new PropertyValue(cPtr, false);
231             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
232             return ret;
233         }
234
235         /// <summary>
236         /// Finds the value for the specified keys if either exist.
237         /// </summary>
238         /// <param name="indexKey">The index key to find.</param>
239         /// <param name="stringKey">The string key to find.</param>
240         /// <returns>The value if it exists, an empty object otherwise.</returns>
241         /// <since_tizen> 3 </since_tizen>
242         public PropertyValue Find(int indexKey, string stringKey)
243         {
244             global::System.IntPtr cPtr = Interop.PropertyMap.Find(SwigCPtr, indexKey, stringKey);
245             PropertyValue ret = (cPtr == global::System.IntPtr.Zero) ? null : new PropertyValue(cPtr, false);
246             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247             return ret;
248         }
249
250         /// <summary>
251         /// Clears the map.
252         /// </summary>
253         /// <since_tizen> 3 </since_tizen>
254         public void Clear()
255         {
256             Interop.PropertyMap.Clear(SwigCPtr);
257             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258         }
259
260         /// <summary>
261         /// Merges values from the map 'from' to the current.<br />
262         /// Any values in 'from' will overwrite the values in the current map.<br />
263         /// </summary>
264         /// <param name="from">The map to merge from.</param>
265         /// <since_tizen> 3 </since_tizen>
266         public void Merge(PropertyMap from)
267         {
268             Interop.PropertyMap.Merge(SwigCPtr, PropertyMap.getCPtr(from));
269             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270         }
271
272         /// <summary>
273         /// Retrieves the element with the specified string 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(string key)
278         {
279             PropertyValue ret = new PropertyValue(Interop.PropertyMap.ValueOfIndex(SwigCPtr, key), false);
280             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281             return ret;
282         }
283
284         /// <summary>
285         /// Retrieves the element with the specified index key.
286         /// </summary>
287         /// <param name="key">The key whose value to retrieve.</param>
288         /// <returns>The value for the element with the specified key.</returns>
289         internal PropertyValue ValueOfIndex(int key)
290         {
291             PropertyValue ret = new PropertyValue(Interop.PropertyMap.ValueOfIndex(SwigCPtr, key), false);
292             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293             return ret;
294         }
295
296         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PropertyMap obj)
297         {
298             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
299         }
300
301         internal void SetValue(int key, PropertyValue value)
302         {
303             Interop.PropertyMap.SetValueIntKey(SwigCPtr, key, PropertyValue.getCPtr(value));
304             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305         }
306
307         internal void SetValue(string key, PropertyValue value)
308         {
309             Interop.PropertyMap.SetValueStringKey(SwigCPtr, key, PropertyValue.getCPtr(value));
310             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311         }
312
313         /// This will not be public opened.
314         [EditorBrowsable(EditorBrowsableState.Never)]
315         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
316         {
317             Interop.PropertyMap.DeletePropertyMap(swigCPtr);
318         }
319     }
320 }