Browse Source

We now create an extra public constructor that takes an IntPtr. We do this because by default native types are not exported as public in MSVC C++/CLI and we need to be able to instantiate these objects.

pull/1/head
triton 13 years ago
parent
commit
27a70dbbfe
  1. 3
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs
  2. 48
      src/Generator/Generators/CLI/CLISourcesTemplate.cs

3
src/Generator/Generators/CLI/CLIHeadersTemplate.cs

@ -199,7 +199,7 @@ namespace Cxxi.Generators.CLI @@ -199,7 +199,7 @@ namespace Cxxi.Generators.CLI
WriteLine("{");
WriteLine("public:");
var nativeType = string.Format("::{0}*", @class.OriginalName);
var nativeType = string.Format("::{0}*", @class.QualifiedOriginalName);
if (@class.IsRefType)
{
@ -212,6 +212,7 @@ namespace Cxxi.Generators.CLI @@ -212,6 +212,7 @@ namespace Cxxi.Generators.CLI
// Output a default constructor that takes the native pointer.
PushIndent();
WriteLine("{0}({1} native);", SafeIdentifier(@class.Name), nativeType);
WriteLine("{0}({1} native);", SafeIdentifier(@class.Name), "System::IntPtr");
PopIndent();
if (@class.IsValueType)

48
src/Generator/Generators/CLI/CLISourcesTemplate.cs

@ -99,22 +99,9 @@ namespace Cxxi.Generators.CLI @@ -99,22 +99,9 @@ namespace Cxxi.Generators.CLI
{
GenerateDeclarationCommon(@class);
if (!@class.IsValueType)
{
// Output a default constructor that takes the native pointer.
Write("{0}::{1}(", QualifiedIdentifier(@class), SafeIdentifier(@class.Name));
var nativeType = string.Format("::{0}*", @class.OriginalName);
WriteLine("{0} native)", nativeType);
WriteLine("{");
PushIndent();
WriteLine("NativePtr = native;");
PopIndent();
WriteLine("}");
NewLine();
}
// Output a default constructor that takes the native pointer.
GenerateClassConstructor(@class, isIntPtr: false);
GenerateClassConstructor(@class, isIntPtr: true);
foreach (var method in @class.Methods)
{
@ -128,6 +115,35 @@ namespace Cxxi.Generators.CLI @@ -128,6 +115,35 @@ namespace Cxxi.Generators.CLI
}
}
private void GenerateClassConstructor(Class @class, bool isIntPtr)
{
Write("{0}::{1}(", QualifiedIdentifier(@class), SafeIdentifier(@class.Name));
var nativeType = string.Format("::{0}*", @class.OriginalName);
WriteLine("{0} native)", isIntPtr ? "System::IntPtr" : nativeType);
WriteLine("{");
PushIndent();
if (@class.IsRefType)
{
Write("NativePtr = ");
if (isIntPtr)
Write("({0})", nativeType);
Write("native");
if (isIntPtr)
Write(".ToPointer()");
WriteLine(";");
}
else
{
WriteLine("// TODO: Struct marshaling");
}
PopIndent();
WriteLine("}");
NewLine();
}
public void GenerateMethod(Method method, Class @class)
{
GenerateDeclarationCommon(method);

Loading…
Cancel
Save