summaryrefslogtreecommitdiff
path: root/src/bindings/mono/eina_mono/eina_list.cs
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-09-30 23:10:40 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2019-09-30 23:11:53 -0300
commit465b049d5b6b85dad1df111769bffd1e4f87a067 (patch)
tree5fd4aee445bc84038ea1d715b9abe404e5f49c72 /src/bindings/mono/eina_mono/eina_list.cs
parent74e79b5ae27efa7ed8f4baa1a9c1ae91cd52d178 (diff)
csharp: Document Eina.List
Summary: Also added Since 1.23 info Depends on D10253o ref T8293 Test Plan: Check docs Reviewers: segfaultxavi, brunobelo, felipealmeida Reviewed By: felipealmeida Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T8293 Differential Revision: https://phab.enlightenment.org/D10254
Diffstat (limited to 'src/bindings/mono/eina_mono/eina_list.cs')
-rw-r--r--src/bindings/mono/eina_mono/eina_list.cs67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/bindings/mono/eina_mono/eina_list.cs b/src/bindings/mono/eina_mono/eina_list.cs
index c65801c..7521ed6 100644
--- a/src/bindings/mono/eina_mono/eina_list.cs
+++ b/src/bindings/mono/eina_mono/eina_list.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.ListNativeFunctions; 9using static Eina.ListNativeFunctions;
@@ -11,6 +12,7 @@ using Eina.Callbacks;
11namespace Eina 12namespace Eina
12{ 13{
13 14
15[EditorBrowsable(EditorBrowsableState.Never)]
14public static class ListNativeFunctions 16public static class ListNativeFunctions
15{ 17{
16 [DllImport(efl.Libs.Eina)] public static extern IntPtr 18 [DllImport(efl.Libs.Eina)] public static extern IntPtr
@@ -104,16 +106,22 @@ public static class ListNativeFunctions
104 eina_list_last_data_get_custom_export_mono(IntPtr list); 106 eina_list_last_data_get_custom_export_mono(IntPtr list);
105} 107}
106 108
109/// <summary>Native wrapper around a linked list of items. (Since EFL 1.23)</summary>
107public class List<T> : IEnumerable<T>, IDisposable 110public class List<T> : IEnumerable<T>, IDisposable
108{ 111{
112
113 [EditorBrowsable(EditorBrowsableState.Never)]
109 public IntPtr Handle {get;set;} = IntPtr.Zero; 114 public IntPtr Handle {get;set;} = IntPtr.Zero;
115 /// <summary>Whether this managed list owns the native one.</summary>
110 public bool Own {get;set;} 116 public bool Own {get;set;}
117 /// <summary>Whether the native list wrapped owns the content it points to.</summary>
111 public bool OwnContent {get;set;} 118 public bool OwnContent {get;set;}
112 119
113 /// <summary>Delegate for comparing two elements of this list.</summary> 120 /// <summary>Delegate for comparing two elements of this list.</summary>
114 /// <returns>-1, 0 or 1 for respectively smaller, equal or larger.</returns> 121 /// <returns>-1, 0 or 1 for respectively smaller, equal or larger.</returns>
115 public delegate int Compare(T a, T b); 122 public delegate int Compare(T a, T b);
116 123
124 /// <summary>The number of elements on this list.</summary>
117 public int Length 125 public int Length
118 { 126 {
119 get { return Count(); } 127 get { return Count(); }
@@ -153,11 +161,14 @@ public class List<T> : IEnumerable<T>, IDisposable
153 } 161 }
154 162
155 163
164 /// <summary>Creates a new empty list.</summary>
156 public List() 165 public List()
157 { 166 {
158 InitNew(); 167 InitNew();
159 } 168 }
160 169
170 /// <summary>Creates a new list wrapping the given handle.</summary>
171 [EditorBrowsable(EditorBrowsableState.Never)]
161 public List(IntPtr handle, bool own) 172 public List(IntPtr handle, bool own)
162 { 173 {
163 Handle = handle; 174 Handle = handle;
@@ -165,6 +176,8 @@ public class List<T> : IEnumerable<T>, IDisposable
165 OwnContent = own; 176 OwnContent = own;
166 } 177 }
167 178
179 /// <summary>Creates a new list wrapping the given handle.</summary>
180 [EditorBrowsable(EditorBrowsableState.Never)]
168 public List(IntPtr handle, bool own, bool ownContent) 181 public List(IntPtr handle, bool own, bool ownContent)
169 { 182 {
170 Handle = handle; 183 Handle = handle;
@@ -172,11 +185,15 @@ public class List<T> : IEnumerable<T>, IDisposable
172 OwnContent = ownContent; 185 OwnContent = ownContent;
173 } 186 }
174 187
188 /// <summary>Finalizes this list.</summary>
175 ~List() 189 ~List()
176 { 190 {
177 Dispose(false); 191 Dispose(false);
178 } 192 }
179 193
194 /// <summary>Disposes of this list.</summary>
195 /// <param name="disposing">Whether this was called from the finalizer (<c>false</c>) or from the
196 /// <see cref="Dispose()"/> method.</param>
180 protected virtual void Dispose(bool disposing) 197 protected virtual void Dispose(bool disposing)
181 { 198 {
182 IntPtr h = Handle; 199 IntPtr h = Handle;
@@ -207,17 +224,21 @@ public class List<T> : IEnumerable<T>, IDisposable
207 } 224 }
208 } 225 }
209 226
227 /// <summary>Disposes of this list.</summary>
210 public void Dispose() 228 public void Dispose()
211 { 229 {
212 Dispose(true); 230 Dispose(true);
213 GC.SuppressFinalize(this); 231 GC.SuppressFinalize(this);
214 } 232 }
215 233
234 /// <summary>Disposes of this list.</summary>
216 public void Free() 235 public void Free()
217 { 236 {
218 Dispose(); 237 Dispose();
219 } 238 }
220 239
240 /// <summary>Relinquishes of the native list.</summary>
241 /// <returns>The previously wrapped native list handle.</returns>
221 public IntPtr Release() 242 public IntPtr Release()
222 { 243 {
223 IntPtr h = Handle; 244 IntPtr h = Handle;
@@ -225,57 +246,77 @@ public class List<T> : IEnumerable<T>, IDisposable
225 return h; 246 return h;
226 } 247 }
227 248
249 /// <summary>Sets whether this wrapper should own the native list or not.</summary>
228 public void SetOwnership(bool ownAll) 250 public void SetOwnership(bool ownAll)
229 { 251 {
230 Own = ownAll; 252 Own = ownAll;
231 OwnContent = ownAll; 253 OwnContent = ownAll;
232 } 254 }
233 255
256 /// <summary>Sets whether this wrapper should own the native list and its content or not.</summary>
234 public void SetOwnership(bool own, bool ownContent) 257 public void SetOwnership(bool own, bool ownContent)
235 { 258 {
236 Own = own; 259 Own = own;
237 OwnContent = ownContent; 260 OwnContent = ownContent;
238 } 261 }
239 262
263 /// <summary>Returns the number of elements in this list.</summary>
240 public int Count() 264 public int Count()
241 { 265 {
242 return (int)eina_list_count_custom_export_mono(Handle); 266 return (int)eina_list_count_custom_export_mono(Handle);
243 } 267 }
244 268
269 /// <summary>Appends <c>val</c> to the list.</summary>
270 /// <param name="val">The item to be appended.</param>
245 public void Append(T val) 271 public void Append(T val)
246 { 272 {
247 IntPtr ele = ManagedToNativeAlloc(val); 273 IntPtr ele = ManagedToNativeAlloc(val);
248 Handle = eina_list_append(Handle, ele); 274 Handle = eina_list_append(Handle, ele);
249 } 275 }
250 276
277 /// <summary>Prepends <c>val</c> to the list.</summary>
278 /// <param name="val">The item to be prepended.</param>
251 public void Prepend(T val) 279 public void Prepend(T val)
252 { 280 {
253 IntPtr ele = ManagedToNativeAlloc(val); 281 IntPtr ele = ManagedToNativeAlloc(val);
254 Handle = eina_list_prepend(Handle, ele); 282 Handle = eina_list_prepend(Handle, ele);
255 } 283 }
256 284
285 /// <summary>Inserts <c>val</c> in the list in a sorted manner. It presumes the list is already sorted.</summary>
286 /// <param name="val">The item to be inserted.</param>
257 public void SortedInsert(T val) 287 public void SortedInsert(T val)
258 { 288 {
259 IntPtr ele = ManagedToNativeAlloc(val); 289 IntPtr ele = ManagedToNativeAlloc(val);
260 Handle = eina_list_sorted_insert(Handle, EinaCompareCb<T>(), ele); 290 Handle = eina_list_sorted_insert(Handle, EinaCompareCb<T>(), ele);
261 } 291 }
262 292
293 /// <summary>Inserts <c>val</c> in the list in a sorted manner with the given <c>compareCb</c> for element comparison.
294 /// It presumes the list is already sorted.</summary>
295 /// <param name="compareCb">The function to compare two elements of the list.</param>
296 /// <param name="val">The item to be inserted.</param>
263 public void SortedInsert(Compare compareCb, T val) 297 public void SortedInsert(Compare compareCb, T val)
264 { 298 {
265 IntPtr ele = ManagedToNativeAlloc(val); 299 IntPtr ele = ManagedToNativeAlloc(val);
266 Handle = eina_list_sorted_insert(Handle, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)), ele); 300 Handle = eina_list_sorted_insert(Handle, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)), ele);
267 } 301 }
268 302
303 /// <summary>Sorts <c>limit</c> elements in this list inplace.</summary>
304 /// <param name="limit">The max number of elements to be sorted.</param>
269 public void Sort(int limit = 0) 305 public void Sort(int limit = 0)
270 { 306 {
271 Handle = eina_list_sort(Handle, (uint)limit, EinaCompareCb<T>()); 307 Handle = eina_list_sort(Handle, (uint)limit, EinaCompareCb<T>());
272 } 308 }
273 309
310 /// <summary>Sorts all elements in this list inplace.</summary>
311 /// <param name="compareCb">The function to compare two elements of the list.</param>
274 public void Sort(Compare compareCb) 312 public void Sort(Compare compareCb)
275 { 313 {
276 Handle = eina_list_sort(Handle, 0, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb))); 314 Handle = eina_list_sort(Handle, 0, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)));
277 } 315 }
278 316
317 /// <summary>Sorts <c>limit</c> elements in this list inplace.</summary>
318 /// <param name="limit">The max number of elements to be sorted.</param>
319 /// <param name="compareCb">The function to compare two elements of the list.</param>
279 public void Sort(int limit, Compare compareCb) 320 public void Sort(int limit, Compare compareCb)
280 { 321 {
281 Handle = eina_list_sort(Handle, (uint)limit, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb))); 322 Handle = eina_list_sort(Handle, (uint)limit, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)));
@@ -288,6 +329,9 @@ public class List<T> : IEnumerable<T>, IDisposable
288 }; 329 };
289 } 330 }
290 331
332 /// <summary>Returns the <c>n</c>th element of this list. Due to marshalling details, the returned element
333 /// may be a different C# object from the one you used to append.</summary>
334 /// <param name="n">The 0-based index to be retrieved.</param>
291 public T Nth(int n) 335 public T Nth(int n)
292 { 336 {
293 // TODO: check bounds ??? 337 // TODO: check bounds ???
@@ -295,6 +339,9 @@ public class List<T> : IEnumerable<T>, IDisposable
295 return NativeToManaged<T>(ele); 339 return NativeToManaged<T>(ele);
296 } 340 }
297 341
342 /// <summary>Sets the data at the <c>idx</c> position.</summary>
343 /// <param name="idx">The 0-based index to be set.</param>
344 /// <param name="val">The value to be inserted.</param>
298 public void DataSet(int idx, T val) 345 public void DataSet(int idx, T val)
299 { 346 {
300 IntPtr pos = eina_list_nth_list(Handle, (uint)idx); 347 IntPtr pos = eina_list_nth_list(Handle, (uint)idx);
@@ -312,6 +359,8 @@ public class List<T> : IEnumerable<T>, IDisposable
312 InternalDataSet(pos, ele); 359 InternalDataSet(pos, ele);
313 } 360 }
314 361
362 /// <summary>Accessor for the data at the <c>idx</c> position.</summary>
363 /// <param name="idx">The 0-based index to be get/set.</param>
315 public T this[int idx] 364 public T this[int idx]
316 { 365 {
317 get 366 get
@@ -324,23 +373,30 @@ public class List<T> : IEnumerable<T>, IDisposable
324 } 373 }
325 } 374 }
326 375
376 /// <summary>Returns the data at the last list element.</summary>
377 /// <returns>The value contained in the last list position.</returns>
327 public T LastDataGet() 378 public T LastDataGet()
328 { 379 {
329 IntPtr ele = eina_list_last_data_get_custom_export_mono(Handle); 380 IntPtr ele = eina_list_last_data_get_custom_export_mono(Handle);
330 return NativeToManaged<T>(ele); 381 return NativeToManaged<T>(ele);
331 } 382 }
332 383
384 /// <summary>Reverses this list in place.</summary>
385 /// <returns>A reference to this object.</returns>
333 public List<T> Reverse() 386 public List<T> Reverse()
334 { 387 {
335 Handle = eina_list_reverse(Handle); 388 Handle = eina_list_reverse(Handle);
336 return this; 389 return this;
337 } 390 }
338 391
392 /// <summary>Randomly shuffles this list in place.</summary>
339 public void Shuffle() 393 public void Shuffle()
340 { 394 {
341 Handle = eina_list_shuffle(Handle, IntPtr.Zero); 395 Handle = eina_list_shuffle(Handle, IntPtr.Zero);
342 } 396 }
343 397
398 /// <summary>Gets a C# array of the elements in this list.</summary>
399 /// <returns>A managed array of the elements.</returns>
344 public T[] ToArray() 400 public T[] ToArray()
345 { 401 {
346 var managed = new T[Count()]; 402 var managed = new T[Count()];
@@ -353,6 +409,8 @@ public class List<T> : IEnumerable<T>, IDisposable
353 return managed; 409 return managed;
354 } 410 }
355 411
412 /// <summary>Appends the given array of elements to this list.</summary>
413 /// <param name="values">The values to be appended.</param>
356 public void AppendArray(T[] values) 414 public void AppendArray(T[] values)
357 { 415 {
358 foreach (T v in values) 416 foreach (T v in values)
@@ -362,16 +420,22 @@ public class List<T> : IEnumerable<T>, IDisposable
362 } 420 }
363 421
364 422
423 /// <summary>Gets an iterator that iterates this list in normal order.</summary>
424 /// <returns>The iterator.</returns>
365 public Eina.Iterator<T> GetIterator() 425 public Eina.Iterator<T> GetIterator()
366 { 426 {
367 return new Eina.Iterator<T>(eina_list_iterator_new(Handle), true); 427 return new Eina.Iterator<T>(eina_list_iterator_new(Handle), true);
368 } 428 }
369 429
430 /// <summary>Gets an iterator that iterates this list in reverse order.</summary>
431 /// <returns>The iterator.</returns>
370 public Eina.Iterator<T> GetReversedIterator() 432 public Eina.Iterator<T> GetReversedIterator()
371 { 433 {
372 return new Eina.Iterator<T>(eina_list_iterator_reversed_new(Handle), true); 434 return new Eina.Iterator<T>(eina_list_iterator_reversed_new(Handle), true);
373 } 435 }
374 436
437 /// <summary>Gets an enumerator into this list.</summary>
438 /// <returns>The enumerator.</returns>
375 public IEnumerator<T> GetEnumerator() 439 public IEnumerator<T> GetEnumerator()
376 { 440 {
377 for (IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr)) 441 for (IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr))
@@ -380,12 +444,15 @@ public class List<T> : IEnumerable<T>, IDisposable
380 } 444 }
381 } 445 }
382 446
447 /// <summary>Gets an enumerator into this list.</summary>
448 /// <returns>The enumerator.</returns>
383 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 449 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
384 { 450 {
385 return this.GetEnumerator(); 451 return this.GetEnumerator();
386 } 452 }
387 453
388 /// <summary> Gets an Accessor for this List.</summary> 454 /// <summary> Gets an Accessor for this List.</summary>
455 /// <returns>The accessor.</returns>
389 public Eina.Accessor<T> GetAccessor() 456 public Eina.Accessor<T> GetAccessor()
390 { 457 {
391 return new Eina.Accessor<T>(eina_list_accessor_new(Handle), Ownership.Managed); 458 return new Eina.Accessor<T>(eina_list_accessor_new(Handle), Ownership.Managed);