summaryrefslogtreecommitdiff
path: root/src/bindings/mono/eina_mono/eina_error.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bindings/mono/eina_mono/eina_error.cs')
-rw-r--r--src/bindings/mono/eina_mono/eina_error.cs145
1 files changed, 122 insertions, 23 deletions
diff --git a/src/bindings/mono/eina_mono/eina_error.cs b/src/bindings/mono/eina_mono/eina_error.cs
index 7b5733d..44528cc 100644
--- a/src/bindings/mono/eina_mono/eina_error.cs
+++ b/src/bindings/mono/eina_mono/eina_error.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;
@@ -9,7 +24,7 @@ namespace Eina
9/// <summary>Error codes from native Eina methods. 24/// <summary>Error codes from native Eina methods.
10/// <para>Since EFL 1.23.</para> 25/// <para>Since EFL 1.23.</para>
11/// </summary> 26/// </summary>
12public struct Error : IComparable<Error> 27public struct Error : IComparable<Error>, IEquatable<Error>
13{ 28{
14 int code; 29 int code;
15 30
@@ -26,7 +41,7 @@ public struct Error : IComparable<Error>
26 /// Unhandled Exception error identifier. 41 /// Unhandled Exception error identifier.
27 /// <para>Since EFL 1.23.</para> 42 /// <para>Since EFL 1.23.</para>
28 /// </summary> 43 /// </summary>
29 public static readonly Error UNHANDLED_EXCEPTION; 44 public static readonly Error UNHANDLED_EXCEPTION = eina_error_msg_register("Unhandled C# exception occurred.");
30 45
31 /// <summary> 46 /// <summary>
32 /// No error identifier. 47 /// No error identifier.
@@ -64,31 +79,28 @@ public struct Error : IComparable<Error>
64 /// <para>Since EFL 1.23.</para> 79 /// <para>Since EFL 1.23.</para>
65 /// </summary> 80 /// </summary>
66 /// <param name="val">Value to be converted to Error</param> 81 /// <param name="val">Value to be converted to Error</param>
67 static public implicit operator Error(int val) 82 public static implicit operator Error(int val) => FromInt32(val);
68 { 83
69 return new Error(val); 84 /// <summary>
70 } 85 /// Converts a <see cref="int" /> to a <see cref="Error" />.
86 /// <para>Since EFL 1.23.</para>
87 /// </summary>
88 /// <param name="val">The <see cref="int" /> to be converted.</param>
89 public static Error FromInt32(int val) => new Error(val);
71 90
72 /// <summary> 91 /// <summary>
73 /// Int conversion from Error. 92 /// Int conversion from Error.
74 /// <para>Since EFL 1.23.</para> 93 /// <para>Since EFL 1.23.</para>
75 /// </summary> 94 /// </summary>
76 /// <param name="error">Error identifier to be converted to int</param> 95 /// <param name="error">Error identifier to be converted to int</param>
77 static public implicit operator int(Error error) 96 public static implicit operator int(Error error) => ToInt32(error);
78 {
79 return error.code;
80 }
81 97
82 /// <summary> 98 /// <summary>
83 /// Compare two Errors. 99 /// Converts a <see cref="Error" /> to a <see cref="int" />.
84 /// <para>Since EFL 1.23.</para> 100 /// <para>Since EFL 1.23.</para>
85 /// </summary> 101 /// </summary>
86 /// <param name="err">Error to be compared with</param> 102 /// <param name="error">The <see cref="Error" /> to be converted.</param>
87 /// <returns>True with the Errors is equal, False otherwise.</returns> 103 public static int ToInt32(Error error) => error.code;
88 public int CompareTo(Error err)
89 {
90 return code.CompareTo(err.code);
91 }
92 104
93 /// <summary> 105 /// <summary>
94 /// Transform the object to a string representing the object. 106 /// Transform the object to a string representing the object.
@@ -100,11 +112,6 @@ public struct Error : IComparable<Error>
100 return "Eina.Error(" + code + ")"; 112 return "Eina.Error(" + code + ")";
101 } 113 }
102 114
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); 115 [DllImport(efl.Libs.Eina)] static extern Error eina_error_msg_register(string msg);
109 [DllImport(efl.Libs.Eina)] static extern Error eina_error_get(); 116 [DllImport(efl.Libs.Eina)] static extern Error eina_error_get();
110 [DllImport(efl.Libs.Eina)] static extern void eina_error_set(Error error); 117 [DllImport(efl.Libs.Eina)] static extern void eina_error_set(Error error);
@@ -187,6 +194,98 @@ public struct Error : IComparable<Error>
187 { 194 {
188 return eina_error_msg_register(msg); 195 return eina_error_msg_register(msg);
189 } 196 }
190}
191 197
198 /// <summary>
199 /// Gets a hash for <see cref="Eina.Error" />.
200 /// <para>Since EFL 1.23.</para>
201 /// </summary>
202 /// <returns>A hash code.</returns>
203 public override int GetHashCode()
204 => code.GetHashCode() + Message.GetHashCode(StringComparison.Ordinal);
205
206 /// <summary>
207 /// Compare to a given error.
208 /// <para>Since EFL 1.23.</para>
209 /// </summary>
210 /// <param name="err">Error to be compared with.</param>
211 /// <returns>-1, 0 or 1 if -1 if Error is less, equal or greater than err.</returns>
212 public int CompareTo(Error err) => code.CompareTo(err.code);
213
214 /// <summary>
215 /// Check if is equal to obj.
216 /// <para>Since EFL 1.23.</para>
217 /// </summary>
218 /// <param name="obj">The object to be checked.</param>
219 /// <returns>false if obj is null or not equals, true otherwise.</returns>
220 public override bool Equals(object obj)
221 {
222 if (object.ReferenceEquals(obj, null))
223 return false;
224
225 return this.Equals((Error)obj);
226 }
227
228 /// <summary>
229 /// Check if is equal to err.
230 /// <para>Since EFL 1.23.</para>
231 /// </summary>
232 /// <param name="err">The object to be checked.</param>
233 /// <returns>false if obj is null or not equals, true otherwise.</returns>
234 public bool Equals(Error err) => this.CompareTo(err) == 0;
235
236 /// <summary>
237 /// Check if lhs is equals to rhs.
238 /// <para>Since EFL 1.23.</para>
239 /// </summary>
240 /// <param name="lhs">The left hand side of the operator.</param>
241 /// <param name="rhs">The right hand side of the operator.</param>
242 /// <returns>true if lhs is equals to rhs, false otherwise.</returns>
243 public static bool operator==(Error lhs, Error rhs) => lhs.Equals(rhs);
244
245 /// <summary>
246 /// Check if lhs is not equals to rhs.
247 /// <para>Since EFL 1.23.</para>
248 /// </summary>
249 /// <param name="lhs">The left hand side of the operator.</param>
250 /// <param name="rhs">The right hand side of the operator.</param>
251 /// <returns>true if lhs is not equals to rhs, false otherwise.</returns>
252 public static bool operator!=(Error lhs, Error rhs) => !(lhs == rhs);
253
254 /// <summary>
255 /// Check if lhs is less than rhs.
256 /// <para>Since EFL 1.23.</para>
257 /// </summary>
258 /// <param name="lhs">The left hand side of the operator.</param>
259 /// <param name="rhs">The right hand side of the operator.</param>
260 /// <returns>true if lhs is less than rhs, false otherwise.</returns>
261 public static bool operator<(Error lhs, Error rhs) => (lhs.CompareTo(rhs) < 0);
262
263 /// <summary>
264 /// Check if lhs is greater to rhs.
265 /// <para>Since EFL 1.23.</para>
266 /// </summary>
267 /// <param name="lhs">The left hand side of the operator.</param>
268 /// <param name="rhs">The right hand side of the operator.</param>
269 /// <returns>true if lhs is greater than rhs, false otherwise.</returns>
270 public static bool operator>(Error lhs, Error rhs) => rhs < lhs;
271
272 /// <summary>
273 /// Check if lhs is equals and less than rhs.
274 /// <para>Since EFL 1.23.</para>
275 /// </summary>
276 /// <param name="lhs">The left hand side of the operator.</param>
277 /// <param name="rhs">The right hand side of the operator.</param>
278 /// <returns>true if lhs is equals and less than rhs, false otherwise.</returns>
279 public static bool operator<=(Error lhs, Error rhs) => !(lhs > rhs);
280
281 /// <summary>
282 /// Check if lhs is equals and greater than rhs.
283 /// <para>Since EFL 1.23.</para>
284 /// </summary>
285 /// <param name="lhs">The left hand side of the operator.</param>
286 /// <param name="rhs">The right hand side of the operator.</param>
287 /// <returns>true if lhs is equals and greater than rhs, false otherwise.</returns>
288 public static bool operator>=(Error lhs, Error rhs) => !(lhs < rhs);
289
290}
192} 291}