2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 using System.ComponentModel;
22 /// A map of property values, the key type could be string or Property::Index.
24 /// <since_tizen> 3 </since_tizen>
25 public class PropertyMap : Disposable
31 /// <since_tizen> 3 </since_tizen>
32 public PropertyMap() : this(Interop.PropertyMap.NewPropertyMap(), true)
34 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
38 /// The copy constructor.
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)
44 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
47 internal PropertyMap(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
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 />
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]
62 return ValueOfIndex(key);
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 />
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]
81 return ValueOfIndex(key);
90 /// Retrieves the number of elements in the map.
92 /// <returns>The number of elements in the map.</returns>
93 /// <since_tizen> 3 </since_tizen>
96 uint ret = Interop.PropertyMap.Count(SwigCPtr);
97 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102 /// Returns whether the map is empty.
104 /// <returns>Returns true if empty, false otherwise.</returns>
105 /// <since_tizen> 3 </since_tizen>
108 bool ret = Interop.PropertyMap.Empty(SwigCPtr);
109 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114 /// Inserts the key-value pair in the map, with the key type as string.<br />
115 /// Does not check for duplicates.<br />
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)
122 Interop.PropertyMap.Insert(SwigCPtr, key, PropertyValue.getCPtr(value));
123 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127 /// Inserts the key-value pair in the map, with the key type as index.<br />
128 /// Does not check for duplicates.<br />
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)
135 Interop.PropertyMap.Insert(SwigCPtr, key, PropertyValue.getCPtr(value));
136 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140 /// Inserts the key-value pair in the map, with the key type as string.<br />
141 /// Does not check for duplicates.<br />
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)
149 Interop.PropertyMap.Add(SwigCPtr, key, PropertyValue.getCPtr(value));
150 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
155 /// Inserts the key-value pair in the map, with the key type as string.<br />
156 /// Does not check for duplicates.<br />
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)
164 Interop.PropertyMap.Add(SwigCPtr, key, PropertyValue.getCPtr(value));
165 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170 /// Inserts the keyvalue to the map.<br />
171 /// Does not check for duplicates.<br />
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)
178 if (null == keyValue)
180 throw new global::System.ArgumentNullException(nameof(keyValue));
182 if (keyValue.KeyInt != null)
184 Interop.PropertyMap.Add(SwigCPtr, (int)keyValue.KeyInt, PropertyValue.getCPtr(keyValue.TrueValue));
186 else if (keyValue.KeyString != null)
188 Interop.PropertyMap.Add(SwigCPtr, keyValue.KeyString, PropertyValue.getCPtr(keyValue.TrueValue));
190 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196 /// Retrieves the value at the specified position.
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)
203 PropertyValue ret = new PropertyValue(Interop.PropertyMap.GetValue(SwigCPtr, position), false);
204 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209 /// Retrieves the key at the specified position.
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)
216 PropertyKey ret = new PropertyKey(Interop.PropertyMap.GetKeyAt(SwigCPtr, position), true);
217 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
222 /// Finds the value for the specified key if it exists.
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)
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();
236 /// Finds the value for the specified keys if either exist.
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)
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();
253 /// <since_tizen> 3 </since_tizen>
256 Interop.PropertyMap.Clear(SwigCPtr);
257 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
264 /// <param name="from">The map to merge from.</param>
265 /// <since_tizen> 3 </since_tizen>
266 public void Merge(PropertyMap from)
268 Interop.PropertyMap.Merge(SwigCPtr, PropertyMap.getCPtr(from));
269 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273 /// Retrieves the element with the specified string key.
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)
279 PropertyValue ret = new PropertyValue(Interop.PropertyMap.ValueOfIndex(SwigCPtr, key), false);
280 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285 /// Retrieves the element with the specified index key.
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)
291 PropertyValue ret = new PropertyValue(Interop.PropertyMap.ValueOfIndex(SwigCPtr, key), false);
292 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
296 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PropertyMap obj)
298 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
301 internal void SetValue(int key, PropertyValue value)
303 Interop.PropertyMap.SetValueIntKey(SwigCPtr, key, PropertyValue.getCPtr(value));
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307 internal void SetValue(string key, PropertyValue value)
309 Interop.PropertyMap.SetValueStringKey(SwigCPtr, key, PropertyValue.getCPtr(value));
310 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313 /// This will not be public opened.
314 [EditorBrowsable(EditorBrowsableState.Never)]
315 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
317 Interop.PropertyMap.DeletePropertyMap(swigCPtr);