summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno da Silva Belo <brunodasilvabelo@gmail.com>2019-10-14 11:22:56 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-10-14 11:31:19 -0300
commit3be9b6a12977b8cb550ab1f44b74d5e86b251014 (patch)
tree0e53c5de9766f271d81310ab30fdb49f5974b8d4
parent4eee6f560c7f42aedf59002f976d14eeea8c3143 (diff)
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
-rw-r--r--src/bindings/mono/eina_mono/eina_hash.cs160
1 files changed, 159 insertions, 1 deletions
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 @@
3using System; 3using System;
4using System.Runtime.InteropServices; 4using System.Runtime.InteropServices;
5using System.Collections.Generic; 5using System.Collections.Generic;
6using System.ComponentModel;
6 7
7using static Eina.TraitFunctions; 8using static Eina.TraitFunctions;
8using static Eina.IteratorNativeFunctions; 9using static Eina.IteratorNativeFunctions;
@@ -13,6 +14,7 @@ namespace Eina
13{ 14{
14 15
15[StructLayout(LayoutKind.Sequential)] 16[StructLayout(LayoutKind.Sequential)]
17[EditorBrowsable(EditorBrowsableState.Never)]
16public struct HashTupleNative 18public struct HashTupleNative
17{ 19{
18 public IntPtr key; 20 public IntPtr key;
@@ -20,6 +22,7 @@ public struct HashTupleNative
20 public uint key_length; 22 public uint key_length;
21} 23}
22 24
25[EditorBrowsable(EditorBrowsableState.Never)]
23public static class HashNativeFunctions 26public static class HashNativeFunctions
24{ 27{
25 [DllImport(efl.Libs.Eina)] public static extern IntPtr 28 [DllImport(efl.Libs.Eina)] public static extern IntPtr
@@ -136,11 +139,24 @@ public static class HashNativeFunctions
136/// </summary> 139/// </summary>
137public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDisposable 140public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDisposable
138{ 141{
142 [EditorBrowsable(EditorBrowsableState.Never)]
139 public IntPtr Handle {get; set;} = IntPtr.Zero; 143 public IntPtr Handle {get; set;} = IntPtr.Zero;
144 /// <summary>Whether this wrapper owns the native hash.
145 /// <para>Since EFL 1.23.</para>
146 /// </summary>
140 public bool Own {get; set;} 147 public bool Own {get; set;}
148 /// <summary>Whether this wrapper owns the key.
149 /// <para>Since EFL 1.23.</para>
150 /// </summary>
141 public bool OwnKey {get; set;} 151 public bool OwnKey {get; set;}
152 /// <summary>Whether this wrapper owns the value.
153 /// <para>Since EFL 1.23.</para>
154 /// </summary>
142 public bool OwnValue {get; set;} 155 public bool OwnValue {get; set;}
143 156
157 /// <summary>Quantity of elements in the hash.
158 /// <para>Since EFL 1.23.</para>
159 /// </summary>
144 public int Count 160 public int Count
145 { 161 {
146 get 162 get
@@ -158,28 +174,42 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
158 SetOwnValue(true); 174 SetOwnValue(true);
159 } 175 }
160 176
177 /// <summary>Default constructor.
178 /// <para>Since EFL 1.23.</para>
179 /// </summary>
161 public Hash() 180 public Hash()
162 { 181 {
163 InitNew(); 182 InitNew();
164 } 183 }
165 184
185 [EditorBrowsable(EditorBrowsableState.Never)]
166 public Hash(IntPtr handle, bool own) 186 public Hash(IntPtr handle, bool own)
167 { 187 {
168 Handle = handle; 188 Handle = handle;
169 SetOwnership(own); 189 SetOwnership(own);
170 } 190 }
171 191
192 [EditorBrowsable(EditorBrowsableState.Never)]
172 public Hash(IntPtr handle, bool own, bool ownKey, bool ownValue) 193 public Hash(IntPtr handle, bool own, bool ownKey, bool ownValue)
173 { 194 {
174 Handle = handle; 195 Handle = handle;
175 SetOwnership(own, ownKey, ownValue); 196 SetOwnership(own, ownKey, ownValue);
176 } 197 }
177 198
199 /// <summary>Default destructor.
200 /// <para>Since EFL 1.23.</para>
201 /// </summary>
178 ~Hash() 202 ~Hash()
179 { 203 {
180 Dispose(false); 204 Dispose(false);
181 } 205 }
182 206
207 /// <summary>Disposes of this wrapper, releasing the native accessor if
208 /// owned.
209 /// <para>Since EFL 1.23.</para>
210 /// </summary>
211 /// <param name="disposing">True if this was called from <see cref="Dispose()"/> public method. False if
212 /// called from the C# finalizer.</param>
183 protected virtual void Dispose(bool disposing) 213 protected virtual void Dispose(bool disposing)
184 { 214 {
185 IntPtr h = Handle; 215 IntPtr h = Handle;
@@ -202,17 +232,27 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
202 } 232 }
203 } 233 }
204 234
235 /// <summary>Release the native resources held by this instance.
236 /// <para>Since EFL 1.23.</para>
237 /// </summary>
205 public void Dispose() 238 public void Dispose()
206 { 239 {
207 Dispose(true); 240 Dispose(true);
208 GC.SuppressFinalize(this); 241 GC.SuppressFinalize(this);
209 } 242 }
210 243
244 /// <summary>Release the native resources held by this instance.
245 /// <para>Since EFL 1.23.</para>
246 /// </summary>
211 public void Free() 247 public void Free()
212 { 248 {
213 Dispose(); 249 Dispose();
214 } 250 }
215 251
252 /// <summary>Release the pointer.
253 /// <para>Since EFL 1.23.</para>
254 /// </summary>
255 /// <returns>The instance.</returns>
216 public IntPtr Release() 256 public IntPtr Release()
217 { 257 {
218 IntPtr h = Handle; 258 IntPtr h = Handle;
@@ -220,16 +260,28 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
220 return h; 260 return h;
221 } 261 }
222 262
263 /// <summary>Sets ownership.
264 /// <para>Since EFL 1.23.</para>
265 /// </summary>
266 /// <param name="own">If the hash own the object.</param>
223 public void SetOwn(bool own) 267 public void SetOwn(bool own)
224 { 268 {
225 Own = own; 269 Own = own;
226 } 270 }
227 271
272 /// <summary>Sets key's ownership.
273 /// <para>Since EFL 1.23.</para>
274 /// </summary>
275 /// <param name="ownKey">If the hash own the key's object.</param>
228 public void SetOwnKey(bool ownKey) 276 public void SetOwnKey(bool ownKey)
229 { 277 {
230 OwnKey = ownKey; 278 OwnKey = ownKey;
231 } 279 }
232 280
281 /// <summary>Sets value's ownership.
282 /// <para>Since EFL 1.23.</para>
283 /// </summary>
284 /// <param name="ownValue">If the hash own the value's object.</param>
233 public void SetOwnValue(bool ownValue) 285 public void SetOwnValue(bool ownValue)
234 { 286 {
235 OwnValue = ownValue; 287 OwnValue = ownValue;
@@ -240,6 +292,10 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
240 } 292 }
241 } 293 }
242 294
295 /// <summary>Sets all ownership.
296 /// <para>Since EFL 1.23.</para>
297 /// </summary>
298 /// <param name="ownAll">If the hash own for all ownerships.</param>
243 public void SetOwnership(bool ownAll) 299 public void SetOwnership(bool ownAll)
244 { 300 {
245 SetOwn(ownAll); 301 SetOwn(ownAll);
@@ -247,6 +303,12 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
247 SetOwnValue(ownAll); 303 SetOwnValue(ownAll);
248 } 304 }
249 305
306 /// <summary>Sets own individually.
307 /// <para>Since EFL 1.23.</para>
308 /// </summary>
309 /// <param name="own">If the hash own the object.</param>
310 /// <param name="ownKey">If the hash own the key's object.</param>
311 /// <param name="ownValue">If the hash own the value's object.</param>
250 public void SetOwnership(bool own, bool ownKey, bool ownValue) 312 public void SetOwnership(bool own, bool ownKey, bool ownValue)
251 { 313 {
252 SetOwn(own); 314 SetOwn(own);
@@ -254,11 +316,22 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
254 SetOwnValue(ownValue); 316 SetOwnValue(ownValue);
255 } 317 }
256 318
319 /// <summary>
320 /// Cleanup for the hash.
321 /// <para>Since EFL 1.23.</para>
322 /// </summary>
257 public void UnSetFreeCb() 323 public void UnSetFreeCb()
258 { 324 {
259 eina_hash_free_cb_set(Handle, IntPtr.Zero); 325 eina_hash_free_cb_set(Handle, IntPtr.Zero);
260 } 326 }
261 327
328 /// <summary>
329 /// Adds an entry to the hash.
330 /// <para>Since EFL 1.23.</para>
331 /// </summary>
332 /// <param name="key">A unique key.</param>
333 /// <param name="val">The value to associate with the key.</param>
334 /// <returns> false if an error occurred, true otherwise.</returns>
262 public bool AddNew(TKey key, TValue val) 335 public bool AddNew(TKey key, TValue val)
263 { 336 {
264 IntPtr gchnk = CopyNativeObject(key, ForceRefKey<TKey>()); 337 IntPtr gchnk = CopyNativeObject(key, ForceRefKey<TKey>());
@@ -271,11 +344,22 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
271 return r; 344 return r;
272 } 345 }
273 346
347 /// <summary>
348 /// Modifies the entry at the specified key.
349 /// <para>Since EFL 1.23.</para>
350 /// </summary>
351 /// <param name="key">The key of the entry to modify.</param>
352 /// <param name="val">The value to replace the previous entry.</param>
274 public void Add(TKey key, TValue val) 353 public void Add(TKey key, TValue val)
275 { 354 {
276 Set(key, val); 355 Set(key, val);
277 } 356 }
278 357
358 /// <summary>
359 /// Removes the entry identified by a key from the hash.
360 /// <para>Since EFL 1.23.</para>
361 /// </summary>
362 /// <param name="key">The key.</param>
279 public bool DelByKey(TKey key) 363 public bool DelByKey(TKey key)
280 { 364 {
281 IntPtr gchnk = CopyNativeObject(key, ForceRefKey<TKey>()); 365 IntPtr gchnk = CopyNativeObject(key, ForceRefKey<TKey>());
@@ -285,7 +369,11 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
285 return r; 369 return r;
286 } 370 }
287 371
288 /// <summary>Searches this hash for <c>val</c> and deletes it from the hash, also deleting it.</summary> 372 /// <summary>Searches this hash for <c>val</c> and deletes it from the hash,
373 /// also deleting it.
374 /// <para>Since EFL 1.23.</para>
375 /// </summary>
376 /// <param name="val">The value to be deleted.</param>
289 /// <returns><c>true</c> if the value was found and deleted, false if it was <c>null</c> or not found.</returns> 377 /// <returns><c>true</c> if the value was found and deleted, false if it was <c>null</c> or not found.</returns>
290 public bool DelByValue(TValue val) 378 public bool DelByValue(TValue val)
291 { 379 {
@@ -309,11 +397,22 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
309 397
310 } 398 }
311 399
400 /// <summary>
401 /// Removes the entry identified by a key from the hash.
402 /// <para>Since EFL 1.23.</para>
403 /// </summary>
404 /// <param name="key">The key.</param>
312 public void Remove(TKey key) 405 public void Remove(TKey key)
313 { 406 {
314 DelByKey(key); 407 DelByKey(key);
315 } 408 }
316 409
410 /// <summary>
411 /// Retrieves a specific entry in the hash.
412 /// <para>Since EFL 1.23.</para>
413 /// </summary>
414 /// <param name="key">The key of the entry to find.</param>
415 /// <returns>The value of the entry.</returns>
317 public TValue Find(TKey key) 416 public TValue Find(TKey key)
318 { 417 {
319 var gchnk = CopyNativeObject<TKey>(key, ForceRefKey<TKey>()); 418 var gchnk = CopyNativeObject<TKey>(key, ForceRefKey<TKey>());
@@ -329,6 +428,13 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
329 return NativeToManaged<TValue>(IndirectNative<TValue>(found, false)); 428 return NativeToManaged<TValue>(IndirectNative<TValue>(found, false));
330 } 429 }
331 430
431 /// <summary>
432 /// Check if key is present. if not, a default value is setted.
433 /// <para>Since EFL 1.23.</para>
434 /// </summary>
435 /// <param name="key">The key to be checked.</param>
436 /// <param name="val">[out] The value of the entry.</param>
437 /// <returns>true if key exists, false otherwise.</returns>
332 public bool TryGetValue(TKey key, out TValue val) 438 public bool TryGetValue(TKey key, out TValue val)
333 { 439 {
334 var gchnk = CopyNativeObject<TKey>(key, ForceRefKey<TKey>()); 440 var gchnk = CopyNativeObject<TKey>(key, ForceRefKey<TKey>());
@@ -345,6 +451,12 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
345 return true; 451 return true;
346 } 452 }
347 453
454 /// <summary>
455 /// Check if key is present.
456 /// <para>Since EFL 1.23.</para>
457 /// </summary>
458 /// <param name="key">The key to be checked.</param>
459 /// <returns>true if key exists, false otherwise.</returns>
348 public bool ContainsKey(TKey key) 460 public bool ContainsKey(TKey key)
349 { 461 {
350 var gchnk = CopyNativeObject<TKey>(key, ForceRefKey<TKey>()); 462 var gchnk = CopyNativeObject<TKey>(key, ForceRefKey<TKey>());
@@ -356,6 +468,13 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
356 return found != IntPtr.Zero; 468 return found != IntPtr.Zero;
357 } 469 }
358 470
471 /// <summary>
472 /// Modifies the speficied key if exists.
473 /// <para>Since EFL 1.23.</para>
474 /// </summary>
475 /// <param name="key">The key to modify.</param>
476 /// <param name="val"> The new value.</param>
477 /// <returns>False if key do not exists, true otherwise.</returns>
359 public bool Modify(TKey key, TValue val) 478 public bool Modify(TKey key, TValue val)
360 { 479 {
361 var gchnk = CopyNativeObject<TKey>(key, ForceRefKey<TKey>()); 480 var gchnk = CopyNativeObject<TKey>(key, ForceRefKey<TKey>());
@@ -449,6 +568,13 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
449 } 568 }
450 } 569 }
451 570
571
572 /// <summary>
573 /// Modifies the entry at the specified key. Adds if key is not found.
574 /// <para>Since EFL 1.23.</para>
575 /// </summary>
576 /// <param name="key">The key to modify.</param>
577 /// <param name="val">The value to replace the previous entry.</param>
452 public void Set(TKey key, TValue val) 578 public void Set(TKey key, TValue val)
453 { 579 {
454 IntPtr gchnk = CopyNativeObject(key, ForceRefKey<TKey>()); 580 IntPtr gchnk = CopyNativeObject(key, ForceRefKey<TKey>());
@@ -465,6 +591,10 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
465 } 591 }
466 } 592 }
467 593
594 /// <summary>
595 /// Accessor by key to the hash.
596 /// <para>Since EFL 1.23.</para>
597 /// </summary>
468 public TValue this[TKey key] 598 public TValue this[TKey key]
469 { 599 {
470 get 600 get
@@ -477,6 +607,13 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
477 } 607 }
478 } 608 }
479 609
610 /// <summary>
611 /// Changes the keys of an entry in the hash.
612 /// <para>Since EFL 1.23.</para>
613 /// </summary>
614 /// <param name="key_old">The current key with data.</param>
615 /// <param name="key_new">The new key with data.</param>
616 /// <returns>false in any case but success, true on success.</returns>
480 public bool Move(TKey key_old, TKey key_new) 617 public bool Move(TKey key_old, TKey key_new)
481 { 618 {
482 IntPtr gchnko = CopyNativeObject(key_old, ForceRefKey<TKey>()); 619 IntPtr gchnko = CopyNativeObject(key_old, ForceRefKey<TKey>());
@@ -493,26 +630,47 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
493 return r; 630 return r;
494 } 631 }
495 632
633 /// <summary>
634 /// Frees the hash buckets.
635 /// <para>Since EFL 1.23.</para>
636 /// </summary>
496 public void FreeBuckets() 637 public void FreeBuckets()
497 { 638 {
498 eina_hash_free_buckets(Handle); 639 eina_hash_free_buckets(Handle);
499 } 640 }
500 641
642 /// <summary>
643 /// Returns the number of entries in the hash.
644 /// <para>Since EFL 1.23.</para>
645 /// </summary>
646 /// <returns>The number of entries, 0 on error.</returns>
501 public int Population() 647 public int Population()
502 { 648 {
503 return eina_hash_population(Handle); 649 return eina_hash_population(Handle);
504 } 650 }
505 651
652 /// <summary>
653 /// Gets an Iterator for keys.
654 /// <para>Since EFL 1.23.</para>
655 /// </summary>
506 public Eina.Iterator<TKey> Keys() 656 public Eina.Iterator<TKey> Keys()
507 { 657 {
508 return new Eina.Iterator<TKey>(EinaHashIteratorKeyNew<TKey>(Handle), true); 658 return new Eina.Iterator<TKey>(EinaHashIteratorKeyNew<TKey>(Handle), true);
509 } 659 }
510 660
661 /// <summary>
662 /// Gets An Iterator for values.
663 /// <para>Since EFL 1.23.</para>
664 /// </summary>
511 public Eina.Iterator<TValue> Values() 665 public Eina.Iterator<TValue> Values()
512 { 666 {
513 return new Eina.Iterator<TValue>(eina_hash_iterator_data_new(Handle), true); 667 return new Eina.Iterator<TValue>(eina_hash_iterator_data_new(Handle), true);
514 } 668 }
515 669
670 /// <summary>
671 /// Gets an Iterator for hask.
672 /// <para>Since EFL 1.23.</para>
673 /// </summary>
516 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() 674 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
517 { 675 {
518 IntPtr itr = eina_hash_iterator_tuple_new(Handle); 676 IntPtr itr = eina_hash_iterator_tuple_new(Handle);