summaryrefslogtreecommitdiff
path: root/src/bindings/mono/eina_mono/eina_value.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bindings/mono/eina_mono/eina_value.cs')
-rw-r--r--src/bindings/mono/eina_mono/eina_value.cs425
1 files changed, 332 insertions, 93 deletions
diff --git a/src/bindings/mono/eina_mono/eina_value.cs b/src/bindings/mono/eina_mono/eina_value.cs
index 6fae14b..edb1ab7 100644
--- a/src/bindings/mono/eina_mono/eina_value.cs
+++ b/src/bindings/mono/eina_mono/eina_value.cs
@@ -178,7 +178,47 @@ static internal class UnsafeNativeMethods {
178 178
179 [DllImport(efl.Libs.CustomExports)] 179 [DllImport(efl.Libs.CustomExports)]
180 [return: MarshalAsAttribute(UnmanagedType.U1)] 180 [return: MarshalAsAttribute(UnmanagedType.U1)]
181 internal static extern bool eina_value_array_append_wrapper(IntPtr handle, IntPtr data); 181 internal static extern bool eina_value_container_append_wrapper_string(IntPtr handle, string data);
182
183 [DllImport(efl.Libs.CustomExports)]
184 [return: MarshalAsAttribute(UnmanagedType.U1)]
185 internal static extern bool eina_value_container_append_wrapper_char(IntPtr handle, sbyte data);
186
187 [DllImport(efl.Libs.CustomExports)]
188 [return: MarshalAsAttribute(UnmanagedType.U1)]
189 internal static extern bool eina_value_container_append_wrapper_uchar(IntPtr handle, byte data);
190
191 [DllImport(efl.Libs.CustomExports)]
192 [return: MarshalAsAttribute(UnmanagedType.U1)]
193 internal static extern bool eina_value_container_append_wrapper_short(IntPtr handle, short data);
194
195 [DllImport(efl.Libs.CustomExports)]
196 [return: MarshalAsAttribute(UnmanagedType.U1)]
197 internal static extern bool eina_value_container_append_wrapper_ushort(IntPtr handle, ushort data);
198
199 [DllImport(efl.Libs.CustomExports)]
200 [return: MarshalAsAttribute(UnmanagedType.U1)]
201 internal static extern bool eina_value_container_append_wrapper_int(IntPtr handle, int data);
202
203 [DllImport(efl.Libs.CustomExports)]
204 [return: MarshalAsAttribute(UnmanagedType.U1)]
205 internal static extern bool eina_value_container_append_wrapper_uint(IntPtr handle, uint data);
206
207 [DllImport(efl.Libs.CustomExports)]
208 [return: MarshalAsAttribute(UnmanagedType.U1)]
209 internal static extern bool eina_value_container_append_wrapper_long(IntPtr handle, long data);
210
211 [DllImport(efl.Libs.CustomExports)]
212 [return: MarshalAsAttribute(UnmanagedType.U1)]
213 internal static extern bool eina_value_container_append_wrapper_ulong(IntPtr handle, ulong data);
214
215 [DllImport(efl.Libs.CustomExports)]
216 [return: MarshalAsAttribute(UnmanagedType.U1)]
217 internal static extern bool eina_value_container_append_wrapper_float(IntPtr handle, float data);
218
219 [DllImport(efl.Libs.CustomExports)]
220 [return: MarshalAsAttribute(UnmanagedType.U1)]
221 internal static extern bool eina_value_container_append_wrapper_double(IntPtr handle, double data);
182 222
183 [DllImport(efl.Libs.CustomExports)] 223 [DllImport(efl.Libs.CustomExports)]
184 [return: MarshalAsAttribute(UnmanagedType.U1)] 224 [return: MarshalAsAttribute(UnmanagedType.U1)]
@@ -186,7 +226,47 @@ static internal class UnsafeNativeMethods {
186 226
187 [DllImport(efl.Libs.CustomExports)] 227 [DllImport(efl.Libs.CustomExports)]
188 [return: MarshalAsAttribute(UnmanagedType.U1)] 228 [return: MarshalAsAttribute(UnmanagedType.U1)]
189 internal static extern bool eina_value_array_get_wrapper(IntPtr handle, int index, out IntPtr output); 229 internal static extern bool eina_value_container_get_wrapper(IntPtr handle, int index, out IntPtr output);
230
231 [DllImport(efl.Libs.CustomExports)]
232 [return: MarshalAsAttribute(UnmanagedType.U1)]
233 internal static extern bool eina_value_container_get_wrapper(IntPtr handle, int index, out sbyte output);
234
235 [DllImport(efl.Libs.CustomExports)]
236 [return: MarshalAsAttribute(UnmanagedType.U1)]
237 internal static extern bool eina_value_container_get_wrapper(IntPtr handle, int index, out byte output);
238
239 [DllImport(efl.Libs.CustomExports)]
240 [return: MarshalAsAttribute(UnmanagedType.U1)]
241 internal static extern bool eina_value_container_get_wrapper(IntPtr handle, int index, out short output);
242
243 [DllImport(efl.Libs.CustomExports)]
244 [return: MarshalAsAttribute(UnmanagedType.U1)]
245 internal static extern bool eina_value_container_get_wrapper(IntPtr handle, int index, out ushort output);
246
247 [DllImport(efl.Libs.CustomExports)]
248 [return: MarshalAsAttribute(UnmanagedType.U1)]
249 internal static extern bool eina_value_container_get_wrapper(IntPtr handle, int index, out int output);
250
251 [DllImport(efl.Libs.CustomExports)]
252 [return: MarshalAsAttribute(UnmanagedType.U1)]
253 internal static extern bool eina_value_container_get_wrapper(IntPtr handle, int index, out uint output);
254
255 [DllImport(efl.Libs.CustomExports)]
256 [return: MarshalAsAttribute(UnmanagedType.U1)]
257 internal static extern bool eina_value_container_get_wrapper(IntPtr handle, int index, out long output);
258
259 [DllImport(efl.Libs.CustomExports)]
260 [return: MarshalAsAttribute(UnmanagedType.U1)]
261 internal static extern bool eina_value_container_get_wrapper(IntPtr handle, int index, out ulong output);
262
263 [DllImport(efl.Libs.CustomExports)]
264 [return: MarshalAsAttribute(UnmanagedType.U1)]
265 internal static extern bool eina_value_container_get_wrapper(IntPtr handle, int index, out float output);
266
267 [DllImport(efl.Libs.CustomExports)]
268 [return: MarshalAsAttribute(UnmanagedType.U1)]
269 internal static extern bool eina_value_container_get_wrapper(IntPtr handle, int index, out double output);
190 270
191 [DllImport(efl.Libs.CustomExports)] 271 [DllImport(efl.Libs.CustomExports)]
192 [return: MarshalAsAttribute(UnmanagedType.U1)] 272 [return: MarshalAsAttribute(UnmanagedType.U1)]
@@ -194,11 +274,47 @@ static internal class UnsafeNativeMethods {
194 274
195 [DllImport(efl.Libs.CustomExports)] 275 [DllImport(efl.Libs.CustomExports)]
196 [return: MarshalAsAttribute(UnmanagedType.U1)] 276 [return: MarshalAsAttribute(UnmanagedType.U1)]
197 internal static extern bool eina_value_array_set_wrapper(IntPtr handle, int index, IntPtr value); 277 internal static extern bool eina_value_container_set_wrapper_string(IntPtr handle, int index, string value);
198 278
199 [DllImport(efl.Libs.CustomExports)] 279 [DllImport(efl.Libs.CustomExports)]
200 [return: MarshalAsAttribute(UnmanagedType.U1)] 280 [return: MarshalAsAttribute(UnmanagedType.U1)]
201 internal static extern bool eina_value_list_set_wrapper(IntPtr handle, int index, IntPtr value); 281 internal static extern bool eina_value_container_set_wrapper_uchar(IntPtr handle, int index, byte value);
282
283 [DllImport(efl.Libs.CustomExports)]
284 [return: MarshalAsAttribute(UnmanagedType.U1)]
285 internal static extern bool eina_value_container_set_wrapper_char(IntPtr handle, int index, sbyte value);
286
287 [DllImport(efl.Libs.CustomExports)]
288 [return: MarshalAsAttribute(UnmanagedType.U1)]
289 internal static extern bool eina_value_container_set_wrapper_short(IntPtr handle, int index, short value);
290
291 [DllImport(efl.Libs.CustomExports)]
292 [return: MarshalAsAttribute(UnmanagedType.U1)]
293 internal static extern bool eina_value_container_set_wrapper_ushort(IntPtr handle, int index, ushort value);
294
295 [DllImport(efl.Libs.CustomExports)]
296 [return: MarshalAsAttribute(UnmanagedType.U1)]
297 internal static extern bool eina_value_container_set_wrapper_int(IntPtr handle, int index, int value);
298
299 [DllImport(efl.Libs.CustomExports)]
300 [return: MarshalAsAttribute(UnmanagedType.U1)]
301 internal static extern bool eina_value_container_set_wrapper_uint(IntPtr handle, int index, uint value);
302
303 [DllImport(efl.Libs.CustomExports)]
304 [return: MarshalAsAttribute(UnmanagedType.U1)]
305 internal static extern bool eina_value_container_set_wrapper_long(IntPtr handle, int index, long value);
306
307 [DllImport(efl.Libs.CustomExports)]
308 [return: MarshalAsAttribute(UnmanagedType.U1)]
309 internal static extern bool eina_value_container_set_wrapper_ulong(IntPtr handle, int index, ulong value);
310
311 [DllImport(efl.Libs.CustomExports)]
312 [return: MarshalAsAttribute(UnmanagedType.U1)]
313 internal static extern bool eina_value_container_set_wrapper_float(IntPtr handle, int index, float value);
314
315 [DllImport(efl.Libs.CustomExports)]
316 [return: MarshalAsAttribute(UnmanagedType.U1)]
317 internal static extern bool eina_value_container_set_wrapper_double(IntPtr handle, int index, double value);
202 318
203 [DllImport(efl.Libs.CustomExports)] 319 [DllImport(efl.Libs.CustomExports)]
204 internal static extern IntPtr eina_value_array_subtype_get_wrapper(IntPtr handle); 320 internal static extern IntPtr eina_value_array_subtype_get_wrapper(IntPtr handle);
@@ -1747,13 +1863,70 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1747 } 1863 }
1748 public bool Append(object o) { 1864 public bool Append(object o) {
1749 ContainerSanityChecks(); 1865 ContainerSanityChecks();
1750 using (DisposableIntPtr marshalled_value = MarshalValue(o)) { 1866
1751 switch (GetValueType()) { 1867 switch (GetValueSubType()) {
1752 case ValueType.Array: 1868 case ValueType.SByte:
1753 return eina_value_array_append_wrapper(this.Handle, marshalled_value.Handle); 1869 {
1754 case ValueType.List: 1870 sbyte b = Convert.ToSByte(o);
1755 return eina_value_list_append_wrapper(this.Handle, marshalled_value.Handle); 1871 return eina_value_container_append_wrapper_char(this.Handle, b);
1756 } 1872 }
1873 case ValueType.Byte:
1874 {
1875 byte b = Convert.ToByte(o);
1876 return eina_value_container_append_wrapper_uchar(this.Handle, b);
1877 }
1878
1879 case ValueType.Short:
1880 {
1881 short b = Convert.ToInt16(o);
1882 return eina_value_container_append_wrapper_short(this.Handle, b);
1883 }
1884 case ValueType.UShort:
1885 {
1886 ushort b = Convert.ToUInt16(o);
1887 return eina_value_container_append_wrapper_ushort(this.Handle, b);
1888 }
1889
1890 case ValueType.Int32:
1891 {
1892 int x = Convert.ToInt32(o);
1893 return eina_value_container_append_wrapper_int(this.Handle, x);
1894 }
1895 case ValueType.UInt32:
1896 {
1897 uint x = Convert.ToUInt32(o);
1898 return eina_value_container_append_wrapper_uint(this.Handle, x);
1899 }
1900
1901 case ValueType.Long:
1902 case ValueType.Int64:
1903 {
1904 long x = Convert.ToInt64(o);
1905 return eina_value_container_append_wrapper_long(this.Handle, x);
1906 }
1907 case ValueType.ULong:
1908 case ValueType.UInt64:
1909 {
1910 ulong x = Convert.ToUInt64(o);
1911 return eina_value_container_append_wrapper_ulong(this.Handle, x);
1912 }
1913
1914 case ValueType.Float:
1915 {
1916 float x = Convert.ToSingle(o);
1917 return eina_value_container_append_wrapper_float(this.Handle, x);
1918 }
1919 case ValueType.Double:
1920 {
1921 double x = Convert.ToDouble(o);
1922 return eina_value_container_append_wrapper_double(this.Handle, x);
1923 }
1924
1925 case ValueType.String:
1926 {
1927 string x = Convert.ToString(o);
1928 return eina_value_container_append_wrapper_string(this.Handle, x);
1929 }
1757 } 1930 }
1758 return false; 1931 return false;
1759 } 1932 }
@@ -1763,49 +1936,163 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1763 get { 1936 get {
1764 ContainerSanityChecks(i); 1937 ContainerSanityChecks(i);
1765 1938
1766 IntPtr output = IntPtr.Zero; 1939 switch (GetValueSubType()) {
1767 switch (GetValueType()) { 1940 case ValueType.SByte:
1768 case ValueType.Array: 1941 {
1769 if (!eina_value_array_get_wrapper(this.Handle, i, out output)) 1942 sbyte ret = default(sbyte);
1770 return null; 1943 eina_value_container_get_wrapper(this.Handle, i, out ret);
1771 break; 1944 return ret;
1772 case ValueType.List: 1945 }
1773 if (!eina_value_list_get_wrapper(this.Handle, i, out output)) 1946 case ValueType.Byte:
1774 return null; 1947 {
1775 break; 1948 byte ret = default(byte);
1949 eina_value_container_get_wrapper(this.Handle, i, out ret);
1950 return ret;
1951 }
1952
1953 case ValueType.Short:
1954 {
1955 short ret = default(short);
1956 eina_value_container_get_wrapper(this.Handle, i, out ret);
1957 return ret;
1958 }
1959 case ValueType.UShort:
1960 {
1961 ushort ret = default(ushort);
1962 eina_value_container_get_wrapper(this.Handle, i, out ret);
1963 return ret;
1964 }
1965
1966 case ValueType.Int32:
1967 {
1968 int ret = default(int);
1969 eina_value_container_get_wrapper(this.Handle, i, out ret);
1970 return ret;
1971 }
1972 case ValueType.UInt32:
1973 {
1974 uint ret = default(uint);
1975 eina_value_container_get_wrapper(this.Handle, i, out ret);
1976 return ret;
1977 }
1978
1979 case ValueType.Long:
1980 case ValueType.Int64:
1981 {
1982 long ret = default(long);
1983 eina_value_container_get_wrapper(this.Handle, i, out ret);
1984 return ret;
1985 }
1986 case ValueType.ULong:
1987 case ValueType.UInt64:
1988 {
1989 ulong ret = default(ulong);
1990 eina_value_container_get_wrapper(this.Handle, i, out ret);
1991 return ret;
1992 }
1993
1994 case ValueType.Float:
1995 {
1996 float ret = default(float);
1997 eina_value_container_get_wrapper(this.Handle, i, out ret);
1998 return ret;
1999 }
2000 case ValueType.Double:
2001 {
2002 double ret = default(double);
2003 eina_value_container_get_wrapper(this.Handle, i, out ret);
2004 return ret;
2005 }
2006
2007 case ValueType.String:
2008 {
2009 // Using intptr as using string as the arg type in the DllImport'd function would
2010 // make mono take ownership of the string.
2011 IntPtr ptr = IntPtr.Zero;
2012 eina_value_container_get_wrapper(this.Handle, i, out ptr);
2013 return Eina.StringConversion.NativeUtf8ToManagedString(ptr);
2014 }
2015 default:
2016 throw new InvalidOperationException("Subtype not supported.");
1776 } 2017 }
1777 return UnMarshalPtr(output);
1778 } 2018 }
1779 set { 2019 set {
1780 ContainerSanityChecks(i); 2020 ContainerSanityChecks(i);
1781 2021
1782 switch (GetValueType()) { 2022 switch (GetValueSubType()) {
1783 case ValueType.Array: 2023 case ValueType.SByte:
1784 ArraySet(i, value); 2024 {
2025 sbyte v = Convert.ToSByte(value);
2026 eina_value_container_set_wrapper_char(this.Handle, i, v);
2027 }
1785 break; 2028 break;
1786 case ValueType.List: 2029 case ValueType.Byte:
1787 ListSet(i, value); 2030 {
2031 byte v = Convert.ToByte(value);
2032 eina_value_container_set_wrapper_uchar(this.Handle, i, v);
2033 }
1788 break; 2034 break;
1789 }
1790 }
1791 }
1792 2035
1793 private void ArraySet(int i, object value) { 2036 case ValueType.Short:
1794 using (DisposableIntPtr marshalled_value = MarshalValue(value)) 2037 {
1795 { 2038 short x = Convert.ToInt16(value);
1796 if (!eina_value_array_set_wrapper(this.Handle, i, 2039 eina_value_container_set_wrapper_short(this.Handle, i, x);
1797 marshalled_value.Handle)) { 2040 }
1798 throw new SetItemFailedException($"Failed to set item at index {i}"); 2041 break;
1799 } 2042 case ValueType.UShort:
1800 } 2043 {
1801 } 2044 ushort x = Convert.ToUInt16(value);
2045 eina_value_container_set_wrapper_ushort(this.Handle, i, x);
2046 }
2047 break;
1802 2048
1803 private void ListSet(int i, object value) { 2049 case ValueType.Int32:
1804 using (DisposableIntPtr marshalled_value = MarshalValue(value)) 2050 {
1805 { 2051 int x = Convert.ToInt32(value);
1806 if (!eina_value_list_set_wrapper(this.Handle, i, 2052 eina_value_container_set_wrapper_int(this.Handle, i, x);
1807 marshalled_value.Handle)) { 2053 }
1808 throw new SetItemFailedException($"Failed to set item at index {i}"); 2054 break;
2055 case ValueType.UInt32:
2056 {
2057 uint x = Convert.ToUInt32(value);
2058 eina_value_container_set_wrapper_uint(this.Handle, i, x);
2059 }
2060 break;
2061
2062 case ValueType.Long:
2063 case ValueType.Int64:
2064 {
2065 long x = Convert.ToInt64(value);
2066 eina_value_container_set_wrapper_long(this.Handle, i, x);
2067 }
2068 break;
2069 case ValueType.ULong:
2070 case ValueType.UInt64:
2071 {
2072 ulong x = Convert.ToUInt64(value);
2073 eina_value_container_set_wrapper_ulong(this.Handle, i, x);
2074 }
2075 break;
2076
2077 case ValueType.Float:
2078 {
2079 float x = Convert.ToSingle(value);
2080 eina_value_container_set_wrapper_float(this.Handle, i, x);
2081 }
2082 break;
2083 case ValueType.Double:
2084 {
2085 double x = Convert.ToDouble(value);
2086 eina_value_container_set_wrapper_double(this.Handle, i, x);
2087 }
2088 break;
2089
2090 case ValueType.String:
2091 {
2092 string x = Convert.ToString(value);
2093 eina_value_container_set_wrapper_string(this.Handle, i, x);
2094 }
2095 break;
1809 } 2096 }
1810 } 2097 }
1811 } 2098 }
@@ -1826,54 +2113,6 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value>
1826 } 2113 }
1827 return ValueTypeBridge.GetManaged(native_subtype); 2114 return ValueTypeBridge.GetManaged(native_subtype);
1828 } 2115 }
1829
1830 private DisposableIntPtr MarshalValue(object value)
1831 {
1832 IntPtr ret = IntPtr.Zero;
1833 bool shouldFree = false;
1834 switch(GetValueSubType()) {
1835 case ValueType.Int32:
1836 {
1837 int x = Convert.ToInt32(value);
1838 ret = new IntPtr(x);
1839 }
1840 break;
1841 case ValueType.UInt32:
1842 {
1843 uint x = Convert.ToUInt32(value);
1844 ret = new IntPtr((int)x);
1845 }
1846 break;
1847 case ValueType.String:
1848 {
1849 string x = value as string;
1850 if (x == null)
1851 ret = IntPtr.Zero;
1852 else {
1853 ret = StringConversion.ManagedStringToNativeUtf8Alloc(x);
1854 shouldFree = true;
1855 }
1856 }
1857 break;
1858 }
1859
1860 return new DisposableIntPtr(ret, shouldFree);
1861 }
1862
1863 private object UnMarshalPtr(IntPtr data)
1864 {
1865 switch(GetValueSubType()) {
1866 case ValueType.Int32:
1867 return Convert.ToInt32(data.ToInt32());
1868 case ValueType.UInt32:
1869 return Convert.ToUInt32(data.ToInt32());
1870 case ValueType.String:
1871 return StringConversion.NativeUtf8ToManagedString(data);
1872 default:
1873 return null;
1874 }
1875 }
1876
1877} 2116}
1878 2117
1879/// <summary> Custom marshaler to convert value pointers to managed values and back, 2118/// <summary> Custom marshaler to convert value pointers to managed values and back,