Gennady
Gennady

Reputation: 11

std map with the user defined key to C# in Swig

I have map in C++ that defined as follow in the file MyFile.h

namespace MyMapKey {
 struct MapKey {
  double k1 = 0.0;
  double k2 = 0.0;
 };
}
namespace MyFuncNamespace {
void Func(std::map<MyMapKey::MapKey, double> mapIn) {..}
}

In the .NET the MapKey is already defined under MapKeyNET namespace (MapKeyNET::MapKey)

In the swig file I defined

%module MyFuncModule
%{
#include "MyFile.h"
%}

%import "SWIG/MapKeyNET.i"
%template (MapKeyDoubleMap) std::map<MyMapKey::MapKey, double>;
namespace MyFuncNamespace {
void Func(std::map<MyMapKey::MapKey, double> mapIn);
}

As result I got automatically generated MapKeyDoubleMap.cs file with

namespace MyFuncNamespace  {

using global::System;
using global::System.Runtime.InteropServices;

public class MapKeyDoubleMap: global::System.IDisposable 
    , global::System.Collections.Generic.IDictionary<**MapKey**, double>
 {..}
}

And this file is not passed compilation, because of MapKey missing namespace (it's already defined under MapKeyNET namespace). How allow to SWIG generate MapKeyDoubleMap.cs with MapKeyNET namespace? Thanx.

I am trying to get right namespace inside the automatically generated file

Upvotes: 0

Views: 13

Answers (0)

Related Questions