From 3be9b6a12977b8cb550ab1f44b74d5e86b251014 Mon Sep 17 00:00:00 2001 From: Bruno da Silva Belo Date: Mon, 14 Oct 2019 11:22:56 -0300 Subject: [PATCH] csharp: updating eina_hash docs and hide api. Reviewers: lauromoura, felipealmeida, segfaultxavi, woohyun Reviewed By: lauromoura Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T8293 Differential Revision: https://phab.enlightenment.org/D10324 --- src/bindings/mono/eina_mono/eina_hash.cs | 160 ++++++++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-) diff --git a/src/bindings/mono/eina_mono/eina_hash.cs b/src/bindings/mono/eina_mono/eina_hash.cs index f4678a1f26..04acc4f3d0 100644 --- a/src/bindings/mono/eina_mono/eina_hash.cs +++ b/src/bindings/mono/eina_mono/eina_hash.cs @@ -3,6 +3,7 @@ using System; using System.Runtime.InteropServices; using System.Collections.Generic; +using System.ComponentModel; using static Eina.TraitFunctions; using static Eina.IteratorNativeFunctions; @@ -13,6 +14,7 @@ namespace Eina { [StructLayout(LayoutKind.Sequential)] +[EditorBrowsable(EditorBrowsableState.Never)] public struct HashTupleNative { public IntPtr key; @@ -20,6 +22,7 @@ public struct HashTupleNative public uint key_length; } +[EditorBrowsable(EditorBrowsableState.Never)] public static class HashNativeFunctions { [DllImport(efl.Libs.Eina)] public static extern IntPtr @@ -136,11 +139,24 @@ public static class HashNativeFunctions /// public class Hash : IEnumerable>, IDisposable { + [EditorBrowsable(EditorBrowsableState.Never)] public IntPtr Handle {get; set;} = IntPtr.Zero; + /// Whether this wrapper owns the native hash. + /// Since EFL 1.23. + /// public bool Own {get; set;} + /// Whether this wrapper owns the key. + /// Since EFL 1.23. + /// public bool OwnKey {get; set;} + /// Whether this wrapper owns the value. + /// Since EFL 1.23. + /// public bool OwnValue {get; set;} + /// Quantity of elements in the hash. + /// Since EFL 1.23. + /// public int Count { get @@ -158,28 +174,42 @@ public class Hash : IEnumerable>, IDi SetOwnValue(true); } + /// Default constructor. + /// Since EFL 1.23. + /// public Hash() { InitNew(); } + [EditorBrowsable(EditorBrowsableState.Never)] public Hash(IntPtr handle, bool own) { Handle = handle; SetOwnership(own); } + [EditorBrowsable(EditorBrowsableState.Never)] public Hash(IntPtr handle, bool own, bool ownKey, bool ownValue) { Handle = handle; SetOwnership(own, ownKey, ownValue); } + /// Default destructor. + /// Since EFL 1.23. + /// ~Hash() { Dispose(false); } + /// Disposes of this wrapper, releasing the native accessor if + /// owned. + /// Since EFL 1.23. + /// + /// True if this was called from public method. False if + /// called from the C# finalizer. protected virtual void Dispose(bool disposing) { IntPtr h = Handle; @@ -202,17 +232,27 @@ public class Hash : IEnumerable>, IDi } } + /// Release the native resources held by this instance. + /// Since EFL 1.23. + /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } + /// Release the native resources held by this instance. + /// Since EFL 1.23. + /// public void Free() { Dispose(); } + /// Release the pointer. + /// Since EFL 1.23. + /// + /// The instance. public IntPtr Release() { IntPtr h = Handle; @@ -220,16 +260,28 @@ public class Hash : IEnumerable>, IDi return h; } + /// Sets ownership. + /// Since EFL 1.23. + /// + /// If the hash own the object. public void SetOwn(bool own) { Own = own; } + /// Sets key's ownership. + /// Since EFL 1.23. + /// + /// If the hash own the key's object. public void SetOwnKey(bool ownKey) { OwnKey = ownKey; } + /// Sets value's ownership. + /// Since EFL 1.23. + /// + /// If the hash own the value's object. public void SetOwnValue(bool ownValue) { OwnValue = ownValue; @@ -240,6 +292,10 @@ public class Hash : IEnumerable>, IDi } } + /// Sets all ownership. + /// Since EFL 1.23. + /// + /// If the hash own for all ownerships. public void SetOwnership(bool ownAll) { SetOwn(ownAll); @@ -247,6 +303,12 @@ public class Hash : IEnumerable>, IDi SetOwnValue(ownAll); } + /// Sets own individually. + /// Since EFL 1.23. + /// + /// If the hash own the object. + /// If the hash own the key's object. + /// If the hash own the value's object. public void SetOwnership(bool own, bool ownKey, bool ownValue) { SetOwn(own); @@ -254,11 +316,22 @@ public class Hash : IEnumerable>, IDi SetOwnValue(ownValue); } + /// + /// Cleanup for the hash. + /// Since EFL 1.23. + /// public void UnSetFreeCb() { eina_hash_free_cb_set(Handle, IntPtr.Zero); } + /// + /// Adds an entry to the hash. + /// Since EFL 1.23. + /// + /// A unique key. + /// The value to associate with the key. + /// false if an error occurred, true otherwise. public bool AddNew(TKey key, TValue val) { IntPtr gchnk = CopyNativeObject(key, ForceRefKey()); @@ -271,11 +344,22 @@ public class Hash : IEnumerable>, IDi return r; } + /// + /// Modifies the entry at the specified key. + /// Since EFL 1.23. + /// + /// The key of the entry to modify. + /// The value to replace the previous entry. public void Add(TKey key, TValue val) { Set(key, val); } + /// + /// Removes the entry identified by a key from the hash. + /// Since EFL 1.23. + /// + /// The key. public bool DelByKey(TKey key) { IntPtr gchnk = CopyNativeObject(key, ForceRefKey()); @@ -285,7 +369,11 @@ public class Hash : IEnumerable>, IDi return r; } - /// Searches this hash for val and deletes it from the hash, also deleting it. + /// Searches this hash for val and deletes it from the hash, + /// also deleting it. + /// Since EFL 1.23. + /// + /// The value to be deleted. /// true if the value was found and deleted, false if it was null or not found. public bool DelByValue(TValue val) { @@ -309,11 +397,22 @@ public class Hash : IEnumerable>, IDi } + /// + /// Removes the entry identified by a key from the hash. + /// Since EFL 1.23. + /// + /// The key. public void Remove(TKey key) { DelByKey(key); } + /// + /// Retrieves a specific entry in the hash. + /// Since EFL 1.23. + /// + /// The key of the entry to find. + /// The value of the entry. public TValue Find(TKey key) { var gchnk = CopyNativeObject(key, ForceRefKey()); @@ -329,6 +428,13 @@ public class Hash : IEnumerable>, IDi return NativeToManaged(IndirectNative(found, false)); } + /// + /// Check if key is present. if not, a default value is setted. + /// Since EFL 1.23. + /// + /// The key to be checked. + /// [out] The value of the entry. + /// true if key exists, false otherwise. public bool TryGetValue(TKey key, out TValue val) { var gchnk = CopyNativeObject(key, ForceRefKey()); @@ -345,6 +451,12 @@ public class Hash : IEnumerable>, IDi return true; } + /// + /// Check if key is present. + /// Since EFL 1.23. + /// + /// The key to be checked. + /// true if key exists, false otherwise. public bool ContainsKey(TKey key) { var gchnk = CopyNativeObject(key, ForceRefKey()); @@ -356,6 +468,13 @@ public class Hash : IEnumerable>, IDi return found != IntPtr.Zero; } + /// + /// Modifies the speficied key if exists. + /// Since EFL 1.23. + /// + /// The key to modify. + /// The new value. + /// False if key do not exists, true otherwise. public bool Modify(TKey key, TValue val) { var gchnk = CopyNativeObject(key, ForceRefKey()); @@ -449,6 +568,13 @@ public class Hash : IEnumerable>, IDi } } + + /// + /// Modifies the entry at the specified key. Adds if key is not found. + /// Since EFL 1.23. + /// + /// The key to modify. + /// The value to replace the previous entry. public void Set(TKey key, TValue val) { IntPtr gchnk = CopyNativeObject(key, ForceRefKey()); @@ -465,6 +591,10 @@ public class Hash : IEnumerable>, IDi } } + /// + /// Accessor by key to the hash. + /// Since EFL 1.23. + /// public TValue this[TKey key] { get @@ -477,6 +607,13 @@ public class Hash : IEnumerable>, IDi } } + /// + /// Changes the keys of an entry in the hash. + /// Since EFL 1.23. + /// + /// The current key with data. + /// The new key with data. + /// false in any case but success, true on success. public bool Move(TKey key_old, TKey key_new) { IntPtr gchnko = CopyNativeObject(key_old, ForceRefKey()); @@ -493,26 +630,47 @@ public class Hash : IEnumerable>, IDi return r; } + /// + /// Frees the hash buckets. + /// Since EFL 1.23. + /// public void FreeBuckets() { eina_hash_free_buckets(Handle); } + /// + /// Returns the number of entries in the hash. + /// Since EFL 1.23. + /// + /// The number of entries, 0 on error. public int Population() { return eina_hash_population(Handle); } + /// + /// Gets an Iterator for keys. + /// Since EFL 1.23. + /// public Eina.Iterator Keys() { return new Eina.Iterator(EinaHashIteratorKeyNew(Handle), true); } + /// + /// Gets An Iterator for values. + /// Since EFL 1.23. + /// public Eina.Iterator Values() { return new Eina.Iterator(eina_hash_iterator_data_new(Handle), true); } + /// + /// Gets an Iterator for hask. + /// Since EFL 1.23. + /// public IEnumerator> GetEnumerator() { IntPtr itr = eina_hash_iterator_tuple_new(Handle);