summaryrefslogtreecommitdiff
path: root/src/bindings/mono/eina_mono/eina_list.cs
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2017-11-23 21:49:22 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2017-12-04 15:47:49 -0300
commit9391407319424c503a78479b407737ccead945b7 (patch)
treeedc4d5bab7b79667c9853d3c9d9ed2956e498394 /src/bindings/mono/eina_mono/eina_list.cs
parente6dd831f7ea57bc4717f364141be1bf197da3cc8 (diff)
efl_mono: Adding support code for the C# binding
This is the C# manual code for the binding. Buildsystem integration will come in a future commit.
Diffstat (limited to 'src/bindings/mono/eina_mono/eina_list.cs')
-rw-r--r--src/bindings/mono/eina_mono/eina_list.cs352
1 files changed, 352 insertions, 0 deletions
diff --git a/src/bindings/mono/eina_mono/eina_list.cs b/src/bindings/mono/eina_mono/eina_list.cs
new file mode 100644
index 0000000..c972c82
--- /dev/null
+++ b/src/bindings/mono/eina_mono/eina_list.cs
@@ -0,0 +1,352 @@
1using System;
2using System.Runtime.InteropServices;
3using System.Collections.Generic;
4
5using static eina.TraitFunctions;
6using static eina.ListNativeFunctions;
7using eina.Callbacks;
8
9namespace eina {
10
11public static class ListNativeFunctions
12{
13 [DllImport(efl.Libs.Eina)] public static extern IntPtr
14 eina_list_append(IntPtr list, IntPtr data);
15 [DllImport(efl.Libs.Eina)] public static extern IntPtr
16 eina_list_prepend(IntPtr list, IntPtr data);
17 [DllImport(efl.Libs.Eina)] public static extern IntPtr
18 eina_list_append_relative(IntPtr list, IntPtr data, IntPtr relative);
19 [DllImport(efl.Libs.Eina)] public static extern IntPtr
20 eina_list_append_relative_list(IntPtr list, IntPtr data, IntPtr relative);
21 [DllImport(efl.Libs.Eina)] public static extern IntPtr
22 eina_list_prepend_relative(IntPtr list, IntPtr data, IntPtr relative);
23 [DllImport(efl.Libs.Eina)] public static extern IntPtr
24 eina_list_prepend_relative_list(IntPtr list, IntPtr data, IntPtr relative);
25 [DllImport(efl.Libs.Eina)] public static extern IntPtr
26 eina_list_sorted_insert(IntPtr list, IntPtr func, IntPtr data);
27 [DllImport(efl.Libs.Eina)] public static extern IntPtr
28 eina_list_remove(IntPtr list, IntPtr data);
29 [DllImport(efl.Libs.Eina)] public static extern IntPtr
30 eina_list_remove_list(IntPtr list, IntPtr remove_list);
31 [DllImport(efl.Libs.Eina)] public static extern IntPtr
32 eina_list_promote_list(IntPtr list, IntPtr move_list);
33 [DllImport(efl.Libs.Eina)] public static extern IntPtr
34 eina_list_demote_list(IntPtr list, IntPtr move_list);
35 [DllImport(efl.Libs.Eina)] public static extern IntPtr
36 eina_list_data_find(IntPtr list, IntPtr data);
37 [DllImport(efl.Libs.Eina)] public static extern IntPtr
38 eina_list_data_find_list(IntPtr list, IntPtr data);
39 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool
40 eina_list_move(ref IntPtr to, ref IntPtr from, IntPtr data);
41 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool
42 eina_list_move_list(ref IntPtr to, ref IntPtr from, IntPtr data);
43 [DllImport(efl.Libs.Eina)] public static extern IntPtr
44 eina_list_free(IntPtr list);
45 [DllImport(efl.Libs.Eina)] public static extern IntPtr
46 eina_list_nth(IntPtr list, uint n);
47 [DllImport(efl.Libs.Eina)] public static extern IntPtr
48 eina_list_nth_list(IntPtr list, uint n);
49 [DllImport(efl.Libs.Eina)] public static extern IntPtr
50 eina_list_reverse(IntPtr list);
51 [DllImport(efl.Libs.Eina)] public static extern IntPtr
52 eina_list_reverse_clone(IntPtr list);
53 [DllImport(efl.Libs.Eina)] public static extern IntPtr
54 eina_list_clone(IntPtr list);
55 [DllImport(efl.Libs.Eina)] public static extern IntPtr
56 eina_list_sort(IntPtr list, uint limit, IntPtr func);
57 [DllImport(efl.Libs.Eina)] public static extern IntPtr
58 eina_list_shuffle(IntPtr list, IntPtr func);
59 [DllImport(efl.Libs.Eina)] public static extern IntPtr
60 eina_list_merge(IntPtr left, IntPtr right);
61 [DllImport(efl.Libs.Eina)] public static extern IntPtr
62 eina_list_sorted_merge(IntPtr left, IntPtr right, IntPtr func);
63 [DllImport(efl.Libs.Eina)] public static extern IntPtr
64 eina_list_split_list(IntPtr list, IntPtr relative, ref IntPtr right);
65 [DllImport(efl.Libs.Eina)] public static extern IntPtr
66 eina_list_search_sorted_near_list(IntPtr list, IntPtr func, IntPtr data, IntPtr result_cmp);
67 [DllImport(efl.Libs.Eina)] public static extern IntPtr
68 eina_list_search_sorted_list(IntPtr list, IntPtr func, IntPtr data);
69 [DllImport(efl.Libs.Eina)] public static extern IntPtr
70 eina_list_search_sorted(IntPtr list, IntPtr func, IntPtr data);
71 [DllImport(efl.Libs.Eina)] public static extern IntPtr
72 eina_list_search_unsorted_list(IntPtr list, IntPtr func, IntPtr data);
73 [DllImport(efl.Libs.Eina)] public static extern IntPtr
74 eina_list_search_unsorted(IntPtr list, IntPtr func, IntPtr data);
75
76 [DllImport(efl.Libs.Eina)] public static extern IntPtr
77 eina_list_iterator_new(IntPtr list);
78 [DllImport(efl.Libs.Eina)] public static extern IntPtr
79 eina_list_iterator_reversed_new(IntPtr list);
80 [DllImport(efl.Libs.Eina)] public static extern IntPtr
81 eina_list_accessor_new(IntPtr list);
82 [DllImport(efl.Libs.Eina)] public static extern int
83 eina_list_data_idx(IntPtr list, IntPtr data);
84
85
86 [DllImport(efl.Libs.CustomExports)] public static extern IntPtr
87 eina_list_last_custom_export_mono(IntPtr list);
88 [DllImport(efl.Libs.CustomExports)] public static extern IntPtr
89 eina_list_next_custom_export_mono(IntPtr list);
90 [DllImport(efl.Libs.CustomExports)] public static extern IntPtr
91 eina_list_prev_custom_export_mono(IntPtr list);
92 [DllImport(efl.Libs.CustomExports)] public static extern IntPtr
93 eina_list_data_get_custom_export_mono(IntPtr list);
94 [DllImport(efl.Libs.CustomExports)] public static extern IntPtr
95 eina_list_data_set_custom_export_mono(IntPtr list, IntPtr data);
96 [DllImport(efl.Libs.CustomExports)] public static extern uint
97 eina_list_count_custom_export_mono(IntPtr list);
98 [DllImport(efl.Libs.CustomExports)] public static extern IntPtr
99 eina_list_last_data_get_custom_export_mono(IntPtr list);
100}
101
102public class List<T> : IEnumerable<T>, IDisposable
103{
104 public IntPtr Handle {get;set;} = IntPtr.Zero;
105 public bool Own {get;set;}
106 public bool OwnContent {get;set;}
107
108 public int Length
109 {
110 get { return Count(); }
111 }
112
113
114 private void InitNew()
115 {
116 Handle = IntPtr.Zero;
117 Own = true;
118 OwnContent = true;
119 }
120
121 private IntPtr InternalLast()
122 {
123 return eina_list_last_custom_export_mono(Handle);
124 }
125
126 private static IntPtr InternalNext(IntPtr list)
127 {
128 return eina_list_next_custom_export_mono(list);
129 }
130
131 private static IntPtr InternalPrev(IntPtr list)
132 {
133 return eina_list_prev_custom_export_mono(list);
134 }
135
136 private static IntPtr InternalDataGet(IntPtr list)
137 {
138 return eina_list_data_get_custom_export_mono(list);
139 }
140
141 private static IntPtr InternalDataSet(IntPtr list, IntPtr data)
142 {
143 return eina_list_data_set_custom_export_mono(list, data);
144 }
145
146
147 public List()
148 {
149 InitNew();
150 }
151
152 public List(IntPtr handle, bool own)
153 {
154 Handle = handle;
155 Own = own;
156 OwnContent = own;
157 }
158
159 public List(IntPtr handle, bool own, bool ownContent)
160 {
161 Handle = handle;
162 Own = own;
163 OwnContent = ownContent;
164 }
165
166 ~List()
167 {
168 Dispose(false);
169 }
170
171 protected virtual void Dispose(bool disposing)
172 {
173 IntPtr h = Handle;
174 Handle = IntPtr.Zero;
175 if (h == IntPtr.Zero)
176 return;
177
178 if (OwnContent)
179 {
180 for(IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr))
181 {
182 NativeFree<T>(InternalDataGet(curr));
183 }
184 }
185
186 if (Own)
187 eina_list_free(h);
188 }
189
190 public void Dispose()
191 {
192 Dispose(true);
193 GC.SuppressFinalize(this);
194 }
195
196 public void Free()
197 {
198 Dispose();
199 }
200
201 public IntPtr Release()
202 {
203 IntPtr h = Handle;
204 Handle = IntPtr.Zero;
205 return h;
206 }
207
208 public void SetOwnership(bool ownAll)
209 {
210 Own = ownAll;
211 OwnContent = ownAll;
212 }
213
214 public void SetOwnership(bool own, bool ownContent)
215 {
216 Own = own;
217 OwnContent = ownContent;
218 }
219
220 public int Count()
221 {
222 return (int) eina_list_count_custom_export_mono(Handle);
223 }
224
225 public void Append(T val)
226 {
227 IntPtr ele = ManagedToNativeAlloc(val);
228 Handle = eina_list_append(Handle, ele);
229 }
230
231 public void Prepend(T val)
232 {
233 IntPtr ele = ManagedToNativeAlloc(val);
234 Handle = eina_list_prepend(Handle, ele);
235 }
236
237 public void SortedInsert(T val)
238 {
239 IntPtr ele = ManagedToNativeAlloc(val);
240 Handle = eina_list_sorted_insert(Handle, EinaCompareCb<T>(), ele);
241 }
242
243 public void SortedInsert(Eina_Compare_Cb compareCb, T val)
244 {
245 IntPtr ele = ManagedToNativeAlloc(val);
246 Handle = eina_list_sorted_insert(Handle, Marshal.GetFunctionPointerForDelegate(compareCb), ele);
247 }
248
249 public void Sort(int limit = 0)
250 {
251 Handle = eina_list_sort(Handle, (uint)limit, EinaCompareCb<T>());
252 }
253
254 public void Sort(Eina_Compare_Cb compareCb)
255 {
256 Handle = eina_list_sort(Handle, 0, Marshal.GetFunctionPointerForDelegate(compareCb));
257 }
258
259 public void Sort(int limit, Eina_Compare_Cb compareCb)
260 {
261 Handle = eina_list_sort(Handle, (uint)limit, Marshal.GetFunctionPointerForDelegate(compareCb));
262 }
263
264 public T Nth(int n)
265 {
266 // TODO: check bounds ???
267 IntPtr ele = eina_list_nth(Handle, (uint)n);
268 return NativeToManaged<T>(ele);
269 }
270
271 public void DataSet(int idx, T val)
272 {
273 IntPtr pos = eina_list_nth_list(Handle, (uint)idx);
274 if (pos == IntPtr.Zero)
275 throw new IndexOutOfRangeException();
276 if (OwnContent)
277 NativeFree<T>(InternalDataGet(pos));
278 IntPtr ele = ManagedToNativeAlloc(val);
279 InternalDataSet(pos, ele);
280 }
281
282 public T this[int idx]
283 {
284 get
285 {
286 return Nth(idx);
287 }
288 set
289 {
290 DataSet(idx, value);
291 }
292 }
293
294 public T LastDataGet()
295 {
296 IntPtr ele = eina_list_last_data_get_custom_export_mono(Handle);
297 return NativeToManaged<T>(ele);
298 }
299
300 public void Reverse()
301 {
302 Handle = eina_list_reverse(Handle);
303 }
304
305 public void Shuffle()
306 {
307 Handle = eina_list_shuffle(Handle, IntPtr.Zero);
308 }
309
310 public T[] ToArray()
311 {
312 var managed = new T[Count()];
313 int i = 0;
314 for(IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr), ++i)
315 {
316 managed[i] = NativeToManaged<T>(InternalDataGet(curr));
317 }
318 return managed;
319 }
320
321 public void AppendArray(T[] values)
322 {
323 foreach (T v in values)
324 Append(v);
325 }
326
327
328 public eina.Iterator<T> GetIterator()
329 {
330 return new eina.Iterator<T>(eina_list_iterator_new(Handle), true, false);
331 }
332
333 public eina.Iterator<T> GetReversedIterator()
334 {
335 return new eina.Iterator<T>(eina_list_iterator_reversed_new(Handle), true, false);
336 }
337
338 public IEnumerator<T> GetEnumerator()
339 {
340 for(IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr))
341 {
342 yield return NativeToManaged<T>(InternalDataGet(curr));
343 }
344 }
345
346 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
347 {
348 return this.GetEnumerator();
349 }
350}
351
352}