init lserp cs 5.0
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
namespace Cef3.Interop
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
//
|
||||
// While C# bool type is not blittable, we use this struct to represent C++ bool type.
|
||||
//
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = libcef.ALIGN, Size = 1)]
|
||||
internal unsafe struct bool_t
|
||||
{
|
||||
private byte _value;
|
||||
|
||||
public bool_t(bool value)
|
||||
{
|
||||
_value = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static implicit operator bool(bool_t value)
|
||||
{
|
||||
return value._value != 0;
|
||||
}
|
||||
|
||||
public static implicit operator bool_t(bool value)
|
||||
{
|
||||
return new bool_t(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
namespace Cef3.Interop
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = libcef.ALIGN)]
|
||||
internal unsafe struct cef_base_t
|
||||
{
|
||||
internal UIntPtr _size;
|
||||
internal IntPtr _add_ref;
|
||||
internal IntPtr _release;
|
||||
internal IntPtr _has_one_ref;
|
||||
|
||||
[UnmanagedFunctionPointer(libcef.CEF_CALLBACK)]
|
||||
#if !DEBUG
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
#endif
|
||||
public delegate void add_ref_delegate(cef_base_t* self);
|
||||
|
||||
[UnmanagedFunctionPointer(libcef.CEF_CALLBACK)]
|
||||
#if !DEBUG
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
#endif
|
||||
public delegate int release_delegate(cef_base_t* self);
|
||||
|
||||
[UnmanagedFunctionPointer(libcef.CEF_CALLBACK)]
|
||||
#if !DEBUG
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
#endif
|
||||
public delegate int has_one_ref_delegate(cef_base_t* self);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
namespace Cef3.Interop
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = libcef.ALIGN)]
|
||||
internal unsafe struct cef_string_list
|
||||
{
|
||||
private static readonly string[] Empty = new string[0];
|
||||
|
||||
public static string[] ToArray(cef_string_list* list)
|
||||
{
|
||||
if (list == null) return null;
|
||||
|
||||
var count = libcef.string_list_size(list);
|
||||
if (count == 0) return Empty;
|
||||
|
||||
var result = new string[count];
|
||||
|
||||
cef_string_t n_value = new cef_string_t();
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
libcef.string_list_value(list, i, &n_value); // FIXME: do not ignore return value of libcef.string_list_value
|
||||
result[i] = cef_string_t.ToString(&n_value);
|
||||
}
|
||||
|
||||
libcef.string_clear(&n_value);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static cef_string_list* From(string[] list)
|
||||
{
|
||||
var result = libcef.string_list_alloc();
|
||||
|
||||
if (list != null && list.Length > 0)
|
||||
{
|
||||
for (var i = 0; i < list.Length; i++)
|
||||
{
|
||||
var item = list[i];
|
||||
fixed (char* item_str = item)
|
||||
{
|
||||
var n_item = new cef_string_t(item_str, item != null ? item.Length : 0);
|
||||
libcef.string_list_append(result, &n_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace Cef3.Interop
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = libcef.ALIGN)]
|
||||
internal unsafe struct cef_string_map
|
||||
{
|
||||
public static Dictionary<string, string> ToDictionary(cef_string_map* map)
|
||||
{
|
||||
if (map == null) return null;
|
||||
|
||||
var result = new Dictionary<string, string>();
|
||||
var count = libcef.string_map_size(map);
|
||||
if (count == 0) return result;
|
||||
|
||||
cef_string_t n_value = new cef_string_t();
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
libcef.string_map_key(map, i, &n_value); // FIXME: do not ignore return value of libcef.string_map_key
|
||||
var key = cef_string_t.ToString(&n_value);
|
||||
libcef.string_map_value(map, i, &n_value); // FIXME: do not ignore return value of libcef.string_map_value
|
||||
var value = cef_string_t.ToString(&n_value);
|
||||
result.Add(key, value);
|
||||
}
|
||||
|
||||
libcef.string_clear(&n_value);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
namespace Cef3.Interop
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = libcef.ALIGN)]
|
||||
internal unsafe struct cef_string_multimap
|
||||
{
|
||||
public static NameValueCollection ToNameValueCollection(cef_string_multimap* multimap)
|
||||
{
|
||||
var result = new NameValueCollection(StringComparer.InvariantCultureIgnoreCase);
|
||||
if (multimap == null) return result;
|
||||
|
||||
var size = libcef.string_multimap_size(multimap);
|
||||
|
||||
var n_key = new cef_string_t();
|
||||
var n_value = new cef_string_t();
|
||||
for (var i = 0; i < size; i++)
|
||||
{
|
||||
libcef.string_multimap_key(multimap, i, &n_key);
|
||||
libcef.string_multimap_value(multimap, i, &n_value);
|
||||
|
||||
result.Add(cef_string_t.ToString(&n_key), cef_string_t.ToString(&n_value));
|
||||
}
|
||||
|
||||
libcef.string_clear(&n_key);
|
||||
libcef.string_clear(&n_value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static cef_string_multimap* From(NameValueCollection collection)
|
||||
{
|
||||
var result = libcef.string_multimap_alloc();
|
||||
|
||||
foreach (string key in collection)
|
||||
{
|
||||
fixed (char* key_ptr = key)
|
||||
{
|
||||
var n_key = new cef_string_t(key_ptr, key.Length);
|
||||
|
||||
foreach (var value in collection.GetValues(key))
|
||||
{
|
||||
fixed (char* value_ptr = value)
|
||||
{
|
||||
var n_value = new cef_string_t(value_ptr, value.Length);
|
||||
|
||||
libcef.string_multimap_append(result, &n_key, &n_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
namespace Cef3.Interop
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = libcef.ALIGN)]
|
||||
internal unsafe partial struct cef_string_t
|
||||
{
|
||||
internal char* _str;
|
||||
internal UIntPtr _length;
|
||||
internal IntPtr _dtor;
|
||||
|
||||
[UnmanagedFunctionPointer(libcef.CEF_CALL)]
|
||||
#if !DEBUG
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
#endif
|
||||
public delegate void dtor_delegate(char* str);
|
||||
|
||||
public cef_string_t(char* str, int length)
|
||||
{
|
||||
_str = str;
|
||||
_length = (UIntPtr)length;
|
||||
_dtor = IntPtr.Zero;
|
||||
}
|
||||
|
||||
public static void Copy(string value, cef_string_t* str)
|
||||
{
|
||||
fixed (char* value_ptr = value)
|
||||
{
|
||||
libcef.string_set(value_ptr, value != null ? (UIntPtr)value.Length : UIntPtr.Zero, str, 1); // FIXME: do not ignore result
|
||||
}
|
||||
}
|
||||
|
||||
public static string ToString(cef_string_t* obj)
|
||||
{
|
||||
if (obj == null) return null;
|
||||
|
||||
return new string((char*)obj->_str, 0, (int)obj->_length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
|
||||
[UnmanagedFunctionPointer(libcef.CallConv)]
|
||||
#if !DEBUG
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
#endif
|
||||
public delegate void dtor_delegate(char* str);
|
||||
|
||||
/// <summary>
|
||||
/// This is useful to pass string without copying.
|
||||
/// </summary>
|
||||
public cef_string_t(char* str, int length)
|
||||
{
|
||||
this.str = str;
|
||||
this.length = length;
|
||||
this.dtor = IntPtr.Zero;
|
||||
}
|
||||
|
||||
#if DIAGNOSTICS
|
||||
private static readonly bool diagnostics = true;
|
||||
|
||||
private static dtor_delegate bs_dtor_impl;
|
||||
private static IntPtr bs_dtor_impl_fp;
|
||||
|
||||
internal static Action<IntPtr, string> OnCreate;
|
||||
internal static Action<IntPtr> OnDispose;
|
||||
|
||||
static cef_string_t()
|
||||
{
|
||||
bs_dtor_impl = new dtor_delegate(dtor_impl);
|
||||
bs_dtor_impl_fp = Marshal.GetFunctionPointerForDelegate(bs_dtor_impl);
|
||||
}
|
||||
|
||||
private static void dtor_impl(char* str)
|
||||
{
|
||||
if (OnDispose != null) OnDispose((IntPtr)str);
|
||||
Marshal.FreeHGlobal((IntPtr)str);
|
||||
}
|
||||
|
||||
private static void copy_impl(string src, cef_string_t* dst)
|
||||
{
|
||||
NativeMethods.string_clear(dst);
|
||||
|
||||
if (string.IsNullOrEmpty(src))
|
||||
{
|
||||
if (OnCreate != null) OnCreate(IntPtr.Zero, null);
|
||||
dst->str = null;
|
||||
dst->length = 0;
|
||||
dst->dtor = IntPtr.Zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
var ptr = Marshal.StringToHGlobalUni(src);
|
||||
if (OnCreate != null) OnCreate((IntPtr)ptr, src);
|
||||
dst->str = (char*)ptr;
|
||||
dst->length = src.Length;
|
||||
dst->dtor = bs_dtor_impl_fp;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public static string ToString(cef_string_t* ptr)
|
||||
{
|
||||
if (ptr == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return new string(ptr->str, 0, ptr->length);
|
||||
}
|
||||
|
||||
public static void Set(string src, cef_string_t* dst, bool copy)
|
||||
{
|
||||
fixed (char* ptr = src)
|
||||
{
|
||||
#if DIAGNOSTICS
|
||||
if (copy)
|
||||
{
|
||||
copy_impl(src, dst);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
NativeMethods.cef_string_set(ptr, src == null ? 0 : src.Length, dst, copy ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Copy(string src, cef_string_t* dst)
|
||||
{
|
||||
fixed (char* ptr = src)
|
||||
{
|
||||
#if DIAGNOSTICS
|
||||
if (diagnostics)
|
||||
{
|
||||
copy_impl(src, dst);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
NativeMethods.cef_string_set(ptr, src == null ? 0 : src.Length, dst, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Clear(cef_string_t* str)
|
||||
{
|
||||
NativeMethods.cef_string_clear(str);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
namespace Cef3.Interop
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
/// <summary>
|
||||
/// It is sometimes necessary for the system to allocate string structures with
|
||||
/// the expectation that the user will free them. The userfree types act as a
|
||||
/// hint that the user is responsible for freeing the structure.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <c>cef_string_userfree*</c> === <c>cef_string_userfree_t</c>.
|
||||
/// </remarks>
|
||||
internal unsafe struct cef_string_userfree
|
||||
{
|
||||
public static string ToString(cef_string_userfree* str)
|
||||
{
|
||||
if (str != null)
|
||||
{
|
||||
var result = cef_string_t.ToString((cef_string_t*)str);
|
||||
libcef.string_userfree_free(str);
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
public static int GetLength(cef_string_userfree* str)
|
||||
{
|
||||
return ((cef_string_t*)str)->length;
|
||||
}
|
||||
|
||||
internal static char GetFirstCharOrDefault(cef_string_userfree* str)
|
||||
{
|
||||
var str_t = ((cef_string_t*)str);
|
||||
if (str_t->length > 0)
|
||||
{
|
||||
return *(str_t->str);
|
||||
}
|
||||
return '\x0';
|
||||
}
|
||||
|
||||
public static void Free(cef_string_userfree* str)
|
||||
{
|
||||
if (str != null)
|
||||
{
|
||||
NativeMethods.cef_string_userfree_free(str);
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetString(cef_string_userfree* str)
|
||||
{
|
||||
if (str != null)
|
||||
{
|
||||
return cef_string_t.ToString((cef_string_t*)str);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetStringAndFree(cef_string_userfree* str)
|
||||
{
|
||||
if (str != null)
|
||||
{
|
||||
var result = cef_string_t.ToString((cef_string_t*)str);
|
||||
NativeMethods.cef_string_userfree_free(str);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Cef3.Interop
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = libcef.ALIGN)]
|
||||
internal unsafe partial struct cefglue_userdata_t
|
||||
{
|
||||
internal cef_base_t _base;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user