2017-12-06 16:03:55 -08:00
|
|
|
#pragma warning disable 1591
|
2017-11-23 16:49:22 -08:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
2019-10-10 01:24:28 -07:00
|
|
|
using System.ComponentModel;
|
2017-11-23 16:49:22 -08:00
|
|
|
|
|
|
|
|
mono: fix space and brace warnings of StyleCop
Summary:
The following warning rules of StyleCop are checked.
Space rules : SA1000, SA1003, SA1008, SA1009, SA1010, SA1011
Brace rules : SA1500, SA1501, SA1502, SA1503, SA1513
Indentation is also applied.
Reviewers: lauromoura, felipealmeida, vitor.sousa, woohyun
Reviewed By: vitor.sousa
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D8485
2019-04-02 07:51:05 -07:00
|
|
|
namespace Eina
|
|
|
|
{
|
2017-11-23 16:49:22 -08:00
|
|
|
|
2019-06-28 06:40:52 -07:00
|
|
|
// TODO: move all native functions to a "NativeMethods" class
|
2019-10-10 01:24:28 -07:00
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
2019-06-28 06:40:52 -07:00
|
|
|
public static partial class NativeMethods
|
mono: fix space and brace warnings of StyleCop
Summary:
The following warning rules of StyleCop are checked.
Space rules : SA1000, SA1003, SA1008, SA1009, SA1010, SA1011
Brace rules : SA1500, SA1501, SA1502, SA1503, SA1513
Indentation is also applied.
Reviewers: lauromoura, felipealmeida, vitor.sousa, woohyun
Reviewed By: vitor.sousa
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D8485
2019-04-02 07:51:05 -07:00
|
|
|
{
|
2019-06-28 06:40:52 -07:00
|
|
|
[DllImport(efl.Libs.Eina)] public static extern IntPtr
|
|
|
|
eina_stringshare_add(IntPtr str);
|
2017-11-23 16:49:22 -08:00
|
|
|
[DllImport(efl.Libs.Eina)] public static extern System.IntPtr
|
2019-06-28 06:40:52 -07:00
|
|
|
eina_stringshare_add_length(IntPtr str, UInt32 slen);
|
2017-11-23 16:49:22 -08:00
|
|
|
[DllImport(efl.Libs.Eina)] public static extern void
|
2019-06-28 06:40:52 -07:00
|
|
|
eina_stringshare_del(IntPtr str);
|
|
|
|
[DllImport(efl.Libs.CustomExports)] public static extern void
|
|
|
|
efl_mono_native_stringshare_del_ref(IntPtr str);
|
|
|
|
[DllImport(efl.Libs.CustomExports)] public static extern IntPtr
|
|
|
|
efl_mono_native_stringshare_del_addr_get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Placeholder type to interact with the native type Eina_Stringshare, mainly for eina containers.
|
2019-09-30 20:03:42 -07:00
|
|
|
///
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <para>Since EFL 1.23.</para>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// Using System.String and merely converting this type to it (by cast or implicitly)
|
|
|
|
/// is recommended for simplicity and ease of use.
|
|
|
|
///
|
|
|
|
/// This type is just a System.String wrapper that works as a placeholder for
|
|
|
|
/// instrumentalizing proper interaction with native EFL API that demands
|
|
|
|
/// strings to be stringshares.
|
|
|
|
///
|
|
|
|
/// Both C strings and eina stringshares are bound as regular strings in EFL#,
|
|
|
|
/// as working directly with these types would demand unnecessary hassle from
|
|
|
|
/// the user viewpoint.
|
|
|
|
/// But for eina containers this distinction is important, and since C# generics
|
|
|
|
/// do not provide a convenient way of dealing with the same type requiring
|
|
|
|
/// a different management based on some other condition (at least not without
|
|
|
|
/// compromising the usability for other types), we use this string wrapper
|
|
|
|
/// in order to signal this distinction.
|
|
|
|
///
|
|
|
|
/// Implements equality/inequality methods for easier comparison with strings and
|
|
|
|
/// other Stringshare objects. For more specific operations convert to a string.
|
|
|
|
/// </remarks>
|
|
|
|
public class Stringshare : IEquatable<Stringshare>, IEquatable<string>
|
|
|
|
{
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// Main constructor. Wrap the given string.
|
|
|
|
/// Have private acess to avoid wrapping a null reference,
|
|
|
|
/// use convertion or the factory method to create a new instance.
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <para>Since EFL 1.23.</para>
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <see cref="Create(string)"/>
|
|
|
|
/// <see cref="implicit operator Stringshare(string)"/>
|
|
|
|
/// </summary>
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <param name="s">The string to be wrapped.</param>
|
2019-06-28 06:40:52 -07:00
|
|
|
private Stringshare(string s)
|
|
|
|
{
|
|
|
|
Str = s;
|
|
|
|
}
|
|
|
|
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// Auto-implemented property that holds the wrapped string value.
|
2019-07-08 08:18:47 -07:00
|
|
|
/// </summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
public string Str { get; private set; }
|
|
|
|
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// Factory method to instantiate a new object.
|
|
|
|
/// Get a wrappper for the given string or a null reference if the given
|
|
|
|
/// string reference is also null.
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <para>Since EFL 1.23.</para>
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <seealso cref="implicit operator Stringshare(string)"/>
|
|
|
|
/// </summary>
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <param name="s">The string to be wrapped.</param>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// <returns>
|
|
|
|
/// A new instance wrapping the given string, or a null reference if
|
|
|
|
/// the given string reference is also null.
|
|
|
|
/// </returns>
|
|
|
|
public static Stringshare Create(string s)
|
|
|
|
{
|
|
|
|
if (s == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Stringshare(s);
|
|
|
|
}
|
|
|
|
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// Implicit convertion to string.
|
2019-07-08 08:18:47 -07:00
|
|
|
/// </summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
public static implicit operator string(Stringshare ss)
|
|
|
|
{
|
|
|
|
if (ReferenceEquals(null, ss))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ss.Str;
|
|
|
|
}
|
|
|
|
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// Implicit convertion from string to Stringshare.
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <para>Since EFL 1.23.</para>
|
2019-07-08 08:18:47 -07:00
|
|
|
/// </summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// <remarks>
|
|
|
|
/// Note that this method can be used to create an instance of this class,
|
|
|
|
/// either via an explicit cast or an implicit convertion.
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <seealso cref="Create(string)"/>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// </remarks>
|
|
|
|
public static implicit operator Stringshare(string s)
|
|
|
|
{
|
|
|
|
if (ReferenceEquals(null, s))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Stringshare(s);
|
|
|
|
}
|
|
|
|
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// Check two Stringshare objects for equality.
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <para>Since EFL 1.23.</para>
|
2019-07-08 08:18:47 -07:00
|
|
|
/// </summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// <returns>
|
|
|
|
/// True if both wrapped strings have the same content or if both
|
|
|
|
/// references are null, false otherwise.
|
|
|
|
/// </returns>
|
|
|
|
public static bool operator==(Stringshare ss1, Stringshare ss2)
|
|
|
|
{
|
|
|
|
return ((string)ss1) == ((string)ss2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// Check two Stringshare objects for inequality.
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <para>Since EFL 1.23.</para>
|
2019-07-08 08:18:47 -07:00
|
|
|
/// </summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// <returns>
|
|
|
|
/// True if the wrapped strings have different content or if one reference is null
|
|
|
|
/// and the other is not, false otherwise.
|
|
|
|
/// </returns>
|
|
|
|
public static bool operator!=(Stringshare ss1, Stringshare ss2)
|
|
|
|
{
|
|
|
|
return !(ss1 == ss2);
|
|
|
|
}
|
|
|
|
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// Returns the wrapped string.
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <para>Since EFL 1.23.</para>
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <seealso cref="Str"/>
|
|
|
|
/// <seealso cref="Get()"/>
|
|
|
|
/// </summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// <returns>The wrapped string. Same as the property Str.</returns>
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return Str;
|
|
|
|
}
|
|
|
|
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// Override of GetHashCode for consistency with user-defined equality methods.
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <para>Since EFL 1.23.</para>
|
2019-07-08 08:18:47 -07:00
|
|
|
/// </summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// <returns>
|
|
|
|
/// The wrapped string hash code.
|
|
|
|
/// </returns>
|
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
return Str.GetHashCode();
|
|
|
|
}
|
|
|
|
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// Check the given object for equality.
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <para>Since EFL 1.23.</para>
|
2019-07-08 08:18:47 -07:00
|
|
|
/// </summary>
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <param name="other">The string to be compare to.</param>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// <returns>
|
|
|
|
/// True if the given object is the same object or if it is another Stringshare object
|
|
|
|
/// and both wrapped strings are equal or if it is a string object and its content
|
|
|
|
/// is the same of the wrapped string.
|
|
|
|
/// In any other case it returns false.
|
|
|
|
/// </returns>
|
|
|
|
public override bool Equals(object other)
|
|
|
|
{
|
|
|
|
if (ReferenceEquals(null, other))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ReferenceEquals(this, other))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (other.GetType() == typeof(string))
|
|
|
|
{
|
|
|
|
return this.Str == (string)other;
|
|
|
|
}
|
|
|
|
|
|
|
|
return other.GetType() == typeof(Stringshare) && this == ((Stringshare)other);
|
|
|
|
}
|
|
|
|
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// Check the given Stringshare for equality.
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <para>Since EFL 1.23.</para>
|
2019-07-08 08:18:47 -07:00
|
|
|
/// </summary>
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <param name="other">The string share to compare to.</param>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// <returns>
|
|
|
|
/// True if the given Stringshare object is not null and its wrapped string
|
|
|
|
/// have the same content of this.Str, false otherwise.
|
|
|
|
/// </returns>
|
|
|
|
public bool Equals(Stringshare other)
|
|
|
|
{
|
|
|
|
return this == other;
|
|
|
|
}
|
|
|
|
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// Check the given Stringshare for equality.
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <para>Since EFL 1.23.</para>
|
2019-07-08 08:18:47 -07:00
|
|
|
/// </summary>
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <param name="other">The string to compare to.</param>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// <returns>
|
|
|
|
/// True if the given string is not null and the wrapped string have the same
|
|
|
|
/// content of the given string, false otherwise.
|
|
|
|
/// </returns>
|
|
|
|
public bool Equals(string other)
|
|
|
|
{
|
|
|
|
return this.Str == other;
|
|
|
|
}
|
|
|
|
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// Get the wrapped string.
|
2019-10-10 01:24:28 -07:00
|
|
|
/// <para>Since EFL 1.23.</para>
|
2019-07-08 08:18:47 -07:00
|
|
|
/// <seealso cref="Str"/>
|
|
|
|
/// <seealso cref="ToString()"/>
|
|
|
|
/// </summary>
|
2019-06-28 06:40:52 -07:00
|
|
|
/// <returns>The wrapped string. Same as the property Str.</returns>
|
|
|
|
public string Get()
|
|
|
|
{
|
|
|
|
return Str;
|
|
|
|
}
|
2017-11-23 16:49:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|