/* * Copyright(c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ using System.ComponentModel; namespace Tizen.NUI { /// /// A map of property values, the key type could be string or Property::Index. /// /// 3 public class PropertyMap : Disposable { /// /// The constructor. /// /// 3 public PropertyMap() : this(Interop.PropertyMap.NewPropertyMap(), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// The copy constructor. /// /// The map to copy from. /// 3 public PropertyMap(PropertyMap other) : this(Interop.PropertyMap.NewPropertyMap(PropertyMap.getCPtr(other)), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal PropertyMap(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) { } /// /// The operator to access the element with the specified string key.
/// If an element with the key does not exist, then it is created.
///
/// The key whose value to access. /// A value for the element with the specified key. /// 3 public PropertyValue this[string key] { get { return ValueOfIndex(key); } internal set { SetValue(key, value); } } /// /// The operator to access the element with the specified index key.
/// If an element with the key does not exist, then it is created.
///
/// The key whose value to access. /// A value for the element with the specified key. /// 3 public PropertyValue this[int key] { get { return ValueOfIndex(key); } internal set { SetValue(key, value); } } /// /// Retrieves the number of elements in the map. /// /// The number of elements in the map. /// 3 public uint Count() { uint ret = Interop.PropertyMap.Count(SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Returns whether the map is empty. /// /// Returns true if empty, false otherwise. /// 3 public bool Empty() { bool ret = Interop.PropertyMap.Empty(SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Inserts the key-value pair in the map, with the key type as string.
/// Does not check for duplicates.
///
/// The key to insert. /// The value to insert. /// 3 public void Insert(string key, PropertyValue value) { Interop.PropertyMap.Insert(SwigCPtr, key, PropertyValue.getCPtr(value)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Inserts the key-value pair in the map, with the key type as index.
/// Does not check for duplicates.
///
/// The key to insert. /// The value to insert. /// 3 public void Insert(int key, PropertyValue value) { Interop.PropertyMap.Insert(SwigCPtr, key, PropertyValue.getCPtr(value)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Inserts the key-value pair in the map, with the key type as string.
/// Does not check for duplicates.
///
/// The key to insert. /// The value to insert. /// Returns a reference to this object. /// 3 public PropertyMap Add(string key, PropertyValue value) { Interop.PropertyMap.Add(SwigCPtr, key, PropertyValue.getCPtr(value)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return this; } /// /// Inserts the key-value pair in the map, with the key type as string.
/// Does not check for duplicates.
///
/// The key to insert. /// The value to insert. /// Returns a reference to this object. /// 3 public PropertyMap Add(int key, PropertyValue value) { Interop.PropertyMap.Add(SwigCPtr, key, PropertyValue.getCPtr(value)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return this; } /// /// Inserts the keyvalue to the map.
/// Does not check for duplicates.
///
/// The keyvalue to insert. /// Returns a reference to this object. /// Thrown when keyValue is null. public PropertyMap Add(KeyValue keyValue) { if (null == keyValue) { throw new global::System.ArgumentNullException(nameof(keyValue)); } if (keyValue.KeyInt != null) { Interop.PropertyMap.Add(SwigCPtr, (int)keyValue.KeyInt, PropertyValue.getCPtr(keyValue.TrueValue)); } else if (keyValue.KeyString != null) { Interop.PropertyMap.Add(SwigCPtr, keyValue.KeyString, PropertyValue.getCPtr(keyValue.TrueValue)); } if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return this; } /// /// Retrieves the value at the specified position. /// /// The specified position. /// A reference to the value at the specified position. /// 3 public PropertyValue GetValue(uint position) { PropertyValue ret = new PropertyValue(Interop.PropertyMap.GetValue(SwigCPtr, position), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Retrieves the key at the specified position. /// /// The specified position. /// A copy of the key at the specified position. /// 3 public PropertyKey GetKeyAt(uint position) { PropertyKey ret = new PropertyKey(Interop.PropertyMap.GetKeyAt(SwigCPtr, position), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Finds the value for the specified key if it exists. /// /// The key to find. /// The value if it exists, an empty object otherwise. /// 3 public PropertyValue Find(int key) { global::System.IntPtr cPtr = Interop.PropertyMap.Find(SwigCPtr, key); PropertyValue ret = (cPtr == global::System.IntPtr.Zero) ? null : new PropertyValue(cPtr, false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Finds the value for the specified keys if either exist. /// /// The index key to find. /// The string key to find. /// The value if it exists, an empty object otherwise. /// 3 public PropertyValue Find(int indexKey, string stringKey) { global::System.IntPtr cPtr = Interop.PropertyMap.Find(SwigCPtr, indexKey, stringKey); PropertyValue ret = (cPtr == global::System.IntPtr.Zero) ? null : new PropertyValue(cPtr, false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Clears the map. /// /// 3 public void Clear() { Interop.PropertyMap.Clear(SwigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Merges values from the map 'from' to the current.
/// Any values in 'from' will overwrite the values in the current map.
///
/// The map to merge from. /// 3 public void Merge(PropertyMap from) { Interop.PropertyMap.Merge(SwigCPtr, PropertyMap.getCPtr(from)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Retrieves the element with the specified string key. /// /// The key whose value to retrieve. /// The value for the element with the specified key. internal PropertyValue ValueOfIndex(string key) { PropertyValue ret = new PropertyValue(Interop.PropertyMap.ValueOfIndex(SwigCPtr, key), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Retrieves the element with the specified index key. /// /// The key whose value to retrieve. /// The value for the element with the specified key. internal PropertyValue ValueOfIndex(int key) { PropertyValue ret = new PropertyValue(Interop.PropertyMap.ValueOfIndex(SwigCPtr, key), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PropertyMap obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr; } internal void SetValue(int key, PropertyValue value) { Interop.PropertyMap.SetValueIntKey(SwigCPtr, key, PropertyValue.getCPtr(value)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal void SetValue(string key, PropertyValue value) { Interop.PropertyMap.SetValueStringKey(SwigCPtr, key, PropertyValue.getCPtr(value)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// This will not be public opened. [EditorBrowsable(EditorBrowsableState.Never)] protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) { Interop.PropertyMap.DeletePropertyMap(swigCPtr); } } }