summaryrefslogtreecommitdiff
path: root/src/bindings/mono/eina_mono
diff options
context:
space:
mode:
Diffstat (limited to 'src/bindings/mono/eina_mono')
-rw-r--r--src/bindings/mono/eina_mono/eina_accessor.cs50
-rw-r--r--src/bindings/mono/eina_mono/eina_array.cs332
-rw-r--r--src/bindings/mono/eina_mono/eina_binbuf.cs19
-rw-r--r--src/bindings/mono/eina_mono/eina_common.cs21
-rw-r--r--src/bindings/mono/eina_mono/eina_config.cs15
-rw-r--r--src/bindings/mono/eina_mono/eina_container_common.cs148
-rw-r--r--src/bindings/mono/eina_mono/eina_environment.cs53
-rw-r--r--src/bindings/mono/eina_mono/eina_error.cs150
-rw-r--r--src/bindings/mono/eina_mono/eina_hash.cs70
-rw-r--r--src/bindings/mono/eina_mono/eina_inarray.cs22
-rw-r--r--src/bindings/mono/eina_mono/eina_inlist.cs22
-rw-r--r--src/bindings/mono/eina_mono/eina_iterator.cs22
-rw-r--r--src/bindings/mono/eina_mono/eina_list.cs386
-rw-r--r--src/bindings/mono/eina_mono/eina_log.cs19
-rw-r--r--src/bindings/mono/eina_mono/eina_promises.cs23
-rw-r--r--src/bindings/mono/eina_mono/eina_slice.cs116
-rw-r--r--src/bindings/mono/eina_mono/eina_strbuf.cs20
-rw-r--r--src/bindings/mono/eina_mono/eina_stringshare.cs30
-rw-r--r--src/bindings/mono/eina_mono/eina_value.cs627
-rw-r--r--src/bindings/mono/eina_mono/meson.build3
20 files changed, 1647 insertions, 501 deletions
diff --git a/src/bindings/mono/eina_mono/eina_accessor.cs b/src/bindings/mono/eina_mono/eina_accessor.cs
index c848a2c..77c9817 100644
--- a/src/bindings/mono/eina_mono/eina_accessor.cs
+++ b/src/bindings/mono/eina_mono/eina_accessor.cs
@@ -1,8 +1,24 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1using System; 16using System;
2using System.Collections; 17using System.Collections;
3using System.Collections.Generic; 18using System.Collections.Generic;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.ComponentModel; 20using System.ComponentModel;
21using System.Diagnostics.CodeAnalysis;
6 22
7using static Eina.TraitFunctions; 23using static Eina.TraitFunctions;
8 24
@@ -13,16 +29,26 @@ namespace Eina
13 29
14internal class AccessorNativeFunctions 30internal class AccessorNativeFunctions
15{ 31{
32 [DllImport(efl.Libs.Eina)] public static extern IntPtr
33 eina_carray_length_accessor_new(IntPtr array, uint step, uint length);
16 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool 34 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool
17 eina_accessor_data_get(IntPtr accessor, uint position, IntPtr data); 35 eina_accessor_data_get(IntPtr accessor, uint position, out IntPtr data);
18 [DllImport(efl.Libs.Eina)] public static extern void 36 [DllImport(efl.Libs.Eina)] public static extern void
19 eina_accessor_free(IntPtr accessor); 37 eina_accessor_free(IntPtr accessor);
38 [DllImport(efl.Libs.CustomExports)] public static extern IntPtr
39 eina_mono_owned_carray_length_accessor_new(IntPtr array,
40 uint step,
41 uint length,
42 Eina.Callbacks.EinaFreeCb freeCb,
43 IntPtr handle);
20} 44}
21 45
22/// <summary>Accessors provide an uniform way of accessing Eina containers, 46/// <summary>Accessors provide an uniform way of accessing Eina containers,
23/// similar to C++ STL's and C# IEnumerable. 47/// similar to C++ STL's and C# IEnumerable.
24/// <para>Since EFL 1.23.</para> 48/// <para>Since EFL 1.23.</para>
25/// </summary> 49/// </summary>
50[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
51 Justification="This is a generalized container mapping the native one.")]
26public class Accessor<T> : IEnumerable<T>, IDisposable 52public class Accessor<T> : IEnumerable<T>, IDisposable
27{ 53{
28 /// <summary>Pointer to the native accessor.</summary> 54 /// <summary>Pointer to the native accessor.</summary>
@@ -80,6 +106,7 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
80 public void Dispose() 106 public void Dispose()
81 { 107 {
82 Dispose(true); 108 Dispose(true);
109 GC.SuppressFinalize(this);
83 } 110 }
84 111
85 /// <summary>Disposes of this wrapper, releasing the native accessor if 112 /// <summary>Disposes of this wrapper, releasing the native accessor if
@@ -134,21 +161,12 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
134 throw new ObjectDisposedException(base.GetType().Name); 161 throw new ObjectDisposedException(base.GetType().Name);
135 } 162 }
136 163
137 IntPtr tmp = MemoryNative.Alloc(Marshal.SizeOf(typeof(IntPtr))); 164 IntPtr tmp;
138 uint position = 0; 165 uint position = 0;
139 166 while (eina_accessor_data_get(Handle, position, out tmp))
140 try
141 {
142 while (eina_accessor_data_get(Handle, position, tmp))
143 {
144 IntPtr data = (IntPtr)Marshal.PtrToStructure(tmp, typeof(IntPtr));
145 yield return Convert(data);
146 position += 1;
147 }
148 }
149 finally
150 { 167 {
151 MemoryNative.Free(tmp); 168 yield return Convert(tmp); // No need to free as it is still owned by the container.
169 position += 1;
152 } 170 }
153 } 171 }
154 172
@@ -161,6 +179,8 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
161/// <summary>Accessor for Inlists. 179/// <summary>Accessor for Inlists.
162/// <para>Since EFL 1.23.</para> 180/// <para>Since EFL 1.23.</para>
163/// </summary> 181/// </summary>
182[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
183 Justification="This is a generalized container mapping the native one.")]
164public class AccessorInList<T> : Accessor<T> 184public class AccessorInList<T> : Accessor<T>
165{ 185{
166 /// <summary>Create a new accessor wrapping the given pointer. 186 /// <summary>Create a new accessor wrapping the given pointer.
@@ -186,6 +206,8 @@ public class AccessorInList<T> : Accessor<T>
186/// <summary>Accessor for Inarrays. 206/// <summary>Accessor for Inarrays.
187/// <para>Since EFL 1.23.</para> 207/// <para>Since EFL 1.23.</para>
188/// </summary> 208/// </summary>
209[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
210 Justification="This is a generalized container mapping the native one.")]
189public class AccessorInArray<T> : Accessor<T> 211public class AccessorInArray<T> : Accessor<T>
190{ 212{
191 /// <summary>Create a new accessor wrapping the given pointer. 213 /// <summary>Create a new accessor wrapping the given pointer.
diff --git a/src/bindings/mono/eina_mono/eina_array.cs b/src/bindings/mono/eina_mono/eina_array.cs
index 78388a5..ba3809b 100644
--- a/src/bindings/mono/eina_mono/eina_array.cs
+++ b/src/bindings/mono/eina_mono/eina_array.cs
@@ -1,9 +1,26 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.Collections.Generic; 20using System.Collections.Generic;
6using System.ComponentModel; 21using System.ComponentModel;
22using System.Diagnostics.CodeAnalysis;
23using System.Diagnostics.Contracts;
7 24
8using static Eina.TraitFunctions; 25using static Eina.TraitFunctions;
9using static Eina.ArrayNativeFunctions; 26using static Eina.ArrayNativeFunctions;
@@ -12,7 +29,7 @@ namespace Eina
12{ 29{
13 30
14[EditorBrowsable(EditorBrowsableState.Never)] 31[EditorBrowsable(EditorBrowsableState.Never)]
15public static class ArrayNativeFunctions 32internal static class ArrayNativeFunctions
16{ 33{
17 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 34 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
18 eina_array_new(uint step); 35 eina_array_new(uint step);
@@ -20,8 +37,9 @@ public static class ArrayNativeFunctions
20 eina_array_free(IntPtr array); 37 eina_array_free(IntPtr array);
21 [DllImport(efl.Libs.Eina)] internal static extern void 38 [DllImport(efl.Libs.Eina)] internal static extern void
22 eina_array_flush(IntPtr array); 39 eina_array_flush(IntPtr array);
40 public delegate bool KeepCb(IntPtr data, IntPtr gdata);
23 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool 41 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool
24 eina_array_remove(IntPtr array, IntPtr keep, IntPtr gdata); 42 eina_array_remove(IntPtr array, KeepCb keep, IntPtr gdata);
25 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool 43 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool
26 eina_array_push(IntPtr array, IntPtr data); 44 eina_array_push(IntPtr array, IntPtr data);
27 45
@@ -29,6 +47,10 @@ public static class ArrayNativeFunctions
29 eina_array_iterator_new(IntPtr array); 47 eina_array_iterator_new(IntPtr array);
30 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 48 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
31 eina_array_accessor_new(IntPtr array); 49 eina_array_accessor_new(IntPtr array);
50 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)]
51 internal static extern bool
52 eina_array_find(IntPtr array, IntPtr data,
53 uint out_idx);
32 54
33 [DllImport(efl.Libs.CustomExports)] internal static extern void 55 [DllImport(efl.Libs.CustomExports)] internal static extern void
34 eina_array_clean_custom_export_mono(IntPtr array); 56 eina_array_clean_custom_export_mono(IntPtr array);
@@ -45,35 +67,51 @@ public static class ArrayNativeFunctions
45 67
46 [DllImport(efl.Libs.CustomExports)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool 68 [DllImport(efl.Libs.CustomExports)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool
47 eina_array_foreach_custom_export_mono(IntPtr array, IntPtr cb, IntPtr fdata); 69 eina_array_foreach_custom_export_mono(IntPtr array, IntPtr cb, IntPtr fdata);
70 [DllImport(efl.Libs.CustomExports)] internal static extern void
71 eina_array_insert_at_custom_export_mono(IntPtr array, uint index, IntPtr data);
48} 72}
49 73
50/// <summary>A container of contiguous allocated elements. 74/// <summary>A container of contiguous allocated elements.
51/// <para>Since EFL 1.23.</para> 75/// <para>Since EFL 1.23.</para>
52/// </summary> 76/// </summary>
53public class Array<T> : IEnumerable<T>, IDisposable 77[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
78 Justification="This is a generalized container mapping the native one.")]
79public class Array<T> : IList<T>, IEnumerable<T>, IDisposable
54{ 80{
55 public const uint DefaultStep = 32; 81 public const uint DefaultStep = 32;
56 82
57 /// <summary>Pointer to the native buffer.</summary> 83 /// <summary>Pointer to the native buffer.</summary>
58 [EditorBrowsable(EditorBrowsableState.Never)] 84 [EditorBrowsable(EditorBrowsableState.Never)]
59 public IntPtr Handle {get;set;} = IntPtr.Zero; 85 public IntPtr Handle { get; set; } = IntPtr.Zero;
86
60 /// <summary>Whether this wrapper owns the native buffer. 87 /// <summary>Whether this wrapper owns the native buffer.
61 /// <para>Since EFL 1.23.</para> 88 /// <para>Since EFL 1.23.</para>
62 /// </summary> 89 /// </summary>
63 public bool Own {get;set;} 90 internal bool Own { get; set; }
91
64 /// <summary>Who is in charge of releasing the resources wrapped by 92 /// <summary>Who is in charge of releasing the resources wrapped by
65 /// this instance. 93 /// this instance.
66 /// <para>Since EFL 1.23.</para> 94 /// <para>Since EFL 1.23.</para>
67 /// </summary> 95 /// </summary>
68 public bool OwnContent {get;set;} 96 internal bool OwnContent { get; set; }
69 /// <summary> Length of the array. 97
70 /// <para>Since EFL 1.23.</para> 98 /// <summary> Gets the number of elements contained in the <see cref="Array{T}" />.
99 /// <para>Since EFL 1.24.</para>
71 /// </summary> 100 /// </summary>
72 public int Length 101 public int Count
73 { 102 {
74 get { return Count(); } 103 get => (int)eina_array_count_custom_export_mono(Handle);
75 } 104 }
76 105
106 /// <summary>
107 /// Gets a value indicating whether the <see cref="Array" /> is read-only.
108 /// <para>Since EFL 1.24.</para>
109 ///<para>
110 /// It's the negative of <see cref="OwnContent" />.
111 ///</para>
112 /// </summary>
113 public bool IsReadOnly { get => !OwnContent; }
114
77 private void InitNew(uint step) 115 private void InitNew(uint step)
78 { 116 {
79 Handle = eina_array_new(step); 117 Handle = eina_array_new(step);
@@ -86,23 +124,62 @@ public class Array<T> : IEnumerable<T>, IDisposable
86 } 124 }
87 125
88 internal bool InternalPush(IntPtr ele) 126 internal bool InternalPush(IntPtr ele)
127 => eina_array_push_custom_export_mono(Handle, ele);
128
129 internal IntPtr InternalPop()
130 => eina_array_pop_custom_export_mono(Handle);
131
132 internal IntPtr InternalDataGet(int idx)
133 => eina_array_data_get_custom_export_mono(Handle, CheckBounds(idx));
134
135 internal void InternalDataSet(int idx, IntPtr ele)
136 => eina_array_data_set_custom_export_mono(Handle, CheckBounds(idx), ele);
137
138 private uint CheckBounds(int idx)
89 { 139 {
90 return eina_array_push_custom_export_mono(Handle, ele); 140 if (!(0 <= idx && idx < Count))
141 {
142 throw new ArgumentOutOfRangeException(nameof(idx), $"{nameof(idx)} is out of bounds.");
143 }
144
145 return (uint)idx;
91 } 146 }
92 147
93 internal IntPtr InternalPop() 148 private U LoopingThrough<U>(T val, Func<int, U> f1, Func<U> f2)
94 { 149 {
95 return eina_array_pop_custom_export_mono(Handle); 150 for (int i = 0, count = Count; i < count; ++i)
151 {
152 if (NativeToManaged<T>(InternalDataGet(i)).Equals(val))
153 {
154 return f1(i);
155 }
156 }
157
158 return f2();
96 } 159 }
97 160
98 internal IntPtr InternalDataGet(int idx) 161 private void CheckOwnerships()
99 { 162 {
100 return eina_array_data_get_custom_export_mono(Handle, (uint)idx); // TODO: Check bounds ??? 163 if ((Own == false) && (OwnContent == true))
164 {
165 throw new InvalidOperationException(nameof(Own) + "/" + nameof(OwnContent));
166 }
101 } 167 }
102 168
103 internal void InternalDataSet(int idx, IntPtr ele) 169 private void RequireWritable()
170 {
171 if (IsReadOnly)
172 {
173 throw new NotSupportedException("This object's instance is read only.");
174 }
175 }
176
177 private void DeleteData(IntPtr ele)
104 { 178 {
105 eina_array_data_set_custom_export_mono(Handle, (uint)idx, ele); // TODO: Check bounds ??? 179 if (OwnContent)
180 {
181 NativeFree<T>(ele);
182 }
106 } 183 }
107 184
108 /// <summary> 185 /// <summary>
@@ -132,14 +209,13 @@ public class Array<T> : IEnumerable<T>, IDisposable
132 [EditorBrowsable(EditorBrowsableState.Never)] 209 [EditorBrowsable(EditorBrowsableState.Never)]
133 public Array(IntPtr handle, bool own) 210 public Array(IntPtr handle, bool own)
134 { 211 {
135 if (handle == IntPtr.Zero) 212 Handle = (handle != IntPtr.Zero)
136 { 213 ? handle
137 throw new ArgumentNullException("Handle can't be null"); 214 : throw new ArgumentNullException(nameof(handle),
138 } 215 $"{nameof(Handle)} can't be null");
139
140 Handle = handle;
141 Own = own; 216 Own = own;
142 OwnContent = own; 217 OwnContent = own;
218 CheckOwnerships();
143 } 219 }
144 220
145 /// <summary> 221 /// <summary>
@@ -151,14 +227,13 @@ public class Array<T> : IEnumerable<T>, IDisposable
151 [EditorBrowsable(EditorBrowsableState.Never)] 227 [EditorBrowsable(EditorBrowsableState.Never)]
152 public Array(IntPtr handle, bool own, bool ownContent) 228 public Array(IntPtr handle, bool own, bool ownContent)
153 { 229 {
154 if (handle == IntPtr.Zero) 230 Handle = (handle != IntPtr.Zero)
155 { 231 ? handle
156 throw new ArgumentNullException("Handle can't be null"); 232 : throw new ArgumentNullException(nameof(handle),
157 } 233 $"{nameof(Handle)} can't be null");
158
159 Handle = handle;
160 Own = own; 234 Own = own;
161 OwnContent = ownContent; 235 OwnContent = ownContent;
236 CheckOwnerships();
162 } 237 }
163 238
164 /// <summary> 239 /// <summary>
@@ -183,15 +258,17 @@ public class Array<T> : IEnumerable<T>, IDisposable
183 return; 258 return;
184 } 259 }
185 260
186 if (Own && OwnContent) 261 for (int len = (int)eina_array_count_custom_export_mono(h),
262 i = 0; i < len; ++i)
187 { 263 {
188 int len = (int)eina_array_count_custom_export_mono(h); 264 if (!OwnContent)
189 for (int i = 0; i < len; ++i)
190 { 265 {
191 NativeFree<T>(eina_array_data_get_custom_export_mono(h, (uint)i)); 266 break;
192 } 267 }
193 }
194 268
269 DeleteData(eina_array_data_get_custom_export_mono(h, (uint)i));
270 }
271
195 if (Own) 272 if (Own)
196 { 273 {
197 if (disposing) 274 if (disposing)
@@ -222,27 +299,16 @@ public class Array<T> : IEnumerable<T>, IDisposable
222 Dispose(); 299 Dispose();
223 } 300 }
224 301
225 /// <summary>
226 /// Releases the native array.
227 /// <para>Since EFL 1.23.</para>
228 /// </summary>
229 /// <returns>The native array.</returns>
230 public IntPtr Release()
231 {
232 IntPtr h = Handle;
233 Handle = IntPtr.Zero;
234 return h;
235 }
236
237 private void FreeElementsIfOwned() 302 private void FreeElementsIfOwned()
238 { 303 {
239 if (OwnContent) 304 if (IsReadOnly)
240 { 305 {
241 int len = Length; 306 throw new NotSupportedException("This object's instance is read only.");
242 for (int i = 0; i < len; ++i) 307 }
243 { 308
244 NativeFree<T>(InternalDataGet(i)); 309 for (int i = 0, count = Count; i < count; ++i)
245 } 310 {
311 DeleteData(InternalDataGet(i));
246 } 312 }
247 } 313 }
248 314
@@ -265,26 +331,18 @@ public class Array<T> : IEnumerable<T>, IDisposable
265 eina_array_flush(Handle); 331 eina_array_flush(Handle);
266 } 332 }
267 333
268 /// <summary> 334 internal void SetOwnership(bool ownAll)
269 /// Returns the number of elements in an array.
270 /// <para>Since EFL 1.23.</para>
271 /// </summary>
272 /// <returns>The number of elements.</returns>
273 public int Count()
274 {
275 return (int)eina_array_count_custom_export_mono(Handle);
276 }
277
278 public void SetOwnership(bool ownAll)
279 { 335 {
280 Own = ownAll; 336 Own = ownAll;
281 OwnContent = ownAll; 337 OwnContent = ownAll;
338 CheckOwnerships();
282 } 339 }
283 340
284 public void SetOwnership(bool own, bool ownContent) 341 internal void SetOwnership(bool own, bool ownContent)
285 { 342 {
286 Own = own; 343 Own = own;
287 OwnContent = ownContent; 344 OwnContent = ownContent;
345 CheckOwnerships();
288 } 346 }
289 347
290 /// <summary> 348 /// <summary>
@@ -294,6 +352,8 @@ public class Array<T> : IEnumerable<T>, IDisposable
294 /// <param name="val">The value of the element to be inserted.</param> 352 /// <param name="val">The value of the element to be inserted.</param>
295 public bool Push(T val) 353 public bool Push(T val)
296 { 354 {
355 RequireWritable();
356
297 IntPtr ele = ManagedToNativeAlloc(val); 357 IntPtr ele = ManagedToNativeAlloc(val);
298 var r = InternalPush(ele); 358 var r = InternalPush(ele);
299 if (!r) 359 if (!r)
@@ -320,11 +380,13 @@ public class Array<T> : IEnumerable<T>, IDisposable
320 /// <returns>The element at the end position.</returns> 380 /// <returns>The element at the end position.</returns>
321 public T Pop() 381 public T Pop()
322 { 382 {
383 RequireWritable();
384
323 IntPtr ele = InternalPop(); 385 IntPtr ele = InternalPop();
324 var r = NativeToManaged<T>(ele); 386 var r = NativeToManaged<T>(ele);
325 if (OwnContent && ele != IntPtr.Zero) 387 if (ele != IntPtr.Zero)
326 { 388 {
327 NativeFree<T>(ele); 389 DeleteData(ele);
328 } 390 }
329 391
330 return r; 392 return r;
@@ -337,10 +399,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
337 /// <param name="idx">The position of the desired element.</param> 399 /// <param name="idx">The position of the desired element.</param>
338 /// <returns>The element at the specified position</returns> 400 /// <returns>The element at the specified position</returns>
339 public T DataGet(int idx) 401 public T DataGet(int idx)
340 { 402 => NativeToManaged<T>(InternalDataGet(idx));
341 IntPtr ele = InternalDataGet(idx);
342 return NativeToManaged<T>(ele);
343 }
344 403
345 /// <summary> 404 /// <summary>
346 /// Returns the element of the array at the specified position. 405 /// Returns the element of the array at the specified position.
@@ -349,9 +408,8 @@ public class Array<T> : IEnumerable<T>, IDisposable
349 /// <param name="idx">The position of the desired element.</param> 408 /// <param name="idx">The position of the desired element.</param>
350 /// <returns>The element at the specified position</returns> 409 /// <returns>The element at the specified position</returns>
351 public T At(int idx) 410 public T At(int idx)
352 { 411 => DataGet(idx);
353 return DataGet(idx); 412
354 }
355 413
356 /// <summary> 414 /// <summary>
357 /// Replaces the element at the specified position. 415 /// Replaces the element at the specified position.
@@ -359,16 +417,17 @@ public class Array<T> : IEnumerable<T>, IDisposable
359 /// </summary> 417 /// </summary>
360 /// <param name="idx">The position of the desired element.</param> 418 /// <param name="idx">The position of the desired element.</param>
361 /// <param name="val">The value of the element to be inserted.</param> 419 /// <param name="val">The value of the element to be inserted.</param>
362 public void DataSet(int idx, T val) 420 internal void DataSet(int idx, T val)
363 { 421 {
364 IntPtr ele = InternalDataGet(idx); // TODO: check bondaries ?? 422 RequireWritable();
365 if (OwnContent && ele != IntPtr.Zero) 423
424 IntPtr ele = InternalDataGet(idx);
425 if (ele != IntPtr.Zero)
366 { 426 {
367 NativeFree<T>(ele); 427 DeleteData(ele);
368 } 428 }
369 429
370 ele = ManagedToNativeAlloc(val); 430 InternalDataSet(idx, ManagedToNativeAlloc(val));
371 InternalDataSet(idx, ele);
372 } 431 }
373 432
374 /// <summary> 433 /// <summary>
@@ -394,7 +453,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
394 /// <returns>A array</returns> 453 /// <returns>A array</returns>
395 public T[] ToArray() 454 public T[] ToArray()
396 { 455 {
397 int len = Length; 456 int len = Count;
398 var managed = new T[len]; 457 var managed = new T[len];
399 for (int i = 0; i < len; ++i) 458 for (int i = 0; i < len; ++i)
400 { 459 {
@@ -410,6 +469,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
410 /// </summary> 469 /// </summary>
411 public bool Append(T[] values) 470 public bool Append(T[] values)
412 { 471 {
472 Contract.Requires(values != null, nameof(values));
413 foreach (T v in values) 473 foreach (T v in values)
414 { 474 {
415 if (!Push(v)) 475 if (!Push(v))
@@ -426,17 +486,14 @@ public class Array<T> : IEnumerable<T>, IDisposable
426 /// <para>Since EFL 1.23.</para> 486 /// <para>Since EFL 1.23.</para>
427 /// </summary> 487 /// </summary>
428 public Eina.Iterator<T> GetIterator() 488 public Eina.Iterator<T> GetIterator()
429 { 489 => new Eina.Iterator<T>(eina_array_iterator_new(Handle), true);
430 return new Eina.Iterator<T>(eina_array_iterator_new(Handle), true);
431 }
432 490
433 /// <summary> Gets an Enumerator for this Array. 491 /// <summary> Gets an Enumerator for this Array.
434 /// <para>Since EFL 1.23.</para> 492 /// <para>Since EFL 1.23.</para>
435 /// </summary> 493 /// </summary>
436 public IEnumerator<T> GetEnumerator() 494 public IEnumerator<T> GetEnumerator()
437 { 495 {
438 int len = Length; 496 for (int i = 0, count = Count; i < count; ++i)
439 for (int i = 0; i < len; ++i)
440 { 497 {
441 yield return DataGet(i); 498 yield return DataGet(i);
442 } 499 }
@@ -446,16 +503,113 @@ public class Array<T> : IEnumerable<T>, IDisposable
446 /// <para>Since EFL 1.23.</para> 503 /// <para>Since EFL 1.23.</para>
447 /// </summary> 504 /// </summary>
448 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 505 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
449 { 506 => this.GetEnumerator();
450 return this.GetEnumerator();
451 }
452 507
453 /// <summary> Gets an Accessor for this Array. 508 /// <summary> Gets an Accessor for this Array.
454 /// <para>Since EFL 1.23.</para> 509 /// <para>Since EFL 1.23.</para>
455 /// </summary> 510 /// </summary>
456 public Eina.Accessor<T> GetAccessor() 511 public Eina.Accessor<T> GetAccessor()
512 => new Eina.Accessor<T>(eina_array_accessor_new(Handle), Ownership.Managed);
513
514 /// <summary>
515 /// Removes the first occurrence of a specific object.
516 /// <para>Since EFL 1.24.</para>
517 /// </summary>
518 /// <param name="val">The object to remove.</param>
519 public bool Remove(T val)
520 => LoopingThrough(val,
521 (i) =>
522 {
523 RemoveAt(i);
524 return true;
525 }, () => false);
526
527 /// <summary>
528 /// Adds an item.
529 /// <para>Since EFL 1.24.</para>
530 /// </summary>
531 /// <param name="val">The object to add.</param>
532 public void Add(T val) => Push(val);
533
534 /// <summary>
535 /// Removes all items.
536 /// <para>Since EFL 1.24.</para>
537 /// </summary>
538 public void Clear() => Clean();
539
540 /// <summary>
541 /// Determines whether the <see cref="Array{T}" /> contains a specific value.
542 /// <para>Since EFL 1.24.</para>
543 /// </summary>
544 /// <param name="val">The object to locate.</param>
545 public bool Contains(T val)
546 => LoopingThrough(val, (i) => true, () => false);
547
548 /// <summary>
549 /// Copies the elements of the <see cref="Array{T}" /> to an
550 /// <see cref="Array" />, starting at a particular <see cref="Array" /> index.
551 /// <para>Since EFL 1.24.</para>
552 /// </summary>
553 /// <param name="array">The one-dimensional <see cref="Array" /> that is the
554 /// destination of the elements copied from <see cref="Array{T}" />.
555 /// The <see cref="Array" /> must have zero-based indexing.</param>
556 /// <param name="arrayIndex">The zero-based index in array at which copying
557 /// begins.</param>
558 public void CopyTo(T[] array, int arrayIndex)
559 => ToArray().CopyTo(array, arrayIndex);
560
561 /// <summary>
562 /// Determines the index of a specific item.
563 /// <para>Since EFL 1.24.</para>
564 /// </summary>
565 /// <param name="val">The object to locate.</param>
566 public int IndexOf(T val)
567 => LoopingThrough(val, (i) => i, () => -1);
568
569 /// <summary>
570 /// Inserts an item to the <see cref="Array{T}" /> at the specified index.
571 /// <para>Since EFL 1.24.</para>
572 /// </summary>
573 /// <param name="index">The zero-based index at which item should be inserted.</param>
574 /// <param name="val">The object to insert.</param>
575 public void Insert(int index, T val)
576 {
577 RequireWritable();
578
579 if (index < 0)
580 {
581 throw new ArgumentOutOfRangeException(nameof(index), $"{nameof(index)} cannot be negative.");
582 }
583
584 if (Count < index)
585 {
586 throw new ArgumentOutOfRangeException(nameof(index), $"{nameof(index)} is greater than {nameof(Count)} + 1.");
587 }
588
589 if (index == Count)
590 {
591 Push(val);
592 return;
593 }
594
595 eina_array_insert_at_custom_export_mono(Handle, (uint)index,
596 ManagedToNativeAlloc(val));
597 }
598
599 /// <summary>
600 /// Removes the <see cref="Array{T}" /> item at the specified index.
601 /// <para>Since EFL 1.24.</para>
602 /// </summary>
603 /// <param name="index">The zero-based index of the item to remove.</param>
604 public void RemoveAt(int index)
457 { 605 {
458 return new Eina.Accessor<T>(eina_array_accessor_new(Handle), Ownership.Managed); 606 RequireWritable();
607
608 var ele = InternalDataGet(index);
609 DeleteData(ele);
610 eina_array_remove(Handle, (data,gdata)
611 => ele != data,
612 IntPtr.Zero);
459 } 613 }
460} 614}
461 615
diff --git a/src/bindings/mono/eina_mono/eina_binbuf.cs b/src/bindings/mono/eina_mono/eina_binbuf.cs
index 0e9824c..6cc79f9 100644
--- a/src/bindings/mono/eina_mono/eina_binbuf.cs
+++ b/src/bindings/mono/eina_mono/eina_binbuf.cs
@@ -1,8 +1,24 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.ComponentModel; 20using System.ComponentModel;
21using System.Diagnostics.Contracts;
6 22
7namespace Eina 23namespace Eina
8{ 24{
@@ -199,6 +215,7 @@ public class Binbuf : IDisposable
199 /// <returns>true on success, false if data could not be appended.</returns> 215 /// <returns>true on success, false if data could not be appended.</returns>
200 public bool Append(byte[] str) 216 public bool Append(byte[] str)
201 { 217 {
218 Contract.Requires(str != null, nameof(str));
202 return 0 != eina_binbuf_append_length(Handle, str, (UIntPtr)(str.Length)); 219 return 0 != eina_binbuf_append_length(Handle, str, (UIntPtr)(str.Length));
203 } 220 }
204 221
@@ -223,6 +240,7 @@ public class Binbuf : IDisposable
223 /// <returns>true on success, false if data could not be appended.</returns> 240 /// <returns>true on success, false if data could not be appended.</returns>
224 public bool Append(Binbuf bb) 241 public bool Append(Binbuf bb)
225 { 242 {
243 Contract.Requires(bb != null, nameof(bb));
226 return 0 != eina_binbuf_append_buffer(Handle, bb.Handle); 244 return 0 != eina_binbuf_append_buffer(Handle, bb.Handle);
227 } 245 }
228 246
@@ -258,6 +276,7 @@ public class Binbuf : IDisposable
258 /// <returns>true on success, false if data could not be appended.</returns> 276 /// <returns>true on success, false if data could not be appended.</returns>
259 public bool Insert(byte[] str, uint pos) 277 public bool Insert(byte[] str, uint pos)
260 { 278 {
279 Contract.Requires(str != null, nameof(str));
261 return 0 != eina_binbuf_insert_length(Handle, str, (UIntPtr)(str.Length), (UIntPtr)pos); 280 return 0 != eina_binbuf_insert_length(Handle, str, (UIntPtr)(str.Length), (UIntPtr)pos);
262 } 281 }
263 282
diff --git a/src/bindings/mono/eina_mono/eina_common.cs b/src/bindings/mono/eina_mono/eina_common.cs
index badd62e..a4f2ff4 100644
--- a/src/bindings/mono/eina_mono/eina_common.cs
+++ b/src/bindings/mono/eina_mono/eina_common.cs
@@ -1,3 +1,18 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
@@ -16,7 +31,7 @@ internal delegate void EinaFreeCb(IntPtr data);
16 31
17} 32}
18 33
19internal static class NativeCustomExportFunctions 34internal static partial class NativeCustomExportFunctions
20{ 35{
21 [DllImport(efl.Libs.CustomExports)] public static extern void 36 [DllImport(efl.Libs.CustomExports)] public static extern void
22 efl_mono_native_free(IntPtr ptr); 37 efl_mono_native_free(IntPtr ptr);
@@ -190,10 +205,10 @@ public static class StringConversion
190 Marshal.WriteByte(native + strbuf.Length, 0); // write the terminating null 205 Marshal.WriteByte(native + strbuf.Length, 0); // write the terminating null
191 return native; 206 return native;
192 } 207 }
193 catch(Exception e) 208 catch (Exception)
194 { 209 {
195 MemoryNative.Free(native); 210 MemoryNative.Free(native);
196 throw e; 211 throw;
197 } 212 }
198 } 213 }
199 214
diff --git a/src/bindings/mono/eina_mono/eina_config.cs b/src/bindings/mono/eina_mono/eina_config.cs
index e9efea3..d1f536e 100644
--- a/src/bindings/mono/eina_mono/eina_config.cs
+++ b/src/bindings/mono/eina_mono/eina_config.cs
@@ -1,3 +1,18 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
diff --git a/src/bindings/mono/eina_mono/eina_container_common.cs b/src/bindings/mono/eina_mono/eina_container_common.cs
index 03a6875..192469a 100644
--- a/src/bindings/mono/eina_mono/eina_container_common.cs
+++ b/src/bindings/mono/eina_mono/eina_container_common.cs
@@ -1,3 +1,18 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
@@ -6,6 +21,7 @@ using System.Runtime.InteropServices;
6using System.Collections.Generic; 21using System.Collections.Generic;
7using System.Reflection; 22using System.Reflection;
8using System.ComponentModel; 23using System.ComponentModel;
24using System.Globalization;
9 25
10using Eina.Callbacks; 26using Eina.Callbacks;
11using static Eina.HashNativeFunctions; 27using static Eina.HashNativeFunctions;
@@ -17,7 +33,7 @@ namespace Eina
17{ 33{
18 34
19[EditorBrowsable(EditorBrowsableState.Never)] 35[EditorBrowsable(EditorBrowsableState.Never)]
20public enum ElementType 36internal enum ElementType
21{ 37{
22 NumericType, 38 NumericType,
23 StringType, 39 StringType,
@@ -27,23 +43,115 @@ public enum ElementType
27 43
28[EditorBrowsable(EditorBrowsableState.Never)] 44[EditorBrowsable(EditorBrowsableState.Never)]
29[StructLayout(LayoutKind.Sequential)] 45[StructLayout(LayoutKind.Sequential)]
30public struct InlistMem 46internal struct InlistMem : IEquatable<InlistMem>
31{ 47{
32 public IntPtr next {get;set;} 48 public IntPtr next {get;set;}
33 public IntPtr prev {get;set;} 49 public IntPtr prev {get;set;}
34 public IntPtr last {get;set;} 50 public IntPtr last {get;set;}
51
52 /// <summary>
53 /// Gets a hash for <see cref="InlistMem" />.
54 /// <para>Since EFL 1.24.</para>
55 /// </summary>
56 /// <returns>A hash code.</returns>
57 public override int GetHashCode()
58 => next.GetHashCode() ^ prev.GetHashCode() ^ last.GetHashCode();
59
60 /// <summary>Returns whether this <see cref="InlistMem" />
61 /// is equal to the given <see cref="object" />.
62 /// <para>Since EFL 1.24.</para>
63 /// </summary>
64 /// <param name="other">The <see cref="object" /> to be compared to.</param>
65 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
66 public override bool Equals(object other)
67 => (!(other is InlistMem)) ? false : Equals((InlistMem)other);
68
69 /// <summary>Returns whether this <see cref="InlistMem" /> is equal
70 /// to the given <see cref="InlistMem" />.
71 /// <para>Since EFL 1.24.</para>
72 /// </summary>
73 /// <param name="other">The <see cref="InlistMem" /> to be compared to.</param>
74 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
75 public bool Equals(InlistMem other)
76 => (next == other.next) && (prev == other.prev)
77 && (last == other.last);
78
79 /// <summary>Returns whether <c>lhs</c> is equal to <c>rhs</c>.
80 /// <para>Since EFL 1.24.</para>
81 /// </summary>
82 /// <param name="lhs">The left hand side of the operator.</param>
83 /// <param name="rhs">The right hand side of the operator.</param>
84 /// <returns><c>true</c> if <c>lhs</c> is equal
85 /// to <c>rhs</c>.</returns>
86 public static bool operator==(InlistMem lhs, InlistMem rhs)
87 => lhs.Equals(rhs);
88
89 /// <summary>Returns whether <c>lhs</c> is not equal to <c>rhs</c>.
90 /// <para>Since EFL 1.24.</para>
91 /// </summary>
92 /// <param name="lhs">The left hand side of the operator.</param>
93 /// <param name="rhs">The right hand side of the operator.</param>
94 /// <returns><c>true</c> if <c>lhs</c> is not equal
95 /// to <c>rhs</c>.</returns>
96 public static bool operator!=(InlistMem lhs, InlistMem rhs) => !(lhs == rhs);
35} 97}
36 98
37[EditorBrowsable(EditorBrowsableState.Never)] 99[EditorBrowsable(EditorBrowsableState.Never)]
38[StructLayout(LayoutKind.Sequential)] 100[StructLayout(LayoutKind.Sequential)]
39public struct InlistNode<T> 101internal struct InlistNode<T> : IEquatable<InlistNode<T>>
40{ 102{
41 public InlistMem __in_list {get;set;} 103 public InlistMem __in_list {get;set;}
42 public T Val {get;set;} 104 public T Val {get;set;}
105
106 /// <summary>
107 /// Gets a hash for <see cref="InlistNode{T}" />.
108 /// <para>Since EFL 1.24.</para>
109 /// </summary>
110 /// <returns>A hash code.</returns>
111 public override int GetHashCode()
112 => __in_list.GetHashCode() ^ Val.GetHashCode();
113
114 /// <summary>Returns whether this <see cref="InlistNode{T}" />
115 /// is equal to the given <see cref="object" />.
116 /// <para>Since EFL 1.24.</para>
117 /// </summary>
118 /// <param name="other">The <see cref="object" /> to be compared to.</param>
119 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
120 public override bool Equals(object other)
121 => (!(other is InlistNode<T>)) ? false : Equals((InlistNode<T>)other);
122
123 /// <summary>Returns whether this <see cref="InlistNode{T}" /> is equal
124 /// to the given <see cref="InlistNode{T}" />.
125 /// <para>Since EFL 1.24.</para>
126 /// </summary>
127 /// <param name="other">The <see cref="InlistNode{T}" /> to be compared to.</param>
128 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
129 public bool Equals(InlistNode<T> other)
130 => (__in_list == other.__in_list) && (Val.Equals(other.Val));
131
132 /// <summary>Returns whether <c>lhs</c> is equal to <c>rhs</c>.
133 /// <para>Since EFL 1.24.</para>
134 /// </summary>
135 /// <param name="lhs">The left hand side of the operator.</param>
136 /// <param name="rhs">The right hand side of the operator.</param>
137 /// <returns><c>true</c> if <c>lhs</c> is equal
138 /// to <c>rhs</c>.</returns>
139 public static bool operator==(InlistNode<T> lhs, InlistNode<T> rhs)
140 => lhs.Equals(rhs);
141
142 /// <summary>Returns whether <c>lhs</c> is not equal to <c>rhs</c>.
143 /// <para>Since EFL 1.24.</para>
144 /// </summary>
145 /// <param name="lhs">The left hand side of the operator.</param>
146 /// <param name="rhs">The right hand side of the operator.</param>
147 /// <returns><c>true</c> if <c>lhs</c> is not equal
148 /// to <c>rhs</c>.</returns>
149 public static bool operator!=(InlistNode<T> lhs, InlistNode<T> rhs)
150 => !(lhs == rhs);
43} 151}
44 152
45[EditorBrowsable(EditorBrowsableState.Never)] 153[EditorBrowsable(EditorBrowsableState.Never)]
46public interface IBaseElementTraits<T> 154internal interface IBaseElementTraits<T>
47{ 155{
48 IntPtr ManagedToNativeAlloc(T man); 156 IntPtr ManagedToNativeAlloc(T man);
49 IntPtr ManagedToNativeAllocInlistNode(T man); 157 IntPtr ManagedToNativeAllocInlistNode(T man);
@@ -64,7 +172,7 @@ public interface IBaseElementTraits<T>
64} 172}
65 173
66[EditorBrowsable(EditorBrowsableState.Never)] 174[EditorBrowsable(EditorBrowsableState.Never)]
67public class StringElementTraits : IBaseElementTraits<string> 175internal class StringElementTraits : IBaseElementTraits<string>
68{ 176{
69 public StringElementTraits() 177 public StringElementTraits()
70 { 178 {
@@ -203,7 +311,7 @@ public class StringElementTraits : IBaseElementTraits<string>
203} 311}
204 312
205[EditorBrowsable(EditorBrowsableState.Never)] 313[EditorBrowsable(EditorBrowsableState.Never)]
206public class StringshareElementTraits : IBaseElementTraits<Eina.Stringshare> 314internal class StringshareElementTraits : IBaseElementTraits<Eina.Stringshare>
207{ 315{
208 public StringshareElementTraits() 316 public StringshareElementTraits()
209 { 317 {
@@ -343,7 +451,7 @@ public class StringshareElementTraits : IBaseElementTraits<Eina.Stringshare>
343} 451}
344 452
345[EditorBrowsable(EditorBrowsableState.Never)] 453[EditorBrowsable(EditorBrowsableState.Never)]
346public class EflObjectElementTraits<T> : IBaseElementTraits<T> 454internal class EflObjectElementTraits<T> : IBaseElementTraits<T>
347{ 455{
348 public IntPtr ManagedToNativeAlloc(T man) 456 public IntPtr ManagedToNativeAlloc(T man)
349 { 457 {
@@ -501,7 +609,7 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
501} 609}
502 610
503[EditorBrowsable(EditorBrowsableState.Never)] 611[EditorBrowsable(EditorBrowsableState.Never)]
504public abstract class PrimitiveElementTraits<T> 612internal abstract class PrimitiveElementTraits<T>
505{ 613{
506 private Eina.Callbacks.EinaCompareCb dlgt = null; 614 private Eina.Callbacks.EinaCompareCb dlgt = null;
507 615
@@ -603,7 +711,7 @@ public abstract class PrimitiveElementTraits<T>
603} 711}
604 712
605[EditorBrowsable(EditorBrowsableState.Never)] 713[EditorBrowsable(EditorBrowsableState.Never)]
606abstract public class Primitive32ElementTraits<T> : PrimitiveElementTraits<T>, IBaseElementTraits<T> 714internal abstract class Primitive32ElementTraits<T> : PrimitiveElementTraits<T>, IBaseElementTraits<T>
607{ 715{
608 private static IBaseElementTraits<Int32> int32Traits = null; 716 private static IBaseElementTraits<Int32> int32Traits = null;
609 717
@@ -627,7 +735,7 @@ abstract public class Primitive32ElementTraits<T> : PrimitiveElementTraits<T>, I
627 735
628 public IntPtr ManagedToNativeAllocRef(T man, bool refs) 736 public IntPtr ManagedToNativeAllocRef(T man, bool refs)
629 { 737 {
630 return int32Traits.ManagedToNativeAlloc(Convert.ToInt32((object)man)); 738 return int32Traits.ManagedToNativeAlloc(Convert.ToInt32((object)man, CultureInfo.CurrentCulture));
631 } 739 }
632 740
633 public void NativeFreeRef(IntPtr nat, bool unrefs) 741 public void NativeFreeRef(IntPtr nat, bool unrefs)
@@ -642,7 +750,7 @@ abstract public class Primitive32ElementTraits<T> : PrimitiveElementTraits<T>, I
642} 750}
643 751
644[EditorBrowsable(EditorBrowsableState.Never)] 752[EditorBrowsable(EditorBrowsableState.Never)]
645abstract public class Primitive64ElementTraits<T> : PrimitiveElementTraits<T>, IBaseElementTraits<T> 753internal abstract class Primitive64ElementTraits<T> : PrimitiveElementTraits<T>, IBaseElementTraits<T>
646{ 754{
647 private static IBaseElementTraits<Int64> int64Traits = null; 755 private static IBaseElementTraits<Int64> int64Traits = null;
648 756
@@ -666,7 +774,7 @@ abstract public class Primitive64ElementTraits<T> : PrimitiveElementTraits<T>, I
666 774
667 public IntPtr ManagedToNativeAllocRef(T man, bool refs) 775 public IntPtr ManagedToNativeAllocRef(T man, bool refs)
668 { 776 {
669 return int64Traits.ManagedToNativeAlloc(Convert.ToInt64((object)man)); 777 return int64Traits.ManagedToNativeAlloc(Convert.ToInt64((object)man, CultureInfo.CurrentCulture));
670 } 778 }
671 779
672 public void NativeFreeRef(IntPtr nat, bool unrefs) 780 public void NativeFreeRef(IntPtr nat, bool unrefs)
@@ -681,7 +789,7 @@ abstract public class Primitive64ElementTraits<T> : PrimitiveElementTraits<T>, I
681} 789}
682 790
683[EditorBrowsable(EditorBrowsableState.Never)] 791[EditorBrowsable(EditorBrowsableState.Never)]
684public class IntElementTraits : Primitive32ElementTraits<int>, IBaseElementTraits<int> 792internal class IntElementTraits : Primitive32ElementTraits<int>, IBaseElementTraits<int>
685{ 793{
686 override public void ManagedToNativeCopyTo(int man, IntPtr mem) 794 override public void ManagedToNativeCopyTo(int man, IntPtr mem)
687 { 795 {
@@ -706,7 +814,7 @@ public class IntElementTraits : Primitive32ElementTraits<int>, IBaseElementTrait
706} 814}
707 815
708[EditorBrowsable(EditorBrowsableState.Never)] 816[EditorBrowsable(EditorBrowsableState.Never)]
709public class CharElementTraits : Primitive32ElementTraits<char>, IBaseElementTraits<char> 817internal class CharElementTraits : Primitive32ElementTraits<char>, IBaseElementTraits<char>
710{ 818{
711 override public void ManagedToNativeCopyTo(char man, IntPtr mem) 819 override public void ManagedToNativeCopyTo(char man, IntPtr mem)
712 { 820 {
@@ -731,7 +839,7 @@ public class CharElementTraits : Primitive32ElementTraits<char>, IBaseElementTra
731} 839}
732 840
733[EditorBrowsable(EditorBrowsableState.Never)] 841[EditorBrowsable(EditorBrowsableState.Never)]
734public class LongElementTraits : Primitive64ElementTraits<long>, IBaseElementTraits<long> 842internal class LongElementTraits : Primitive64ElementTraits<long>, IBaseElementTraits<long>
735{ 843{
736 override public void ManagedToNativeCopyTo(long man, IntPtr mem) 844 override public void ManagedToNativeCopyTo(long man, IntPtr mem)
737 { 845 {
@@ -756,7 +864,7 @@ public class LongElementTraits : Primitive64ElementTraits<long>, IBaseElementTra
756} 864}
757 865
758[EditorBrowsable(EditorBrowsableState.Never)] 866[EditorBrowsable(EditorBrowsableState.Never)]
759public class ShortElementTraits : Primitive32ElementTraits<short>, IBaseElementTraits<short> 867internal class ShortElementTraits : Primitive32ElementTraits<short>, IBaseElementTraits<short>
760{ 868{
761 override public void ManagedToNativeCopyTo(short man, IntPtr mem) 869 override public void ManagedToNativeCopyTo(short man, IntPtr mem)
762 { 870 {
@@ -781,7 +889,7 @@ public class ShortElementTraits : Primitive32ElementTraits<short>, IBaseElementT
781} 889}
782 890
783[EditorBrowsable(EditorBrowsableState.Never)] 891[EditorBrowsable(EditorBrowsableState.Never)]
784public class FloatElementTraits : Primitive32ElementTraits<float>, IBaseElementTraits<float> 892internal class FloatElementTraits : Primitive32ElementTraits<float>, IBaseElementTraits<float>
785{ 893{
786 override public void ManagedToNativeCopyTo(float man, IntPtr mem) 894 override public void ManagedToNativeCopyTo(float man, IntPtr mem)
787 { 895 {
@@ -806,7 +914,7 @@ public class FloatElementTraits : Primitive32ElementTraits<float>, IBaseElementT
806} 914}
807 915
808[EditorBrowsable(EditorBrowsableState.Never)] 916[EditorBrowsable(EditorBrowsableState.Never)]
809public class DoubleElementTraits : Primitive64ElementTraits<double>, IBaseElementTraits<double> 917internal class DoubleElementTraits : Primitive64ElementTraits<double>, IBaseElementTraits<double>
810{ 918{
811 override public void ManagedToNativeCopyTo(double man, IntPtr mem) 919 override public void ManagedToNativeCopyTo(double man, IntPtr mem)
812 { 920 {
@@ -831,7 +939,7 @@ public class DoubleElementTraits : Primitive64ElementTraits<double>, IBaseElemen
831} 939}
832 940
833[EditorBrowsable(EditorBrowsableState.Never)] 941[EditorBrowsable(EditorBrowsableState.Never)]
834public class ByteElementTraits : Primitive32ElementTraits<byte>, IBaseElementTraits<byte> 942internal class ByteElementTraits : Primitive32ElementTraits<byte>, IBaseElementTraits<byte>
835{ 943{
836 override public void ManagedToNativeCopyTo(byte man, IntPtr mem) 944 override public void ManagedToNativeCopyTo(byte man, IntPtr mem)
837 { 945 {
@@ -856,7 +964,7 @@ public class ByteElementTraits : Primitive32ElementTraits<byte>, IBaseElementTra
856} 964}
857 965
858[EditorBrowsable(EditorBrowsableState.Never)] 966[EditorBrowsable(EditorBrowsableState.Never)]
859public static class TraitFunctions 967internal static class TraitFunctions
860{ 968{
861 public static bool IsEflObject(System.Type type) 969 public static bool IsEflObject(System.Type type)
862 { 970 {
diff --git a/src/bindings/mono/eina_mono/eina_environment.cs b/src/bindings/mono/eina_mono/eina_environment.cs
new file mode 100644
index 0000000..e7f847b
--- /dev/null
+++ b/src/bindings/mono/eina_mono/eina_environment.cs
@@ -0,0 +1,53 @@
1using System;
2using System.Runtime.InteropServices;
3
4namespace Eina
5{
6
7/// <summary>
8/// Class to deal with native Environment variables.
9///
10/// <para>To be used in place of <see cref="System.Environment" /> methods when
11/// accessing the native environment directly.</para>
12/// <para>Since EFL 1.24.</para>
13/// </summary>
14internal static class Environment
15{
16 /// <summary>
17 /// Returns the value of the environment variable named <c>name</c>.
18 ///
19 /// <para>Since EFL 1.24.</para>
20 /// </summary>
21 /// <param name="name">The name of the variable to be retrieved</param>
22 /// <returns>The value of the variable. <c>null</c> if not set.</returns>
23 public static string GetEnv(string name)
24 {
25 return Eina.NativeCustomExportFunctions.efl_mono_native_getenv(name);
26 }
27
28 /// <summary>
29 /// Sets a native environment variable.
30 ///
31 /// <para>Since EFL 1.24.</para>
32 /// </summary>
33 /// <param name="name">The name of the variable</param>
34 /// <param name="value">The value to be set.</param>
35 /// <param name="overwrite"><c>true</c> if an existing variable must be overwritten.</param>
36 public static void SetEnv(string name, string value, bool overwrite=true)
37 {
38 Eina.Error error = Eina.NativeCustomExportFunctions.efl_mono_native_setenv(name, value, overwrite ? 1 : 0);
39 Eina.Error.Raise(error);
40 }
41}
42
43internal static partial class NativeCustomExportFunctions
44{
45 [DllImport(efl.Libs.CustomExports, CharSet=CharSet.Ansi)]
46 [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]
47 public static extern string efl_mono_native_getenv(string name);
48
49 [DllImport(efl.Libs.CustomExports, CharSet=CharSet.Ansi)]
50 public static extern Eina.Error efl_mono_native_setenv(string name, string value, int overwrite);
51}
52
53}
diff --git a/src/bindings/mono/eina_mono/eina_error.cs b/src/bindings/mono/eina_mono/eina_error.cs
index 7b5733d..1300e79 100644
--- a/src/bindings/mono/eina_mono/eina_error.cs
+++ b/src/bindings/mono/eina_mono/eina_error.cs
@@ -1,7 +1,23 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
20using System.Diagnostics.CodeAnalysis;
5 21
6namespace Eina 22namespace Eina
7{ 23{
@@ -9,7 +25,7 @@ namespace Eina
9/// <summary>Error codes from native Eina methods. 25/// <summary>Error codes from native Eina methods.
10/// <para>Since EFL 1.23.</para> 26/// <para>Since EFL 1.23.</para>
11/// </summary> 27/// </summary>
12public struct Error : IComparable<Error> 28public struct Error : IComparable<Error>, IEquatable<Error>
13{ 29{
14 int code; 30 int code;
15 31
@@ -26,7 +42,7 @@ public struct Error : IComparable<Error>
26 /// Unhandled Exception error identifier. 42 /// Unhandled Exception error identifier.
27 /// <para>Since EFL 1.23.</para> 43 /// <para>Since EFL 1.23.</para>
28 /// </summary> 44 /// </summary>
29 public static readonly Error UNHANDLED_EXCEPTION; 45 public static readonly Error UNHANDLED_EXCEPTION = eina_error_msg_register("Unhandled C# exception occurred.");
30 46
31 /// <summary> 47 /// <summary>
32 /// No error identifier. 48 /// No error identifier.
@@ -64,31 +80,28 @@ public struct Error : IComparable<Error>
64 /// <para>Since EFL 1.23.</para> 80 /// <para>Since EFL 1.23.</para>
65 /// </summary> 81 /// </summary>
66 /// <param name="val">Value to be converted to Error</param> 82 /// <param name="val">Value to be converted to Error</param>
67 static public implicit operator Error(int val) 83 public static implicit operator Error(int val) => FromInt32(val);
68 { 84
69 return new Error(val); 85 /// <summary>
70 } 86 /// Converts a <see cref="int" /> to a <see cref="Error" />.
87 /// <para>Since EFL 1.23.</para>
88 /// </summary>
89 /// <param name="val">The <see cref="int" /> to be converted.</param>
90 public static Error FromInt32(int val) => new Error(val);
71 91
72 /// <summary> 92 /// <summary>
73 /// Int conversion from Error. 93 /// Int conversion from Error.
74 /// <para>Since EFL 1.23.</para> 94 /// <para>Since EFL 1.23.</para>
75 /// </summary> 95 /// </summary>
76 /// <param name="error">Error identifier to be converted to int</param> 96 /// <param name="error">Error identifier to be converted to int</param>
77 static public implicit operator int(Error error) 97 public static implicit operator int(Error error) => ToInt32(error);
78 {
79 return error.code;
80 }
81 98
82 /// <summary> 99 /// <summary>
83 /// Compare two Errors. 100 /// Converts a <see cref="Error" /> to a <see cref="int" />.
84 /// <para>Since EFL 1.23.</para> 101 /// <para>Since EFL 1.23.</para>
85 /// </summary> 102 /// </summary>
86 /// <param name="err">Error to be compared with</param> 103 /// <param name="error">The <see cref="Error" /> to be converted.</param>
87 /// <returns>True with the Errors is equal, False otherwise.</returns> 104 public static int ToInt32(Error error) => error.code;
88 public int CompareTo(Error err)
89 {
90 return code.CompareTo(err.code);
91 }
92 105
93 /// <summary> 106 /// <summary>
94 /// Transform the object to a string representing the object. 107 /// Transform the object to a string representing the object.
@@ -100,11 +113,6 @@ public struct Error : IComparable<Error>
100 return "Eina.Error(" + code + ")"; 113 return "Eina.Error(" + code + ")";
101 } 114 }
102 115
103 static Error()
104 {
105 UNHANDLED_EXCEPTION = eina_error_msg_register("Unhandled C# exception occurred.");
106 }
107
108 [DllImport(efl.Libs.Eina)] static extern Error eina_error_msg_register(string msg); 116 [DllImport(efl.Libs.Eina)] static extern Error eina_error_msg_register(string msg);
109 [DllImport(efl.Libs.Eina)] static extern Error eina_error_get(); 117 [DllImport(efl.Libs.Eina)] static extern Error eina_error_get();
110 [DllImport(efl.Libs.Eina)] static extern void eina_error_set(Error error); 118 [DllImport(efl.Libs.Eina)] static extern void eina_error_set(Error error);
@@ -146,6 +154,8 @@ public struct Error : IComparable<Error>
146 /// back to the native code. For example, in an event handler. 154 /// back to the native code. For example, in an event handler.
147 /// <para>Since EFL 1.23.</para> 155 /// <para>Since EFL 1.23.</para>
148 /// </summary> 156 /// </summary>
157 [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate",
158 Justification = "It's not an event.")]
149 public static void RaiseIfUnhandledException() 159 public static void RaiseIfUnhandledException()
150 { 160 {
151 Error e = Get(); 161 Error e = Get();
@@ -160,6 +170,8 @@ public struct Error : IComparable<Error>
160 /// Raises an exception. 170 /// Raises an exception.
161 /// <para>Since EFL 1.23.</para> 171 /// <para>Since EFL 1.23.</para>
162 /// </summary> 172 /// </summary>
173 [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate",
174 Justification = "It's not an event.")]
163 public static void Raise(Error e) 175 public static void Raise(Error e)
164 { 176 {
165 if (e != 0) 177 if (e != 0)
@@ -187,6 +199,98 @@ public struct Error : IComparable<Error>
187 { 199 {
188 return eina_error_msg_register(msg); 200 return eina_error_msg_register(msg);
189 } 201 }
190}
191 202
203 /// <summary>
204 /// Gets a hash for <see cref="Eina.Error" />.
205 /// <para>Since EFL 1.23.</para>
206 /// </summary>
207 /// <returns>A hash code.</returns>
208 public override int GetHashCode()
209 => code.GetHashCode() + Message.GetHashCode(StringComparison.Ordinal);
210
211 /// <summary>
212 /// Compare to a given error.
213 /// <para>Since EFL 1.23.</para>
214 /// </summary>
215 /// <param name="err">Error to be compared with.</param>
216 /// <returns>-1, 0 or 1 if -1 if Error is less, equal or greater than err.</returns>
217 public int CompareTo(Error err) => code.CompareTo(err.code);
218
219 /// <summary>
220 /// Check if is equal to obj.
221 /// <para>Since EFL 1.23.</para>
222 /// </summary>
223 /// <param name="obj">The object to be checked.</param>
224 /// <returns>false if obj is null or not equals, true otherwise.</returns>
225 public override bool Equals(object obj)
226 {
227 if (object.ReferenceEquals(obj, null))
228 return false;
229
230 return this.Equals((Error)obj);
231 }
232
233 /// <summary>
234 /// Check if is equal to err.
235 /// <para>Since EFL 1.23.</para>
236 /// </summary>
237 /// <param name="err">The object to be checked.</param>
238 /// <returns>false if obj is null or not equals, true otherwise.</returns>
239 public bool Equals(Error err) => this.CompareTo(err) == 0;
240
241 /// <summary>
242 /// Check if lhs is equals to rhs.
243 /// <para>Since EFL 1.23.</para>
244 /// </summary>
245 /// <param name="lhs">The left hand side of the operator.</param>
246 /// <param name="rhs">The right hand side of the operator.</param>
247 /// <returns>true if lhs is equals to rhs, false otherwise.</returns>
248 public static bool operator==(Error lhs, Error rhs) => lhs.Equals(rhs);
249
250 /// <summary>
251 /// Check if lhs is not equals to rhs.
252 /// <para>Since EFL 1.23.</para>
253 /// </summary>
254 /// <param name="lhs">The left hand side of the operator.</param>
255 /// <param name="rhs">The right hand side of the operator.</param>
256 /// <returns>true if lhs is not equals to rhs, false otherwise.</returns>
257 public static bool operator!=(Error lhs, Error rhs) => !(lhs == rhs);
258
259 /// <summary>
260 /// Check if lhs is less than rhs.
261 /// <para>Since EFL 1.23.</para>
262 /// </summary>
263 /// <param name="lhs">The left hand side of the operator.</param>
264 /// <param name="rhs">The right hand side of the operator.</param>
265 /// <returns>true if lhs is less than rhs, false otherwise.</returns>
266 public static bool operator<(Error lhs, Error rhs) => (lhs.CompareTo(rhs) < 0);
267
268 /// <summary>
269 /// Check if lhs is greater to rhs.
270 /// <para>Since EFL 1.23.</para>
271 /// </summary>
272 /// <param name="lhs">The left hand side of the operator.</param>
273 /// <param name="rhs">The right hand side of the operator.</param>
274 /// <returns>true if lhs is greater than rhs, false otherwise.</returns>
275 public static bool operator>(Error lhs, Error rhs) => rhs < lhs;
276
277 /// <summary>
278 /// Check if lhs is equals and less than rhs.
279 /// <para>Since EFL 1.23.</para>
280 /// </summary>
281 /// <param name="lhs">The left hand side of the operator.</param>
282 /// <param name="rhs">The right hand side of the operator.</param>
283 /// <returns>true if lhs is equals and less than rhs, false otherwise.</returns>
284 public static bool operator<=(Error lhs, Error rhs) => !(lhs > rhs);
285
286 /// <summary>
287 /// Check if lhs is equals and greater than rhs.
288 /// <para>Since EFL 1.23.</para>
289 /// </summary>
290 /// <param name="lhs">The left hand side of the operator.</param>
291 /// <param name="rhs">The right hand side of the operator.</param>
292 /// <returns>true if lhs is equals and greater than rhs, false otherwise.</returns>
293 public static bool operator>=(Error lhs, Error rhs) => !(lhs < rhs);
294
295}
192} 296}
diff --git a/src/bindings/mono/eina_mono/eina_hash.cs b/src/bindings/mono/eina_mono/eina_hash.cs
index 54fd343..3cc8980 100644
--- a/src/bindings/mono/eina_mono/eina_hash.cs
+++ b/src/bindings/mono/eina_mono/eina_hash.cs
@@ -1,9 +1,25 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.Collections.Generic; 20using System.Collections.Generic;
6using System.ComponentModel; 21using System.ComponentModel;
22using System.Diagnostics.CodeAnalysis;
7 23
8using static Eina.TraitFunctions; 24using static Eina.TraitFunctions;
9using static Eina.IteratorNativeFunctions; 25using static Eina.IteratorNativeFunctions;
@@ -15,15 +31,61 @@ namespace Eina
15 31
16[StructLayout(LayoutKind.Sequential)] 32[StructLayout(LayoutKind.Sequential)]
17[EditorBrowsable(EditorBrowsableState.Never)] 33[EditorBrowsable(EditorBrowsableState.Never)]
18public struct HashTupleNative 34internal struct HashTupleNative : IEquatable<HashTupleNative>
19{ 35{
20 public IntPtr key; 36 public IntPtr key;
21 public IntPtr data; 37 public IntPtr data;
22 public uint key_length; 38 public uint key_length;
39
40 /// <summary>
41 /// Gets a hash for <see cref="HashTupleNative" />.
42 /// <para>Since EFL 1.24.</para>
43 /// </summary>
44 /// <returns>A hash code.</returns>
45 public override int GetHashCode()
46 => key.GetHashCode() ^ data.GetHashCode() ^ key_length.GetHashCode();
47
48 /// <summary>Returns whether this <see cref="HashTupleNative" />
49 /// is equal to the given <see cref="object" />.
50 /// <para>Since EFL 1.24.</para>
51 /// </summary>
52 /// <param name="other">The <see cref="object" /> to be compared to.</param>
53 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
54 public override bool Equals(object other)
55 => (!(other is HashTupleNative)) ? false : Equals((HashTupleNative)other);
56
57 /// <summary>Returns whether this <see cref="HashTupleNative" /> is equal
58 /// to the given <see cref="HashTupleNative" />.
59 /// <para>Since EFL 1.24.</para>
60 /// </summary>
61 /// <param name="other">The <see cref="HashTupleNative" /> to be compared to.</param>
62 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
63 public bool Equals(HashTupleNative other)
64 => (key == other.key) && (data == other.data)
65 && (key_length == other.key_length);
66
67 /// <summary>Returns whether <c>lhs</c> is equal to <c>rhs</c>.
68 /// <para>Since EFL 1.24.</para>
69 /// </summary>
70 /// <param name="lhs">The left hand side of the operator.</param>
71 /// <param name="rhs">The right hand side of the operator.</param>
72 /// <returns><c>true</c> if <c>lhs</c> is equal
73 /// to <c>rhs</c>.</returns>
74 public static bool operator==(HashTupleNative lhs, HashTupleNative rhs)
75 => lhs.Equals(rhs);
76
77 /// <summary>Returns whether <c>lhs</c> is not equal to <c>rhs</c>.
78 /// <para>Since EFL 1.24.</para>
79 /// </summary>
80 /// <param name="lhs">The left hand side of the operator.</param>
81 /// <param name="rhs">The right hand side of the operator.</param>
82 /// <returns><c>true</c> if <c>lhs</c> is not equal
83 /// to <c>rhs</c>.</returns>
84 public static bool operator!=(HashTupleNative lhs, HashTupleNative rhs) => !(lhs == rhs);
23} 85}
24 86
25[EditorBrowsable(EditorBrowsableState.Never)] 87[EditorBrowsable(EditorBrowsableState.Never)]
26public static class HashNativeFunctions 88internal static class HashNativeFunctions
27{ 89{
28 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 90 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
29 eina_hash_new(IntPtr key_length_cb, IntPtr key_cmp_cb, IntPtr key_hash_cb, IntPtr data_free_cb, int buckets_power_size); 91 eina_hash_new(IntPtr key_length_cb, IntPtr key_cmp_cb, IntPtr key_hash_cb, IntPtr data_free_cb, int buckets_power_size);
@@ -135,8 +197,10 @@ public static class HashNativeFunctions
135 197
136/// <summary>Wrapper around native dictionary mapping keys to values. 198/// <summary>Wrapper around native dictionary mapping keys to values.
137/// 199///
138/// Since EFL 1.23. 200/// <para>Since EFL 1.23.</para>
139/// </summary> 201/// </summary>
202[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
203 Justification = "This is a generalized container mapping the native one.")]
140public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDisposable 204public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDisposable
141{ 205{
142 [EditorBrowsable(EditorBrowsableState.Never)] 206 [EditorBrowsable(EditorBrowsableState.Never)]
diff --git a/src/bindings/mono/eina_mono/eina_inarray.cs b/src/bindings/mono/eina_mono/eina_inarray.cs
index 0263faf..6bb8626 100644
--- a/src/bindings/mono/eina_mono/eina_inarray.cs
+++ b/src/bindings/mono/eina_mono/eina_inarray.cs
@@ -1,9 +1,26 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.Collections.Generic; 20using System.Collections.Generic;
6using System.ComponentModel; 21using System.ComponentModel;
22using System.Diagnostics.CodeAnalysis;
23using System.Diagnostics.Contracts;
7 24
8using static Eina.TraitFunctions; 25using static Eina.TraitFunctions;
9using static Eina.InarrayNativeFunctions; 26using static Eina.InarrayNativeFunctions;
@@ -12,7 +29,7 @@ namespace Eina
12{ 29{
13 30
14[EditorBrowsable(EditorBrowsableState.Never)] 31[EditorBrowsable(EditorBrowsableState.Never)]
15public static class InarrayNativeFunctions 32internal static class InarrayNativeFunctions
16{ 33{
17 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 34 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
18 eina_inarray_new(uint member_size, uint step); 35 eina_inarray_new(uint member_size, uint step);
@@ -72,6 +89,8 @@ public static class InarrayNativeFunctions
72/// <summary>Wrapper around an inplace array. 89/// <summary>Wrapper around an inplace array.
73/// <para>Since EFL 1.23.</para> 90/// <para>Since EFL 1.23.</para>
74/// </summary> 91/// </summary>
92[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
93 Justification="This is a generalized container mapping the native one.")]
75public class Inarray<T> : IEnumerable<T>, IDisposable 94public class Inarray<T> : IEnumerable<T>, IDisposable
76{ 95{
77 public const uint DefaultStep = 0; 96 public const uint DefaultStep = 0;
@@ -467,6 +486,7 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
467 /// <returns>true on success, false otherwise.</returns> 486 /// <returns>true on success, false otherwise.</returns>
468 public bool Append(T[] values) 487 public bool Append(T[] values)
469 { 488 {
489 Contract.Requires(values != null, nameof(values));
470 foreach (T v in values) 490 foreach (T v in values)
471 { 491 {
472 if (Push(v) == -1) 492 if (Push(v) == -1)
diff --git a/src/bindings/mono/eina_mono/eina_inlist.cs b/src/bindings/mono/eina_mono/eina_inlist.cs
index a2769bc..3d2670e 100644
--- a/src/bindings/mono/eina_mono/eina_inlist.cs
+++ b/src/bindings/mono/eina_mono/eina_inlist.cs
@@ -1,9 +1,26 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.Collections.Generic; 20using System.Collections.Generic;
6using System.ComponentModel; 21using System.ComponentModel;
22using System.Diagnostics.CodeAnalysis;
23using System.Diagnostics.Contracts;
7 24
8using static Eina.TraitFunctions; 25using static Eina.TraitFunctions;
9using static Eina.InlistNativeFunctions; 26using static Eina.InlistNativeFunctions;
@@ -13,7 +30,7 @@ namespace Eina
13{ 30{
14 31
15[EditorBrowsable(EditorBrowsableState.Never)] 32[EditorBrowsable(EditorBrowsableState.Never)]
16public static class InlistNativeFunctions 33internal static class InlistNativeFunctions
17{ 34{
18 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 35 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
19 eina_inlist_append(IntPtr in_list, IntPtr in_item); 36 eina_inlist_append(IntPtr in_list, IntPtr in_item);
@@ -85,6 +102,8 @@ public static class InlistNativeFunctions
85/// <summary>Wrapper around an inplace list. 102/// <summary>Wrapper around an inplace list.
86/// <para>Since EFL 1.23.</para> 103/// <para>Since EFL 1.23.</para>
87/// </summary> 104/// </summary>
105[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
106 Justification="This is a generalized container mapping the native one.")]
88public class Inlist<T> : IEnumerable<T>, IDisposable 107public class Inlist<T> : IEnumerable<T>, IDisposable
89{ 108{
90 [EditorBrowsable(EditorBrowsableState.Never)] 109 [EditorBrowsable(EditorBrowsableState.Never)]
@@ -404,6 +423,7 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
404 /// <param name="values">The values to be added.</param> 423 /// <param name="values">The values to be added.</param>
405 public void AppendArray(T[] values) 424 public void AppendArray(T[] values)
406 { 425 {
426 Contract.Requires(values != null, nameof(values));
407 foreach (T v in values) 427 foreach (T v in values)
408 { 428 {
409 Append(v); 429 Append(v);
diff --git a/src/bindings/mono/eina_mono/eina_iterator.cs b/src/bindings/mono/eina_mono/eina_iterator.cs
index b95e1e6..f142c3c 100644
--- a/src/bindings/mono/eina_mono/eina_iterator.cs
+++ b/src/bindings/mono/eina_mono/eina_iterator.cs
@@ -1,9 +1,25 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.Collections.Generic; 20using System.Collections.Generic;
6using System.ComponentModel; 21using System.ComponentModel;
22using System.Diagnostics.CodeAnalysis;
7 23
8using static Eina.TraitFunctions; 24using static Eina.TraitFunctions;
9using static Eina.IteratorNativeFunctions; 25using static Eina.IteratorNativeFunctions;
@@ -12,7 +28,7 @@ namespace Eina
12{ 28{
13 29
14[EditorBrowsable(EditorBrowsableState.Never)] 30[EditorBrowsable(EditorBrowsableState.Never)]
15public static class IteratorNativeFunctions 31internal static class IteratorNativeFunctions
16{ 32{
17 [DllImport(efl.Libs.Eina)] internal static extern void 33 [DllImport(efl.Libs.Eina)] internal static extern void
18 eina_iterator_free(IntPtr iterator); 34 eina_iterator_free(IntPtr iterator);
@@ -29,11 +45,15 @@ public static class IteratorNativeFunctions
29 45
30 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 46 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
31 eina_carray_iterator_new(IntPtr array); 47 eina_carray_iterator_new(IntPtr array);
48 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
49 eina_carray_length_iterator_new(IntPtr array, uint step, uint length);
32} 50}
33 51
34/// <summary>Wrapper around a native Eina iterator. 52/// <summary>Wrapper around a native Eina iterator.
35/// <para>Since EFL 1.23.</para> 53/// <para>Since EFL 1.23.</para>
36/// </summary> 54/// </summary>
55[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
56 Justification="This is a generalized container mapping the native one.")]
37public class Iterator<T> : IEnumerable<T>, IDisposable 57public class Iterator<T> : IEnumerable<T>, IDisposable
38{ 58{
39 [EditorBrowsable(EditorBrowsableState.Never)] 59 [EditorBrowsable(EditorBrowsableState.Never)]
diff --git a/src/bindings/mono/eina_mono/eina_list.cs b/src/bindings/mono/eina_mono/eina_list.cs
index df2fb68..f4882d0 100644
--- a/src/bindings/mono/eina_mono/eina_list.cs
+++ b/src/bindings/mono/eina_mono/eina_list.cs
@@ -1,9 +1,26 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.Collections.Generic; 20using System.Collections.Generic;
6using System.ComponentModel; 21using System.ComponentModel;
22using System.Diagnostics.CodeAnalysis;
23using System.Diagnostics.Contracts;
7 24
8using static Eina.TraitFunctions; 25using static Eina.TraitFunctions;
9using static Eina.ListNativeFunctions; 26using static Eina.ListNativeFunctions;
@@ -13,7 +30,7 @@ namespace Eina
13{ 30{
14 31
15[EditorBrowsable(EditorBrowsableState.Never)] 32[EditorBrowsable(EditorBrowsableState.Never)]
16public static class ListNativeFunctions 33internal static class ListNativeFunctions
17{ 34{
18 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 35 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
19 eina_list_append(IntPtr list, IntPtr data); 36 eina_list_append(IntPtr list, IntPtr data);
@@ -109,19 +126,24 @@ public static class ListNativeFunctions
109/// <summary>Native wrapper around a linked list of items. 126/// <summary>Native wrapper around a linked list of items.
110/// <para>Since EFL 1.23.</para> 127/// <para>Since EFL 1.23.</para>
111/// </summary> 128/// </summary>
112public class List<T> : IEnumerable<T>, IDisposable 129[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
130 Justification="This is a generalized container mapping the native one.")]
131public class List<T> : IList<T>, IEnumerable<T>, IDisposable
113{ 132{
114 133
115 [EditorBrowsable(EditorBrowsableState.Never)] 134 [EditorBrowsable(EditorBrowsableState.Never)]
116 public IntPtr Handle {get;set;} = IntPtr.Zero; 135 public IntPtr Handle {get; set; } = IntPtr.Zero;
136
117 /// <summary>Whether this managed list owns the native one. 137 /// <summary>Whether this managed list owns the native one.
118 /// <para>Since EFL 1.23.</para> 138 /// <para>Since EFL 1.23.</para>
119 /// </summary> 139 /// </summary>
120 public bool Own {get;set;} 140 internal bool Own { get; set; }
141
121 /// <summary>Whether the native list wrapped owns the content it points to. 142 /// <summary>Whether the native list wrapped owns the content it points to.
122 /// <para>Since EFL 1.23.</para> 143 /// <para>Since EFL 1.23.</para>
123 ///</summary> 144 ///</summary>
124 public bool OwnContent {get;set;} 145 internal bool OwnContent { get; set; }
146
125 147
126 /// <summary>Delegate for comparing two elements of this list. 148 /// <summary>Delegate for comparing two elements of this list.
127 /// <para>Since EFL 1.23.</para> 149 /// <para>Since EFL 1.23.</para>
@@ -131,15 +153,16 @@ public class List<T> : IEnumerable<T>, IDisposable
131 /// <returns>-1, 0 or 1 for respectively smaller, equal or larger.</returns> 153 /// <returns>-1, 0 or 1 for respectively smaller, equal or larger.</returns>
132 public delegate int Compare(T a, T b); 154 public delegate int Compare(T a, T b);
133 155
134 /// <summary>The number of elements on this list. 156 public bool IsReadOnly { get => !OwnContent; }
135 /// <para>Since EFL 1.23.</para> 157
158 /// <summary>The number of elements in this list.
159 /// <para>Since EFL 1.24.</para>
136 /// </summary> 160 /// </summary>
137 public int Length 161 public int Count
138 { 162 {
139 get { return Count(); } 163 get => (int)eina_list_count_custom_export_mono(Handle);
140 } 164 }
141 165
142
143 private void InitNew() 166 private void InitNew()
144 { 167 {
145 Handle = IntPtr.Zero; 168 Handle = IntPtr.Zero;
@@ -148,38 +171,85 @@ public class List<T> : IEnumerable<T>, IDisposable
148 } 171 }
149 172
150 private IntPtr InternalLast() 173 private IntPtr InternalLast()
151 { 174 => eina_list_last_custom_export_mono(Handle);
152 return eina_list_last_custom_export_mono(Handle);
153 }
154 175
155 private static IntPtr InternalNext(IntPtr list) 176 private static IntPtr InternalNext(IntPtr list)
177 => eina_list_next_custom_export_mono(list);
178
179 private static IntPtr InternalPrev(IntPtr list)
180 => eina_list_prev_custom_export_mono(list);
181
182 private static IntPtr InternalDataGet(IntPtr list)
183 => eina_list_data_get_custom_export_mono(list);
184
185 private static IntPtr InternalDataSet(IntPtr list, IntPtr data)
186 => eina_list_data_set_custom_export_mono(list, data);
187
188 private IntPtr GetNative(int idx, Func<IntPtr, uint, IntPtr> f)
156 { 189 {
157 return eina_list_next_custom_export_mono(list); 190 if (!(0 <= idx && idx < Count))
191 {
192 throw new ArgumentOutOfRangeException(nameof(idx), $"{nameof(idx)} cannot be negative, neither smaller than {nameof(Count)}");
193 }
194
195 var ele = f(Handle, (uint)idx);
196 if (ele == IntPtr.Zero)
197 {
198 throw new ArgumentOutOfRangeException(nameof(idx), $"There is no position {nameof(idx)}");
199 }
200
201 return ele;
158 } 202 }
159 203
160 private static IntPtr InternalPrev(IntPtr list) 204 private IntPtr GetNativeDataPointer(int idx)
205 => GetNative(idx, eina_list_nth);
206
207 private IntPtr GetNativePointer(int idx)
208 => GetNative(idx, eina_list_nth_list);
209
210 private void RequireWritable()
161 { 211 {
162 return eina_list_prev_custom_export_mono(list); 212 if (IsReadOnly)
213 {
214 throw new NotSupportedException("Cannot modify read-only container.");
215 }
163 } 216 }
164 217
165 private static IntPtr InternalDataGet(IntPtr list) 218 private void CheckOwnerships()
166 { 219 {
167 return eina_list_data_get_custom_export_mono(list); 220 if ((Own == false) && (OwnContent == true))
221 {
222 throw new InvalidOperationException(nameof(Own) + "/" + nameof(OwnContent));
223 }
168 } 224 }
169 225
170 private static IntPtr InternalDataSet(IntPtr list, IntPtr data) 226 private void DeleteData(IntPtr ele)
171 { 227 {
172 return eina_list_data_set_custom_export_mono(list, data); 228 if (OwnContent)
229 {
230 NativeFree<T>(InternalDataGet(ele));
231 }
173 } 232 }
174 233
234 private U LoopingThrough<U>(T val, Func<int, U> f1, Func<U> f2)
235 {
236 int i = 0;
237 IntPtr cur = Handle;
238 for (; cur != IntPtr.Zero; ++i, cur = InternalNext(cur))
239 {
240 if (NativeToManaged<T>(InternalDataGet(cur)).Equals(val))
241 {
242 return f1(i);
243 }
244 }
245
246 return f2();
247 }
175 248
176 /// <summary>Creates a new empty list. 249 /// <summary>Creates a new empty list.
177 /// <para>Since EFL 1.23.</para> 250 /// <para>Since EFL 1.23.</para>
178 /// </summary> 251 /// </summary>
179 public List() 252 public List() => InitNew();
180 {
181 InitNew();
182 }
183 253
184 /// <summary>Creates a new list wrapping the given handle.</summary> 254 /// <summary>Creates a new list wrapping the given handle.</summary>
185 [EditorBrowsable(EditorBrowsableState.Never)] 255 [EditorBrowsable(EditorBrowsableState.Never)]
@@ -188,6 +258,7 @@ public class List<T> : IEnumerable<T>, IDisposable
188 Handle = handle; 258 Handle = handle;
189 Own = own; 259 Own = own;
190 OwnContent = own; 260 OwnContent = own;
261 CheckOwnerships();
191 } 262 }
192 263
193 /// <summary>Creates a new list wrapping the given handle.</summary> 264 /// <summary>Creates a new list wrapping the given handle.</summary>
@@ -197,15 +268,13 @@ public class List<T> : IEnumerable<T>, IDisposable
197 Handle = handle; 268 Handle = handle;
198 Own = own; 269 Own = own;
199 OwnContent = ownContent; 270 OwnContent = ownContent;
271 CheckOwnerships();
200 } 272 }
201 273
202 /// <summary>Finalizes this list. 274 /// <summary>Finalizes this list.
203 /// <para>Since EFL 1.23.</para> 275 /// <para>Since EFL 1.23.</para>
204 /// </summary> 276 /// </summary>
205 ~List() 277 ~List() => Dispose(false);
206 {
207 Dispose(false);
208 }
209 278
210 /// <summary>Disposes of this list. 279 /// <summary>Disposes of this list.
211 /// <para>Since EFL 1.23.</para> 280 /// <para>Since EFL 1.23.</para>
@@ -221,12 +290,14 @@ public class List<T> : IEnumerable<T>, IDisposable
221 return; 290 return;
222 } 291 }
223 292
224 if (Own && OwnContent) 293 for (IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr))
225 { 294 {
226 for (IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr)) 295 if (!OwnContent)
227 { 296 {
228 NativeFree<T>(InternalDataGet(curr)); 297 break;
229 } 298 }
299
300 DeleteData(curr);
230 } 301 }
231 302
232 if (Own) 303 if (Own)
@@ -254,30 +325,17 @@ public class List<T> : IEnumerable<T>, IDisposable
254 /// <summary>Disposes of this list. 325 /// <summary>Disposes of this list.
255 /// <para>Since EFL 1.23.</para> 326 /// <para>Since EFL 1.23.</para>
256 /// </summary> 327 /// </summary>
257 public void Free() 328 public void Free() => Dispose();
258 {
259 Dispose();
260 }
261
262 /// <summary>Relinquishes of the native list.
263 /// <para>Since EFL 1.23.</para>
264 /// </summary>
265 /// <returns>The previously wrapped native list handle.</returns>
266 public IntPtr Release()
267 {
268 IntPtr h = Handle;
269 Handle = IntPtr.Zero;
270 return h;
271 }
272 329
273 /// <summary>Sets whether this wrapper should own the native list or not. 330 /// <summary>Sets whether this wrapper should own the native list or not.
274 /// <para>Since EFL 1.23.</para> 331 /// <para>Since EFL 1.23.</para>
275 /// </summary> 332 /// </summary>
276 /// <param name="ownAll">If the hash own for all ownerships.</param> 333 /// <param name="ownAll">If the hash own for all ownerships.</param>
277 public void SetOwnership(bool ownAll) 334 internal void SetOwnership(bool ownAll)
278 { 335 {
279 Own = ownAll; 336 Own = ownAll;
280 OwnContent = ownAll; 337 OwnContent = ownAll;
338 CheckOwnerships();
281 } 339 }
282 340
283 /// <summary>Sets whether this wrapper should own the native list and 341 /// <summary>Sets whether this wrapper should own the native list and
@@ -286,19 +344,11 @@ public class List<T> : IEnumerable<T>, IDisposable
286 /// </summary> 344 /// </summary>
287 /// <param name="own">If own the object.</param> 345 /// <param name="own">If own the object.</param>
288 /// <param name="ownContent">If own the content's object.</param> 346 /// <param name="ownContent">If own the content's object.</param>
289 public void SetOwnership(bool own, bool ownContent) 347 internal void SetOwnership(bool own, bool ownContent)
290 { 348 {
291 Own = own; 349 Own = own;
292 OwnContent = ownContent; 350 OwnContent = ownContent;
293 } 351 CheckOwnerships();
294
295 /// <summary>Returns the number of elements in this list.
296 /// <para>Since EFL 1.23.</para>
297 /// </summary>
298 /// <returns>The number of elements.</returns>
299 public int Count()
300 {
301 return (int)eina_list_count_custom_export_mono(Handle);
302 } 352 }
303 353
304 /// <summary>Appends <c>val</c> to the list. 354 /// <summary>Appends <c>val</c> to the list.
@@ -307,8 +357,9 @@ public class List<T> : IEnumerable<T>, IDisposable
307 /// <param name="val">The item to be appended.</param> 357 /// <param name="val">The item to be appended.</param>
308 public void Append(T val) 358 public void Append(T val)
309 { 359 {
310 IntPtr ele = ManagedToNativeAlloc(val); 360 RequireWritable();
311 Handle = eina_list_append(Handle, ele); 361
362 Handle = eina_list_append(Handle, ManagedToNativeAlloc(val));
312 } 363 }
313 364
314 /// <summary>Prepends <c>val</c> to the list. 365 /// <summary>Prepends <c>val</c> to the list.
@@ -317,8 +368,9 @@ public class List<T> : IEnumerable<T>, IDisposable
317 /// <param name="val">The item to be prepended.</param> 368 /// <param name="val">The item to be prepended.</param>
318 public void Prepend(T val) 369 public void Prepend(T val)
319 { 370 {
320 IntPtr ele = ManagedToNativeAlloc(val); 371 RequireWritable();
321 Handle = eina_list_prepend(Handle, ele); 372
373 Handle = eina_list_prepend(Handle, ManagedToNativeAlloc(val));
322 } 374 }
323 375
324 /// <summary>Inserts <c>val</c> in the list in a sorted manner. 376 /// <summary>Inserts <c>val</c> in the list in a sorted manner.
@@ -328,8 +380,11 @@ public class List<T> : IEnumerable<T>, IDisposable
328 /// <param name="val">The item to be inserted.</param> 380 /// <param name="val">The item to be inserted.</param>
329 public void SortedInsert(T val) 381 public void SortedInsert(T val)
330 { 382 {
331 IntPtr ele = ManagedToNativeAlloc(val); 383 RequireWritable();
332 Handle = eina_list_sorted_insert(Handle, EinaCompareCb<T>(), ele); 384
385 Handle = eina_list_sorted_insert(Handle,
386 EinaCompareCb<T>(),
387 ManagedToNativeAlloc(val));
333 } 388 }
334 389
335 /// <summary>Inserts <c>val</c> in the list in a sorted manner with the 390 /// <summary>Inserts <c>val</c> in the list in a sorted manner with the
@@ -341,8 +396,11 @@ public class List<T> : IEnumerable<T>, IDisposable
341 /// <param name="val">The item to be inserted.</param> 396 /// <param name="val">The item to be inserted.</param>
342 public void SortedInsert(Compare compareCb, T val) 397 public void SortedInsert(Compare compareCb, T val)
343 { 398 {
344 IntPtr ele = ManagedToNativeAlloc(val); 399 RequireWritable();
345 Handle = eina_list_sorted_insert(Handle, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)), ele); 400
401 Handle = eina_list_sorted_insert(Handle,
402 Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)),
403 ManagedToNativeAlloc(val));
346 } 404 }
347 405
348 /// <summary>Sorts <c>limit</c> elements in this list inplace. 406 /// <summary>Sorts <c>limit</c> elements in this list inplace.
@@ -351,6 +409,8 @@ public class List<T> : IEnumerable<T>, IDisposable
351 /// <param name="limit">The max number of elements to be sorted.</param> 409 /// <param name="limit">The max number of elements to be sorted.</param>
352 public void Sort(int limit = 0) 410 public void Sort(int limit = 0)
353 { 411 {
412 RequireWritable();
413
354 Handle = eina_list_sort(Handle, (uint)limit, EinaCompareCb<T>()); 414 Handle = eina_list_sort(Handle, (uint)limit, EinaCompareCb<T>());
355 } 415 }
356 416
@@ -360,7 +420,10 @@ public class List<T> : IEnumerable<T>, IDisposable
360 /// <param name="compareCb">The function to compare two elements of the list.</param> 420 /// <param name="compareCb">The function to compare two elements of the list.</param>
361 public void Sort(Compare compareCb) 421 public void Sort(Compare compareCb)
362 { 422 {
363 Handle = eina_list_sort(Handle, 0, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb))); 423 RequireWritable();
424
425 Handle = eina_list_sort(Handle, (uint)0,
426 Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)));
364 } 427 }
365 428
366 /// <summary>Sorts <c>limit</c> elements in this list inplace. 429 /// <summary>Sorts <c>limit</c> elements in this list inplace.
@@ -370,15 +433,16 @@ public class List<T> : IEnumerable<T>, IDisposable
370 /// <param name="compareCb">The function to compare two elements of the list.</param> 433 /// <param name="compareCb">The function to compare two elements of the list.</param>
371 public void Sort(int limit, Compare compareCb) 434 public void Sort(int limit, Compare compareCb)
372 { 435 {
373 Handle = eina_list_sort(Handle, (uint)limit, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb))); 436 RequireWritable();
437
438 Handle = eina_list_sort(Handle, (uint)limit,
439 Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)));
374 } 440 }
375 441
376 private Eina.Callbacks.EinaCompareCb GetNativeCompareCb(Compare managedCb) 442 private Eina.Callbacks.EinaCompareCb GetNativeCompareCb(Compare managedCb)
377 { 443 => (IntPtr a, IntPtr b)
378 return (IntPtr a, IntPtr b) => { 444 => managedCb(NativeToManaged<T>(a), NativeToManaged<T>(b));
379 return managedCb(NativeToManaged<T>(a), NativeToManaged<T>(b)); 445
380 };
381 }
382 446
383 /// <summary>Returns the <c>n</c>th element of this list. Due to marshalling details, the returned element 447 /// <summary>Returns the <c>n</c>th element of this list. Due to marshalling details, the returned element
384 /// may be a different C# object from the one you used to append. 448 /// may be a different C# object from the one you used to append.
@@ -386,33 +450,20 @@ public class List<T> : IEnumerable<T>, IDisposable
386 /// </summary> 450 /// </summary>
387 /// <param name="n">The 0-based index to be retrieved.</param> 451 /// <param name="n">The 0-based index to be retrieved.</param>
388 /// <returns>The value in the specified element.</returns> 452 /// <returns>The value in the specified element.</returns>
389 public T Nth(int n) 453 public T Nth(int n) => NativeToManaged<T>(GetNativeDataPointer(n));
390 {
391 // TODO: check bounds ???
392 IntPtr ele = eina_list_nth(Handle, (uint)n);
393 return NativeToManaged<T>(ele);
394 }
395 454
396 /// <summary>Sets the data at the <c>idx</c> position. 455 /// <summary>Sets the data at the <c>idx</c> position.
397 /// <para>Since EFL 1.23.</para> 456 /// <para>Since EFL 1.23.</para>
398 /// </summary> 457 /// </summary>
399 /// <param name="idx">The 0-based index to be set.</param> 458 /// <param name="idx">The 0-based index to be set.</param>
400 /// <param name="val">The value to be inserted.</param> 459 /// <param name="val">The value to be inserted.</param>
401 public void DataSet(int idx, T val) 460 internal void DataSet(int idx, T val)
402 { 461 {
403 IntPtr pos = eina_list_nth_list(Handle, (uint)idx); 462 RequireWritable();
404 if (pos == IntPtr.Zero)
405 {
406 throw new IndexOutOfRangeException();
407 }
408 463
409 if (OwnContent) 464 IntPtr pos = GetNativePointer(idx);
410 { 465 DeleteData(pos);
411 NativeFree<T>(InternalDataGet(pos)); 466 InternalDataSet(pos, ManagedToNativeAlloc(val));
412 }
413
414 IntPtr ele = ManagedToNativeAlloc(val);
415 InternalDataSet(pos, ele);
416 } 467 }
417 468
418 /// <summary>Accessor for the data at the <c>idx</c> position. 469 /// <summary>Accessor for the data at the <c>idx</c> position.
@@ -436,10 +487,7 @@ public class List<T> : IEnumerable<T>, IDisposable
436 /// </summary> 487 /// </summary>
437 /// <returns>The value contained in the last list position.</returns> 488 /// <returns>The value contained in the last list position.</returns>
438 public T LastDataGet() 489 public T LastDataGet()
439 { 490 => NativeToManaged<T>(eina_list_last_data_get_custom_export_mono(Handle));
440 IntPtr ele = eina_list_last_data_get_custom_export_mono(Handle);
441 return NativeToManaged<T>(ele);
442 }
443 491
444 /// <summary>Reverses this list in place. 492 /// <summary>Reverses this list in place.
445 /// <para>Since EFL 1.23.</para> 493 /// <para>Since EFL 1.23.</para>
@@ -447,6 +495,8 @@ public class List<T> : IEnumerable<T>, IDisposable
447 /// <returns>A reference to this object.</returns> 495 /// <returns>A reference to this object.</returns>
448 public List<T> Reverse() 496 public List<T> Reverse()
449 { 497 {
498 RequireWritable();
499
450 Handle = eina_list_reverse(Handle); 500 Handle = eina_list_reverse(Handle);
451 return this; 501 return this;
452 } 502 }
@@ -456,6 +506,8 @@ public class List<T> : IEnumerable<T>, IDisposable
456 /// </summary> 506 /// </summary>
457 public void Shuffle() 507 public void Shuffle()
458 { 508 {
509 RequireWritable();
510
459 Handle = eina_list_shuffle(Handle, IntPtr.Zero); 511 Handle = eina_list_shuffle(Handle, IntPtr.Zero);
460 } 512 }
461 513
@@ -465,9 +517,10 @@ public class List<T> : IEnumerable<T>, IDisposable
465 /// <returns>A managed array of the elements.</returns> 517 /// <returns>A managed array of the elements.</returns>
466 public T[] ToArray() 518 public T[] ToArray()
467 { 519 {
468 var managed = new T[Count()]; 520 var managed = new T[Count];
469 int i = 0; 521 int i = 0;
470 for (IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr), ++i) 522 for (IntPtr curr = Handle; curr != IntPtr.Zero;
523 curr = InternalNext(curr), ++i)
471 { 524 {
472 managed[i] = NativeToManaged<T>(InternalDataGet(curr)); 525 managed[i] = NativeToManaged<T>(InternalDataGet(curr));
473 } 526 }
@@ -479,8 +532,11 @@ public class List<T> : IEnumerable<T>, IDisposable
479 /// <para>Since EFL 1.23.</para> 532 /// <para>Since EFL 1.23.</para>
480 /// </summary> 533 /// </summary>
481 /// <param name="values">The values to be appended.</param> 534 /// <param name="values">The values to be appended.</param>
482 public void AppendArray(T[] values) 535 public void Append(T[] values)
483 { 536 {
537 Contract.Requires(values != null, nameof(values));
538 RequireWritable();
539
484 foreach (T v in values) 540 foreach (T v in values)
485 { 541 {
486 Append(v); 542 Append(v);
@@ -493,18 +549,14 @@ public class List<T> : IEnumerable<T>, IDisposable
493 /// </summary> 549 /// </summary>
494 /// <returns>The iterator.</returns> 550 /// <returns>The iterator.</returns>
495 public Eina.Iterator<T> GetIterator() 551 public Eina.Iterator<T> GetIterator()
496 { 552 => new Eina.Iterator<T>(eina_list_iterator_new(Handle), true);
497 return new Eina.Iterator<T>(eina_list_iterator_new(Handle), true);
498 }
499 553
500 /// <summary>Gets an iterator that iterates this list in reverse order. 554 /// <summary>Gets an iterator that iterates this list in reverse order.
501 /// <para>Since EFL 1.23.</para> 555 /// <para>Since EFL 1.23.</para>
502 /// </summary> 556 /// </summary>
503 /// <returns>The iterator.</returns> 557 /// <returns>The iterator.</returns>
504 public Eina.Iterator<T> GetReversedIterator() 558 public Eina.Iterator<T> GetReversedIterator()
505 { 559 => new Eina.Iterator<T>(eina_list_iterator_reversed_new(Handle), true);
506 return new Eina.Iterator<T>(eina_list_iterator_reversed_new(Handle), true);
507 }
508 560
509 /// <summary>Gets an enumerator into this list. 561 /// <summary>Gets an enumerator into this list.
510 /// <para>Since EFL 1.23.</para> 562 /// <para>Since EFL 1.23.</para>
@@ -523,18 +575,136 @@ public class List<T> : IEnumerable<T>, IDisposable
523 /// </summary> 575 /// </summary>
524 /// <returns>The enumerator.</returns> 576 /// <returns>The enumerator.</returns>
525 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 577 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
526 { 578 => this.GetEnumerator();
527 return this.GetEnumerator();
528 }
529 579
530 /// <summary> Gets an Accessor for this List. 580 /// <summary> Gets an Accessor for this List.
531 /// <para>Since EFL 1.23.</para> 581 /// <para>Since EFL 1.23.</para>
532 /// </summary> 582 /// </summary>
533 /// <returns>The accessor.</returns> 583 /// <returns>The accessor.</returns>
534 public Eina.Accessor<T> GetAccessor() 584 public Eina.Accessor<T> GetAccessor()
585 => new Eina.Accessor<T>(eina_list_accessor_new(Handle),
586 Ownership.Managed);
587
588 /// <summary>
589 /// Removes the first occurrence of a specific object.
590 /// <para>Since EFL 1.24.</para>
591 /// </summary>
592 /// <param name="val">The object to remove.</param>
593 public bool Remove(T val)
535 { 594 {
536 return new Eina.Accessor<T>(eina_list_accessor_new(Handle), Ownership.Managed); 595 RequireWritable();
596
597 var prev_count = Count;
598 var deleted = LoopingThrough(val,
599 (i) =>
600 {
601 RemoveAt(i);
602 return true;
603 },
604 () => false);
605
606 return deleted && (prev_count - 1 == Count);
537 } 607 }
608
609 /// <summary>
610 /// Adds an item.
611 /// <para>Since EFL 1.24.</para>
612 /// </summary>
613 /// <param name="val">The object to add.</param>
614 public void Add(T val) => Append(val);
615
616 /// <summary>
617 /// Removes all items.
618 /// <para>Since EFL 1.24.</para>
619 /// </summary>
620 public void Clear()
621 {
622 RequireWritable();
623
624 for (; Handle != IntPtr.Zero;)
625 {
626 Handle = eina_list_remove_list(Handle, Handle);
627 }
628 }
629
630 /// <summary>
631 /// Determines whether the <see cref="List{T}" /> contains a specific value.
632 /// <para>Since EFL 1.24.</para>
633 /// </summary>
634 /// <param name="val">The object to locate.</param>
635 public bool Contains(T val)
636 => LoopingThrough(val, (i) => true, () => false);
637
638 /// <summary>
639 /// Determines the index of a specific item.
640 /// <para>Since EFL 1.24.</para>
641 /// </summary>
642 /// <param name="val">The object to locate.</param>
643 public int IndexOf(T val)
644 => LoopingThrough(val, (i) => i, () => -1);
645
646 /// <summary>
647 /// Inserts an item to the <see cref="List{T}" /> at the specified index.
648 /// <para>Since EFL 1.24.</para>
649 /// </summary>
650 /// <param name="idx">The zero-based index at which item should be inserted.</param>
651 /// <param name="val">The object to insert.</param>
652 public void Insert(int idx, T val)
653 {
654 RequireWritable();
655
656 if (idx == 0)
657 {
658 Prepend(val);
659 return;
660 }
661
662 if (idx == Count)
663 {
664 Append(val);
665 return;
666 }
667
668 if (idx < 0)
669 {
670 throw new ArgumentOutOfRangeException(nameof(idx), $"{nameof(idx)} cannot be negative.");
671 }
672
673 if (Count < idx)
674 {
675 throw new ArgumentOutOfRangeException(nameof(idx), $"{nameof(idx)} cannot be greater than {nameof(Count)} + 1.");
676 }
677
678 Handle = eina_list_prepend_relative_list(Handle, ManagedToNativeAlloc(val),
679 GetNativePointer(idx));
680 }
681
682 /// <summary>
683 /// Removes the <see cref="List{T}" /> item at the specified index.
684 /// <para>Since EFL 1.24.</para>
685 /// </summary>
686 /// <param name="idx">The zero-based index of the item to remove.</param>
687 public void RemoveAt(int idx)
688 {
689 RequireWritable();
690
691 var ele = GetNativePointer(idx);
692 DeleteData(ele);
693 Handle = eina_list_remove_list(Handle, ele);
694 }
695
696 /// <summary>
697 /// Copies the elements of the <see cref="List{T}" /> to an
698 /// <see cref="Array" />, starting at a particular <see cref="Array" /> index.
699 /// <para>Since EFL 1.24.</para>
700 /// </summary>
701 /// <param name="array">The one-dimensional <see cref="Array" /> that is the
702 /// destination of the elements copied from <see cref="List{T}" />.
703 /// The <see cref="Array" /> must have zero-based indexing.</param>
704 /// <param name="arrayIndex">The zero-based index in array at which copying
705 /// begins.</param>
706 public void CopyTo(T[] array, int arrayIndex)
707 => ToArray().CopyTo(array, arrayIndex);
538} 708}
539 709
540} 710}
diff --git a/src/bindings/mono/eina_mono/eina_log.cs b/src/bindings/mono/eina_mono/eina_log.cs
index 4d67bbb..2174c65 100644
--- a/src/bindings/mono/eina_mono/eina_log.cs
+++ b/src/bindings/mono/eina_mono/eina_log.cs
@@ -1,3 +1,18 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
@@ -64,7 +79,7 @@ public static class Log
64 /// <summary>The colors to be used by the logging system. 79 /// <summary>The colors to be used by the logging system.
65 /// <para>Since EFL 1.23.</para> 80 /// <para>Since EFL 1.23.</para>
66 /// </summary> 81 /// </summary>
67 public static class Color 82 internal static class Color
68 { 83 {
69 /// <summary>Light red 84 /// <summary>Light red
70 /// <para>Since EFL 1.23.</para> 85 /// <para>Since EFL 1.23.</para>
@@ -124,7 +139,7 @@ public static class Log
124 static Log() 139 static Log()
125 { 140 {
126 const String name = "mono"; 141 const String name = "mono";
127 const String color = "\033[32;1m"; 142 const String color = Color.GREEN;
128 143
129 // Maybe move this check outside when other eina stuff get support? 144 // Maybe move this check outside when other eina stuff get support?
130 domain = eina_log_domain_register(name, color); 145 domain = eina_log_domain_register(name, color);
diff --git a/src/bindings/mono/eina_mono/eina_promises.cs b/src/bindings/mono/eina_mono/eina_promises.cs
index a2cef0d..9f725ad 100644
--- a/src/bindings/mono/eina_mono/eina_promises.cs
+++ b/src/bindings/mono/eina_mono/eina_promises.cs
@@ -1,9 +1,24 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1using System; 16using System;
2using System.Runtime.InteropServices; 17using System.Runtime.InteropServices;
3using System.Collections.Generic; 18using System.Collections.Generic;
4using System.Linq; 19using System.Linq;
5using System.ComponentModel; 20using System.ComponentModel;
6 21using System.Diagnostics.Contracts;
7 22
8using static Eina.EinaNative.PromiseNativeMethods; 23using static Eina.EinaNative.PromiseNativeMethods;
9 24
@@ -192,6 +207,7 @@ public class Promise : IDisposable
192 /// </summary> 207 /// </summary>
193 public void Resolve(Eina.Value value) 208 public void Resolve(Eina.Value value)
194 { 209 {
210 Contract.Requires(value != null, nameof(value));
195 SanityChecks(); 211 SanityChecks();
196 eina_promise_resolve(this.Handle, value); 212 eina_promise_resolve(this.Handle, value);
197 // Promise will take care of releasing this value correctly. 213 // Promise will take care of releasing this value correctly.
@@ -265,6 +281,7 @@ public class Future
265 /// <param name="cb">The callback to be called when the attached promise resolves.</param> 281 /// <param name="cb">The callback to be called when the attached promise resolves.</param>
266 public Future(Promise promise, ResolvedCb cb = null) 282 public Future(Promise promise, ResolvedCb cb = null)
267 { 283 {
284 Contract.Requires(promise != null, nameof(promise));
268 IntPtr intermediate = eina_future_new(promise.Handle); 285 IntPtr intermediate = eina_future_new(promise.Handle);
269 Handle = ThenRaw(intermediate, (Eina.Value value) => 286 Handle = ThenRaw(intermediate, (Eina.Value value) =>
270 { 287 {
@@ -365,11 +382,11 @@ public class Future
365 { 382 {
366 SanityChecks(); 383 SanityChecks();
367 System.Collections.Generic.IList<ResolvedCb> cbsList = cbs.ToList(); 384 System.Collections.Generic.IList<ResolvedCb> cbsList = cbs.ToList();
368 FutureDesc[] descs = new FutureDesc[cbsList.Count() + 1]; // +1 due to the null-cb terminating descriptor. 385 FutureDesc[] descs = new FutureDesc[cbsList.Count + 1]; // +1 due to the null-cb terminating descriptor.
369 int i = 0; 386 int i = 0;
370 try 387 try
371 { 388 {
372 for (; i < cbsList.Count(); i++) 389 for (; i < cbsList.Count; i++)
373 { 390 {
374 ResolvedCb cb = cbsList[i]; 391 ResolvedCb cb = cbsList[i];
375 descs[i].cb = NativeResolvedCbDelegate; 392 descs[i].cb = NativeResolvedCbDelegate;
diff --git a/src/bindings/mono/eina_mono/eina_slice.cs b/src/bindings/mono/eina_mono/eina_slice.cs
index 20bd81f..0b9311e 100644
--- a/src/bindings/mono/eina_mono/eina_slice.cs
+++ b/src/bindings/mono/eina_mono/eina_slice.cs
@@ -1,8 +1,24 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.ComponentModel; 20using System.ComponentModel;
21using System.Diagnostics.Contracts;
6 22
7namespace Eina 23namespace Eina
8{ 24{
@@ -34,10 +50,10 @@ public interface ISliceBase
34 50
35/// <summary>Pointer to a slice of native memory. 51/// <summary>Pointer to a slice of native memory.
36/// 52///
37/// Since EFL 1.23. 53/// <para>Since EFL 1.23.</para>
38/// </summary> 54/// </summary>
39[StructLayout(LayoutKind.Sequential)] 55[StructLayout(LayoutKind.Sequential)]
40public struct Slice : ISliceBase 56public struct Slice : ISliceBase, IEquatable<Slice>
41{ 57{
42 /// <summary> 58 /// <summary>
43 /// The length of this slice. 59 /// The length of this slice.
@@ -72,14 +88,57 @@ public struct Slice : ISliceBase
72 Mem = mem; 88 Mem = mem;
73 Len = len; 89 Len = len;
74 } 90 }
91
92 /// <summary>
93 /// Gets a hash for <see cref="Slice" />.
94 /// <para>Since EFL 1.24.</para>
95 /// </summary>
96 /// <returns>A hash code.</returns>
97 public override int GetHashCode() => Length.GetHashCode() ^ Mem.GetHashCode();
98
99 /// <summary>Returns whether this <see cref="Slice" />
100 /// is equal to the given <see cref="object" />.
101 /// <para>Since EFL 1.24.</para>
102 /// </summary>
103 /// <param name="other">The <see cref="object" /> to be compared to.</param>
104 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
105 public override bool Equals(object other)
106 => (!(other is Slice)) ? false : Equals((Slice)other);
107
108 /// <summary>Returns whether this <see cref="Slice" /> is equal
109 /// to the given <see cref="Slice" />.
110 /// <para>Since EFL 1.24.</para>
111 /// </summary>
112 /// <param name="other">The <see cref="Slice" /> to be compared to.</param>
113 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
114 public bool Equals(Slice other)
115 => (Length == other.Length) ^ (Mem == other.Mem);
116
117 /// <summary>Returns whether <c>lhs</c> is equal to <c>rhs</c>.
118 /// <para>Since EFL 1.24.</para>
119 /// </summary>
120 /// <param name="lhs">The left hand side of the operator.</param>
121 /// <param name="rhs">The right hand side of the operator.</param>
122 /// <returns><c>true</c> if <c>lhs</c> is equal
123 /// to <c>rhs</c>.</returns>
124 public static bool operator==(Slice lhs, Slice rhs) => lhs.Equals(rhs);
125
126 /// <summary>Returns whether <c>lhs</c> is not equal to <c>rhs</c>.
127 /// <para>Since EFL 1.24.</para>
128 /// </summary>
129 /// <param name="lhs">The left hand side of the operator.</param>
130 /// <param name="rhs">The right hand side of the operator.</param>
131 /// <returns><c>true</c> if <c>lhs</c> is not equal
132 /// to <c>rhs</c>.</returns>
133 public static bool operator!=(Slice lhs, Slice rhs) => !(lhs == rhs);
75} 134}
76 135
77/// <summary>Pointer to a slice of native memory. 136/// <summary>Pointer to a slice of native memory.
78/// 137///
79/// Since EFL 1.23. 138/// <para>Since EFL 1.23.</para>
80/// </summary> 139/// </summary>
81[StructLayout(LayoutKind.Sequential)] 140[StructLayout(LayoutKind.Sequential)]
82public struct RwSlice : ISliceBase 141public struct RwSlice : ISliceBase, IEquatable<RwSlice>
83{ 142{
84 /// <summary> 143 /// <summary>
85 /// The length of this slice. 144 /// The length of this slice.
@@ -126,17 +185,64 @@ public struct RwSlice : ISliceBase
126 r.Len = Len; 185 r.Len = Len;
127 return r; 186 return r;
128 } 187 }
188
189 /// <summary>
190 /// Gets a hash for <see cref="RwSlice" />.
191 /// <para>Since EFL 1.24.</para>
192 /// </summary>
193 /// <returns>A hash code.</returns>
194 public override int GetHashCode() => Mem.GetHashCode() ^ Length.GetHashCode();
195
196 /// <summary>Returns whether this <see cref="RwSlice" />
197 /// is equal to the given <see cref="object" />.
198 /// <para>Since EFL 1.24.</para>
199 /// </summary>
200 /// <param name="other">The <see cref="object" /> to be compared to.</param>
201 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
202 public override bool Equals(object other)
203 => (!(other is RwSlice)) ? false : Equals((RwSlice)other);
204
205 /// <summary>Returns whether this <see cref="RwSlice" /> is equal
206 /// to the given <see cref="RwSlice" />.
207 /// <para>Since EFL 1.24.</para>
208 /// </summary>
209 /// <param name="other">The <see cref="RwSlice" /> to be compared to.</param>
210 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
211 public bool Equals(RwSlice other)
212 => (Length == other.Length) && (Mem == other.Mem);
213
214 /// <summary>Returns whether <c>lhs</c> is equal to <c>rhs</c>.
215 /// <para>Since EFL 1.24.</para>
216 /// </summary>
217 /// <param name="lhs">The left hand side of the operator.</param>
218 /// <param name="rhs">The right hand side of the operator.</param>
219 /// <returns><c>true</c> if <c>lhs</c> is equal
220 /// to <c>rhs</c>.</returns>
221 public static bool operator==(RwSlice lhs, RwSlice rhs) => lhs.Equals(rhs);
222
223 /// <summary>Returns whether <c>lhs</c> is not equal to <c>rhs</c>.
224 /// <para>Since EFL 1.24.</para>
225 /// </summary>
226 /// <param name="lhs">The left hand side of the operator.</param>
227 /// <param name="rhs">The right hand side of the operator.</param>
228 /// <returns><c>true</c> if <c>lhs</c> is not equal
229 /// to <c>rhs</c>.</returns>
230 public static bool operator!=(RwSlice lhs, RwSlice rhs) => !(lhs == rhs);
129} 231}
130 232
131} 233}
132 234
133public static class Eina_SliceUtils 235namespace Eina
236{
237public static class SliceExtensions
134{ 238{
135 public static byte[] GetBytes(this Eina.ISliceBase slc) 239 public static byte[] GetBytes(this Eina.ISliceBase slc)
136 { 240 {
241 Contract.Requires(slc != null, nameof(slc));
137 var size = (int)(slc.Len); 242 var size = (int)(slc.Len);
138 byte[] mArray = new byte[size]; 243 byte[] mArray = new byte[size];
139 Marshal.Copy(slc.Mem, mArray, 0, size); 244 Marshal.Copy(slc.Mem, mArray, 0, size);
140 return mArray; 245 return mArray;
141 } 246 }
142} 247}
248}
diff --git a/src/bindings/mono/eina_mono/eina_strbuf.cs b/src/bindings/mono/eina_mono/eina_strbuf.cs
index e4b6ab1..bdde9a9 100644
--- a/src/bindings/mono/eina_mono/eina_strbuf.cs
+++ b/src/bindings/mono/eina_mono/eina_strbuf.cs
@@ -1,3 +1,18 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1using System; 16using System;
2using System.Runtime.InteropServices; 17using System.Runtime.InteropServices;
3using System.ComponentModel; 18using System.ComponentModel;
@@ -238,11 +253,6 @@ public class Strbuf : IDisposable
238 /// <returns>A string with the contents of this buffer.</returns> 253 /// <returns>A string with the contents of this buffer.</returns>
239 public override string ToString() 254 public override string ToString()
240 { 255 {
241 if (Disposed)
242 {
243 throw new ObjectDisposedException(base.GetType().Name);
244 }
245
246 return eina_strbuf_string_get(this.Handle); 256 return eina_strbuf_string_get(this.Handle);
247 } 257 }
248} 258}
diff --git a/src/bindings/mono/eina_mono/eina_stringshare.cs b/src/bindings/mono/eina_mono/eina_stringshare.cs
index 5944904..58656fe 100644
--- a/src/bindings/mono/eina_mono/eina_stringshare.cs
+++ b/src/bindings/mono/eina_mono/eina_stringshare.cs
@@ -1,3 +1,18 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
@@ -10,7 +25,7 @@ namespace Eina
10 25
11// TODO: move all native functions to a "NativeMethods" class 26// TODO: move all native functions to a "NativeMethods" class
12[EditorBrowsable(EditorBrowsableState.Never)] 27[EditorBrowsable(EditorBrowsableState.Never)]
13public static partial class NativeMethods 28internal static partial class NativeMethods
14{ 29{
15 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 30 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
16 eina_stringshare_add(IntPtr str); 31 eina_stringshare_add(IntPtr str);
@@ -125,6 +140,17 @@ public class Stringshare : IEquatable<Stringshare>, IEquatable<string>
125 } 140 }
126 141
127 /// <summary> 142 /// <summary>
143 /// Conversion from string to Stringshare.
144 /// <para>Since EFL 1.24.</para>
145 /// </summary>
146 /// <remarks>
147 /// Note that this method can be used to create an instance of this class,
148 /// either via an explicit cast or an implicit convertion.
149 /// <seealso cref="Create(string)"/>
150 /// </remarks>
151 public static Stringshare FromString(string s) => s;
152
153 /// <summary>
128 /// Check two Stringshare objects for equality. 154 /// Check two Stringshare objects for equality.
129 /// <para>Since EFL 1.23.</para> 155 /// <para>Since EFL 1.23.</para>
130 /// </summary> 156 /// </summary>
@@ -172,7 +198,7 @@ public class Stringshare : IEquatable<Stringshare>, IEquatable<string>
172 /// </returns> 198 /// </returns>
173 public override int GetHashCode() 199 public override int GetHashCode()
174 { 200 {
175 return Str.GetHashCode(); 201 return Str.GetHashCode(StringComparison.Ordinal);
176 } 202 }
177 203
178 /// <summary> 204 /// <summary>
diff --git a/src/bindings/mono/eina_mono/eina_value.cs b/src/bindings/mono/eina_mono/eina_value.cs
index d70d9e6..46d1ff0 100644
--- a/src/bindings/mono/eina_mono/eina_value.cs
+++ b/src/bindings/mono/eina_mono/eina_value.cs
@@ -1,3 +1,18 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3#define CODE_ANALYSIS 18#define CODE_ANALYSIS
@@ -11,6 +26,8 @@ using System.Security.Permissions;
11using System.Security; 26using System.Security;
12using System.Diagnostics.CodeAnalysis; 27using System.Diagnostics.CodeAnalysis;
13using System.Runtime.Serialization; 28using System.Runtime.Serialization;
29using System.Globalization;
30using System.Diagnostics.Contracts;
14 31
15using static Eina.EinaNative.UnsafeNativeMethods; 32using static Eina.EinaNative.UnsafeNativeMethods;
16using static Eina.TraitFunctions; 33using static Eina.TraitFunctions;
@@ -547,7 +564,7 @@ static internal class UnsafeNativeMethods
547/// </summary> 564/// </summary>
548[StructLayout(LayoutKind.Sequential)] 565[StructLayout(LayoutKind.Sequential)]
549[EditorBrowsable(EditorBrowsableState.Never)] 566[EditorBrowsable(EditorBrowsableState.Never)]
550public struct ValueNative 567public struct ValueNative : IEquatable<ValueNative>
551{ 568{
552 public IntPtr Type; 569 public IntPtr Type;
553 public IntPtr Value; // Actually an Eina_Value_Union, but it is padded to 8 bytes. 570 public IntPtr Value; // Actually an Eina_Value_Union, but it is padded to 8 bytes.
@@ -556,6 +573,49 @@ public struct ValueNative
556 { 573 {
557 return $"ValueNative<Type:0x{Type.ToInt64():x}, Value:0x{Value.ToInt64():x}>"; 574 return $"ValueNative<Type:0x{Type.ToInt64():x}, Value:0x{Value.ToInt64():x}>";
558 } 575 }
576
577 /// <summary>
578 /// Gets a hash for <see cref="ValueNative" />.
579 /// <para>Since EFL 1.24.</para>
580 /// </summary>
581 /// <returns>A hash code.</returns>
582 public override int GetHashCode() => Type.GetHashCode() ^ Value.GetHashCode();
583
584 /// <summary>Returns whether this <see cref="ValueNative" />
585 /// is equal to the given <see cref="object" />.
586 /// <para>Since EFL 1.24.</para>
587 /// </summary>
588 /// <param name="other">The <see cref="object" /> to be compared to.</param>
589 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
590 public override bool Equals(object other)
591 => (!(other is ValueNative)) ? false : Equals((ValueNative)other);
592
593 /// <summary>Returns whether this <see cref="ValueNative" /> is equal
594 /// to the given <see cref="ValueNative" />.
595 /// <para>Since EFL 1.24.</para>
596 /// </summary>
597 /// <param name="other">The <see cref="ValueNative" /> to be compared to.</param>
598 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
599 public bool Equals(ValueNative other)
600 => (Type == other.Type) ^ (Value == other.Value);
601
602 /// <summary>Returns whether <c>lhs</c> is equal to <c>rhs</c>.
603 /// <para>Since EFL 1.24.</para>
604 /// </summary>
605 /// <param name="lhs">The left hand side of the operator.</param>
606 /// <param name="rhs">The right hand side of the operator.</param>
607 /// <returns><c>true</c> if <c>lhs</c> is equal
608 /// to <c>rhs</c>.</returns>
609 public static bool operator==(ValueNative lhs, ValueNative rhs) => lhs.Equals(rhs);
610
611 /// <summary>Returns whether <c>lhs</c> is not equal to <c>rhs</c>.
612 /// <para>Since EFL 1.24.</para>
613 /// </summary>
614 /// <param name="lhs">The left hand side of the operator.</param>
615 /// <param name="rhs">The right hand side of the operator.</param>
616 /// <returns><c>true</c> if <c>lhs</c> is not equal
617 /// to <c>rhs</c>.</returns>
618 public static bool operator!=(ValueNative lhs, ValueNative rhs) => !(lhs == rhs);
559} 619}
560 620
561/// <summary>Exception for failures when setting an container item. 621/// <summary>Exception for failures when setting an container item.
@@ -868,7 +928,7 @@ static class ValueTypeMethods
868/// marshall_type_impl.hh in the generator). User-facing API still uses Eina.ValueType 928/// marshall_type_impl.hh in the generator). User-facing API still uses Eina.ValueType
869/// normally.</para> 929/// normally.</para>
870/// 930///
871/// Since EFL 1.23. 931/// <para>Since EFL 1.23.</para>
872/// </summary> 932/// </summary>
873[EditorBrowsable(EditorBrowsableState.Never)] 933[EditorBrowsable(EditorBrowsableState.Never)]
874public class ValueTypeBox 934public class ValueTypeBox
@@ -881,11 +941,15 @@ public class ValueTypeBox
881 } 941 }
882 942
883 public static implicit operator ValueTypeBox(ValueType v) 943 public static implicit operator ValueTypeBox(ValueType v)
884 { 944 => FromValueType(v);
885 return new ValueTypeBox(v); 945
886 } 946 public static ValueTypeBox FromValueType(ValueType v)
947 => new ValueTypeBox(v);
887 948
888 public static implicit operator ValueType(ValueTypeBox box) 949 public static implicit operator ValueType(ValueTypeBox box)
950 => ToValueType(box);
951
952 public static ValueType ToValueType(ValueTypeBox box)
889 { 953 {
890 if (box == null) 954 if (box == null)
891 { 955 {
@@ -1205,8 +1269,10 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1205 /// <para>Since EFL 1.23.</para> 1269 /// <para>Since EFL 1.23.</para>
1206 /// </summary> 1270 /// </summary>
1207 /// <param name="obj">The object to be wrapped.</param> 1271 /// <param name="obj">The object to be wrapped.</param>
1272 [SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", Justification="Could not remove warning!")]
1208 public Value(object obj) : this() 1273 public Value(object obj) : this()
1209 { 1274 {
1275 Contract.Requires(obj != null, nameof(obj));
1210 var objType = obj.GetType(); 1276 var objType = obj.GetType();
1211 1277
1212 if (objType == typeof(sbyte)) 1278 if (objType == typeof(sbyte))
@@ -1278,7 +1344,7 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1278 } 1344 }
1279 1345
1280 Type[] genericArguments = objType.GetGenericArguments(); 1346 Type[] genericArguments = objType.GetGenericArguments();
1281 if (genericArguments.Count() != 1) 1347 if (genericArguments.Length != 1)
1282 { 1348 {
1283 throw new ArgumentException($"Unsupported type for direct construction: {objType}"); 1349 throw new ArgumentException($"Unsupported type for direct construction: {objType}");
1284 } 1350 }
@@ -1361,6 +1427,7 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1361 /// <param name="v">The value to be copied.</param> 1427 /// <param name="v">The value to be copied.</param>
1362 public Value(Value v) 1428 public Value(Value v)
1363 { 1429 {
1430 Contract.Requires(v != null, nameof(v));
1364 Handle = Alloc(); 1431 Handle = Alloc();
1365 if (!eina_value_copy(v.Handle, this.Handle)) 1432 if (!eina_value_copy(v.Handle, this.Handle))
1366 { 1433 {
@@ -1549,8 +1616,12 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1549 /// <para>Since EFL 1.23.</para> 1616 /// <para>Since EFL 1.23.</para>
1550 /// </summary> 1617 /// </summary>
1551 [EditorBrowsable(EditorBrowsableState.Never)] 1618 [EditorBrowsable(EditorBrowsableState.Never)]
1552 public static implicit operator ValueNative(Value v) 1619 public static implicit operator ValueNative(Value v) => ToValueNative(v);
1620
1621 [EditorBrowsable(EditorBrowsableState.Never)]
1622 public static ValueNative ToValueNative(Value v)
1553 { 1623 {
1624 Contract.Requires(v != null, nameof(v));
1554 return v.GetNative(); 1625 return v.GetNative();
1555 } 1626 }
1556 1627
@@ -1558,21 +1629,24 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1558 /// <para>Since EFL 1.23.</para> 1629 /// <para>Since EFL 1.23.</para>
1559 /// </summary> 1630 /// </summary>
1560 [EditorBrowsable(EditorBrowsableState.Never)] 1631 [EditorBrowsable(EditorBrowsableState.Never)]
1561 public static implicit operator Value(ValueNative v) 1632 public static implicit operator Value(ValueNative v) => FromValueNative(v);
1562 { 1633
1563 return new Value(v); 1634 [EditorBrowsable(EditorBrowsableState.Never)]
1564 } 1635 public static Value FromValueNative(ValueNative v) => new Value(v);
1565 1636
1566 /// <summary>Implicit conversion. 1637 /// <summary>Implicit conversion.
1567 /// <para>Since EFL 1.23.</para> 1638 /// <para>Since EFL 1.23.</para>
1568 /// </summary> 1639 /// </summary>
1569 public static implicit operator Value(byte x) 1640 public static implicit operator Value(byte x) => FromByte(x);
1641
1642 /// <summary>
1643 /// Conversion to a <see cref="Value" /> from a <see cref="byte" />
1644 /// </summary>
1645 /// <param name="x">The <see cref="byte" /> to be converted.</param>
1646 public static Value FromByte(byte x)
1570 { 1647 {
1571 var v = new Eina.Value(ValueType.Byte); 1648 var v = new Eina.Value(ValueType.Byte);
1572 if (!v.Set(x)) 1649 v.Set(x);
1573 {
1574 throw new InvalidOperationException("Couldn't set value.");
1575 }
1576 1650
1577 return v; 1651 return v;
1578 } 1652 }
@@ -1580,13 +1654,18 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1580 /// <summary>Implicit conversion. 1654 /// <summary>Implicit conversion.
1581 /// <para>Since EFL 1.23.</para> 1655 /// <para>Since EFL 1.23.</para>
1582 /// </summary> 1656 /// </summary>
1583 public static implicit operator byte(Value v) 1657 public static implicit operator byte(Value v) => ToByte(v);
1658
1659 /// <summary>
1660 /// Conversion to a <see cref="byte" /> from a <see cref="Value" />
1661 /// <para>Since EFL 1.23.</para>
1662 /// </summary>
1663 /// <param name="v">The <see cref="Value" /> to be converted.</param>
1664 public static byte ToByte(Value v)
1584 { 1665 {
1666 Contract.Requires(v != null, nameof(v));
1585 byte b; 1667 byte b;
1586 if (!v.Get(out b)) 1668 v.Get(out b);
1587 {
1588 throw new InvalidOperationException("Couldn't get value.");
1589 }
1590 1669
1591 return b; 1670 return b;
1592 } 1671 }
@@ -1594,13 +1673,17 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1594 /// <summary>Implicit conversion. 1673 /// <summary>Implicit conversion.
1595 /// <para>Since EFL 1.23.</para> 1674 /// <para>Since EFL 1.23.</para>
1596 /// </summary> 1675 /// </summary>
1597 public static implicit operator Value(sbyte x) 1676 public static implicit operator Value(sbyte x) => FromSByte(x);
1677
1678 /// <summary>
1679 /// Conversion to a <see cref="Value" /> from a <see cref="sbyte" />
1680 /// <para>Since EFL 1.23.</para>
1681 /// </summary>
1682 /// <param name="x">The <see cref="sbyte" /> to be converted.</param>
1683 public static Value FromSByte(sbyte x)
1598 { 1684 {
1599 var v = new Eina.Value(ValueType.SByte); 1685 var v = new Eina.Value(ValueType.SByte);
1600 if (!v.Set(x)) 1686 v.Set(x);
1601 {
1602 throw new InvalidOperationException("Couldn't set value.");
1603 }
1604 1687
1605 return v; 1688 return v;
1606 } 1689 }
@@ -1608,13 +1691,18 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1608 /// <summary>Implicit conversion. 1691 /// <summary>Implicit conversion.
1609 /// <para>Since EFL 1.23.</para> 1692 /// <para>Since EFL 1.23.</para>
1610 /// </summary> 1693 /// </summary>
1611 public static implicit operator sbyte(Value v) 1694 public static implicit operator sbyte(Value v) => ToSByte(v);
1695
1696 /// <summary>
1697 /// Conversion to a <see cref="sbyte" /> from a <see cref="Value" />
1698 /// <para>Since EFL 1.23.</para>
1699 /// </summary>
1700 /// <param name="v">The <see cref="Value" /> to be converted.</param>
1701 public static sbyte ToSByte(Value v)
1612 { 1702 {
1703 Contract.Requires(v != null, nameof(v));
1613 sbyte b; 1704 sbyte b;
1614 if (!v.Get(out b)) 1705 v.Get(out b);
1615 {
1616 throw new InvalidOperationException("Couldn't get value.");
1617 }
1618 1706
1619 return b; 1707 return b;
1620 } 1708 }
@@ -1622,13 +1710,17 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1622 /// <summary>Implicit conversion. 1710 /// <summary>Implicit conversion.
1623 /// <para>Since EFL 1.23.</para> 1711 /// <para>Since EFL 1.23.</para>
1624 /// </summary> 1712 /// </summary>
1625 public static implicit operator Value(short x) 1713 public static implicit operator Value(short x) => FromInt16(x);
1714
1715 /// <summary>
1716 /// Conversion to a <see cref="Value" /> from a <see cref="short" />
1717 /// <para>Since EFL 1.23.</para>
1718 /// </summary>
1719 /// <param name="x">The <see cref="short" /> to be converted.</param>
1720 public static Value FromInt16(short x)
1626 { 1721 {
1627 var v = new Eina.Value(ValueType.Short); 1722 var v = new Eina.Value(ValueType.Short);
1628 if (!v.Set(x)) 1723 v.Set(x);
1629 {
1630 throw new InvalidOperationException("Couldn't set value.");
1631 }
1632 1724
1633 return v; 1725 return v;
1634 } 1726 }
@@ -1636,13 +1728,18 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1636 /// <summary>Implicit conversion. 1728 /// <summary>Implicit conversion.
1637 /// <para>Since EFL 1.23.</para> 1729 /// <para>Since EFL 1.23.</para>
1638 /// </summary> 1730 /// </summary>
1639 public static implicit operator short(Value v) 1731 public static implicit operator short(Value v) => ToInt16(v);
1732
1733 /// <summary>
1734 /// Conversion to a <see cref="short" /> from a <see cref="Value" />
1735 /// <para>Since EFL 1.23.</para>
1736 /// </summary>
1737 /// <param name="v">The <see cref="Value" /> to be converted.</param>
1738 public static short ToInt16(Value v)
1640 { 1739 {
1740 Contract.Requires(v != null, nameof(v));
1641 short b; 1741 short b;
1642 if (!v.Get(out b)) 1742 v.Get(out b);
1643 {
1644 throw new InvalidOperationException("Couldn't get value.");
1645 }
1646 1743
1647 return b; 1744 return b;
1648 } 1745 }
@@ -1650,13 +1747,17 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1650 /// <summary>Implicit conversion. 1747 /// <summary>Implicit conversion.
1651 /// <para>Since EFL 1.23.</para> 1748 /// <para>Since EFL 1.23.</para>
1652 /// </summary> 1749 /// </summary>
1653 public static implicit operator Value(ushort x) 1750 public static implicit operator Value(ushort x) => FromUInt16(x);
1751
1752 /// <summary>
1753 /// Conversion to a <see cref="Value" /> from a <see cref="ushort" />
1754 /// <para>Since EFL 1.23.</para>
1755 /// </summary>
1756 /// <param name="x">The <see cref="ushort" /> to be converted.</param>
1757 public static Value FromUInt16(ushort x)
1654 { 1758 {
1655 var v = new Eina.Value(ValueType.UShort); 1759 var v = new Eina.Value(ValueType.UShort);
1656 if (!v.Set(x)) 1760 v.Set(x);
1657 {
1658 throw new InvalidOperationException("Couldn't set value.");
1659 }
1660 1761
1661 return v; 1762 return v;
1662 } 1763 }
@@ -1664,13 +1765,18 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1664 /// <summary>Implicit conversion. 1765 /// <summary>Implicit conversion.
1665 /// <para>Since EFL 1.23.</para> 1766 /// <para>Since EFL 1.23.</para>
1666 /// </summary> 1767 /// </summary>
1667 public static implicit operator ushort(Value v) 1768 public static implicit operator ushort(Value v) => ToUInt16(v);
1769
1770 /// <summary>
1771 /// Conversion to a <see cref="ushort" /> from a <see cref="Value" />
1772 /// <para>Since EFL 1.23.</para>
1773 /// </summary>
1774 /// <param name="v">The <see cref="Value" /> to be converted.</param>
1775 public static ushort ToUInt16(Value v)
1668 { 1776 {
1777 Contract.Requires(v != null, nameof(v));
1669 ushort b; 1778 ushort b;
1670 if (!v.Get(out b)) 1779 v.Get(out b);
1671 {
1672 throw new InvalidOperationException("Couldn't get value.");
1673 }
1674 1780
1675 return b; 1781 return b;
1676 } 1782 }
@@ -1678,27 +1784,37 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1678 /// <summary>Implicit conversion. 1784 /// <summary>Implicit conversion.
1679 /// <para>Since EFL 1.23.</para> 1785 /// <para>Since EFL 1.23.</para>
1680 /// </summary> 1786 /// </summary>
1681 public static implicit operator Value(int x) 1787 public static implicit operator Value(int x) => FromInt32(x);
1788
1789 /// <summary>
1790 /// Conversion to a <see cref="Value" /> from a <see cref="int" />
1791 /// <para>Since EFL 1.23.</para>
1792 /// </summary>
1793 /// <param name="x">The <see cref="int" /> to be converted.</param>
1794 public static Value FromInt32(int x)
1682 { 1795 {
1683 var v = new Eina.Value(ValueType.Int32); 1796 var v = new Eina.Value(ValueType.Int32);
1684 if (!v.Set(x)) 1797 v.Set(x);
1685 {
1686 throw new InvalidOperationException("Couldn't set value.");
1687 }
1688 1798
1689 return v; 1799 return v;
1800
1690 } 1801 }
1691 1802
1692 /// <summary>Implicit conversion. 1803 /// <summary>Implicit conversion.
1693 /// <para>Since EFL 1.23.</para> 1804 /// <para>Since EFL 1.23.</para>
1694 /// </summary> 1805 /// </summary>
1695 public static implicit operator int(Value v) 1806 public static implicit operator int(Value v) => ToInt32(v);
1807
1808 /// <summary>
1809 /// Conversion to a <see cref="int" /> from a <see cref="Value" />
1810 /// <para>Since EFL 1.23.</para>
1811 /// </summary>
1812 /// <param name="v">The <see cref="Value" /> to be converted.</param>
1813 public static int ToInt32(Value v)
1696 { 1814 {
1815 Contract.Requires(v != null, nameof(v));
1697 int b; 1816 int b;
1698 if (!v.Get(out b)) 1817 v.Get(out b);
1699 {
1700 throw new InvalidOperationException("Couldn't get value.");
1701 }
1702 1818
1703 return b; 1819 return b;
1704 } 1820 }
@@ -1706,13 +1822,17 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1706 /// <summary>Implicit conversion. 1822 /// <summary>Implicit conversion.
1707 /// <para>Since EFL 1.23.</para> 1823 /// <para>Since EFL 1.23.</para>
1708 /// </summary> 1824 /// </summary>
1709 public static implicit operator Value(uint x) 1825 public static implicit operator Value(uint x) => FromUInt32(x);
1826
1827 /// <summary>
1828 /// Conversion to a <see cref="Value" /> from a <see cref="uint" />
1829 /// <para>Since EFL 1.23.</para>
1830 /// </summary>
1831 /// <param name="x">The <see cref="uint" /> to be converted.</param>
1832 public static Value FromUInt32(uint x)
1710 { 1833 {
1711 var v = new Eina.Value(ValueType.UInt32); 1834 var v = new Eina.Value(ValueType.UInt32);
1712 if (!v.Set(x)) 1835 v.Set(x);
1713 {
1714 throw new InvalidOperationException("Couldn't set value.");
1715 }
1716 1836
1717 return v; 1837 return v;
1718 } 1838 }
@@ -1720,13 +1840,18 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1720 /// <summary>Implicit conversion. 1840 /// <summary>Implicit conversion.
1721 /// <para>Since EFL 1.23.</para> 1841 /// <para>Since EFL 1.23.</para>
1722 /// </summary> 1842 /// </summary>
1723 public static implicit operator uint(Value v) 1843 public static implicit operator uint(Value v) => ToUInt32(v);
1844
1845 /// <summary>
1846 /// Conversion to a <see cref="uint" /> from a <see cref="Value" />
1847 /// <para>Since EFL 1.23.</para>
1848 /// </summary>
1849 /// <param name="v">The <see cref="Value" /> to be converted.</param>
1850 public static uint ToUInt32(Value v)
1724 { 1851 {
1852 Contract.Requires(v != null, nameof(v));
1725 uint b; 1853 uint b;
1726 if (!v.Get(out b)) 1854 v.Get(out b);
1727 {
1728 throw new InvalidOperationException("Couldn't get value.");
1729 }
1730 1855
1731 return b; 1856 return b;
1732 } 1857 }
@@ -1734,13 +1859,17 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1734 /// <summary>Implicit conversion. 1859 /// <summary>Implicit conversion.
1735 /// <para>Since EFL 1.23.</para> 1860 /// <para>Since EFL 1.23.</para>
1736 /// </summary> 1861 /// </summary>
1737 public static implicit operator Value(long x) 1862 public static implicit operator Value(long x) => FromInt64(x);
1863
1864 /// <summary>
1865 /// Conversion to a <see cref="Value" /> from a <see cref="long" />
1866 /// <para>Since EFL 1.23.</para>
1867 /// </summary>
1868 /// <param name="x">The <see cref="long" /> to be converted.</param>
1869 public static Value F