Browse Source

Deleted the redundant and incomplete manual attempts for marshalling std types.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/681/head
Dimitar Dobrev 9 years ago
parent
commit
87fe62721c
  1. 11
      src/Runtime/StdMap.cs
  2. 123
      src/Runtime/StdString.cs
  3. 217
      src/Runtime/StdVector.cs

11
src/Runtime/StdMap.cs

@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
using System;
using System.Runtime.InteropServices;
namespace Std
{
[StructLayout(LayoutKind.Sequential)]
public unsafe struct Map
{
}
}

123
src/Runtime/StdString.cs

@ -1,123 +0,0 @@ @@ -1,123 +0,0 @@
/* Copyright (c) 2013 Xamarin, Inc and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using CppSharp.Runtime;
namespace Std
{
[StructLayout(LayoutKind.Sequential)]
public struct String : ICppMarshal
{
public int _Mysize;
public int _Myres;
public int Length
{
get { return (int)_Mysize; }
}
public String(string data)
{
_Mysize = 0;
_Myres = 0;
}
public static implicit operator string(Std.String str)
{
return string.Empty;
}
public static implicit operator String(string str)
{
return new String(str);
}
public char this[ulong index]
{
get { return '0'; }
set { }
}
public int NativeDataSize { get { return Marshal.SizeOf(this); } }
public void MarshalManagedToNative(IntPtr instance)
{
unsafe
{
var ptr = (String*) instance.ToPointer();
ptr->_Mysize = _Mysize;
ptr->_Myres = _Myres;
}
}
public void MarshalNativeToManaged(IntPtr instance)
{
unsafe
{
var ptr = (String*) instance.ToPointer();
_Mysize = ptr->_Mysize;
_Myres = ptr->_Myres;
}
}
}
public static class ListStringExtensions
{
public static Std.Vector<Std.String> ToStd(this List<string> list)
{
var vec = new Std.Vector<Std.String>();
foreach (var @string in list)
vec.Add(new Std.String(@string));
return vec;
}
}
public struct WString
{
public IntPtr Instance;
public WString(IntPtr instance)
{
Instance = instance;
}
public static implicit operator string(Std.WString str)
{
return string.Empty;
}
public static implicit operator WString(string str)
{
return new WString(IntPtr.Zero);
}
public char this[ulong index]
{
get { return '0'; }
set { }
}
}
}

217
src/Runtime/StdVector.cs

@ -1,217 +0,0 @@ @@ -1,217 +0,0 @@
/* Copyright (c) 2013 Xamarin, Inc and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#define MSVC
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using CppSharp.Runtime;
namespace Std
{
[StructLayout(LayoutKind.Sequential)]
public unsafe struct Vector
{
#if MSVC
public byte* _Myfirst;
public byte* _Mylast;
public byte* _Myend;
#endif
public long Size()
{
return _Mylast - _Myfirst;
}
public bool Capacity()
{
return (_Myend - _Myfirst) != 0;
}
public bool UnusedCapacity()
{
return (_Myend - _Mylast) != 0;
}
public bool HasUnusedCapacity()
{
return _Myend != _Mylast;
}
public void Add<T>(T item) where T : ICppMarshal
{
item.MarshalManagedToNative(new IntPtr(_Mylast));
_Mylast += item.NativeDataSize;
}
public void ReserveNew(long count, int dataSize)
{
// Allocate some storage if we do not have any yet.
if (_Myfirst == null)
{
_Myfirst = (byte*) Marshal.AllocHGlobal(dataSize);
_Mylast = _Myfirst;
_Myend = _Myfirst + dataSize;
}
// Ensure room for count new elements, grow exponentially.
}
}
[StructLayout(LayoutKind.Sequential)]
public struct Vector<T> : IList<T> where T : ICppMarshal
{
public Vector Internal;
public int Count
{
get { return (int)Internal.Size(); }
}
public bool IsReadOnly { get; private set; }
public Vector(Vector vector) : this()
{
Internal = vector;
}
public IEnumerator<T> GetEnumerator()
{
var enumerator = new VectorEnumerator<T>(this);
return enumerator;
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Add(T item)
{
if (!Internal.HasUnusedCapacity())
Internal.ReserveNew(1, item.NativeDataSize);
Internal.Add(item);
}
public void Clear()
{
throw new NotImplementedException();
}
public bool Contains(T item)
{
throw new NotImplementedException();
}
public void CopyTo(T[] array, int arrayIndex)
{
throw new NotImplementedException();
}
public bool Remove(T item)
{
throw new NotImplementedException();
}
public void Resize(int newSize)
{
throw new NotImplementedException();
}
public int IndexOf(T item)
{
throw new NotImplementedException();
}
public void Insert(int index, T item)
{
throw new NotImplementedException();
}
public void RemoveAt(int index)
{
throw new NotImplementedException();
}
public T this[int index]
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
}
public static class ListExtensions
{
public static Std.Vector<T> ToStd<T>(this List<T> list)
where T : ICppMarshal
{
var vec = new Std.Vector<T>();
return vec;
}
}
public unsafe class VectorEnumerator<T> : IEnumerator<T>
where T : ICppMarshal
{
public Vector<T> Vector;
public byte* Position;
public int DataSize;
public VectorEnumerator(Vector<T> vector)
{
Vector = vector;
if (Vector.Count > 0)
DataSize = Vector[0].NativeDataSize;
}
public void Dispose()
{
}
public bool MoveNext()
{
Position = (byte*)Vector.Internal._Myfirst;
if (Position == Vector.Internal._Mylast)
return false;
Position += DataSize;
return false;
}
public void Reset()
{
throw new NotImplementedException();
}
public T Current { get; private set; }
object IEnumerator.Current
{
get { return Current; }
}
}
}
Loading…
Cancel
Save