Browse Source

Improved type maps for C++ string and vector standard library support.

pull/1/head
triton 13 years ago
parent
commit
2b7e8b9b90
  1. 23
      src/Generator/Types/Std/Stdlib.cs
  2. 68
      src/Runtime/StdVector.cs

23
src/Generator/Types/Std/Stdlib.cs

@ -34,19 +34,17 @@ namespace CppSharp.Types.Std @@ -34,19 +34,17 @@ namespace CppSharp.Types.Std
public override string CSharpSignature(CSharpTypePrinterContext ctx)
{
if (ctx.CSharpKind == CSharpTypePrinterContextKind.ManagedPointer)
return "System.IntPtr";
return "Std.String";
}
public override void CSharpMarshalToNative(MarshalContext ctx)
{
ctx.Return.Write("new Std.String().Instance");
ctx.Return.Write("new Std.String()");
}
public override void CSharpMarshalToManaged(MarshalContext ctx)
{
ctx.Return.Write("new Std.String({0})", ctx.ReturnVarName);
ctx.Return.Write(ctx.ReturnVarName);
}
}
@ -174,18 +172,27 @@ namespace CppSharp.Types.Std @@ -174,18 +172,27 @@ namespace CppSharp.Types.Std
public override string CSharpSignature(CSharpTypePrinterContext ctx)
{
return string.Format("System.Collections.Generic.List<{0}>",
ctx.GetTemplateParameterList());
if (ctx.CSharpKind == CSharpTypePrinterContextKind.Native)
return "Std.Vector";
return string.Format("Std.Vector<{0}>", ctx.GetTemplateParameterList());
}
public override void CSharpMarshalToNative(MarshalContext ctx)
{
ctx.Return.Write("null");
var templateType = Type as TemplateSpecializationType;
var type = templateType.Arguments[0].Type;
ctx.Return.Write("Std.Vector.Create({0})", ctx.Parameter.Name);
}
public override void CSharpMarshalToManaged(MarshalContext ctx)
{
ctx.Return.Write("null");
var templateType = Type as TemplateSpecializationType;
var type = templateType.Arguments[0].Type;
ctx.Return.Write("Std.Vector.Create<{0}>({1})", type,
ctx.ReturnVarName);
}
}

68
src/Runtime/StdVector.cs

@ -0,0 +1,68 @@ @@ -0,0 +1,68 @@
/* 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;
using System.Collections.Generic;
namespace Std
{
public struct Vector<T> : ICollection<T>
{
public IEnumerator<T> GetEnumerator()
{
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Add(T item)
{
throw new NotImplementedException();
}
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 int Count { get; private set; }
public bool IsReadOnly { get; private set; }
}
}
Loading…
Cancel
Save