Map template issues...

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Map template issues...

Adam Fowler
Hello all,

I’m still experiencing issues with std::map and std::vector. The std::map issue is as follows.

In my original C++ header code I am using this definition:-
typedef std::map<FacetOption,std::string> FacetOptionMap; // in namespace mlclient::utilities

So I use this in my i file, as per the recommendation at the top of csharp/std_map.i:-
%template(FacetOptionMap) std::map<mlclient::utilities::FacetOption,std::string>;

This doesn’t change anything - I still have a SWIGTYPE_p_std__mapT… instead of a reasonably named collection. So I go a slight step further.
%template(FacetOptionMap) std::map<mlclient::utilities::FacetOption,std::string,std::less<mlclient::utilities::FacetOption>>;


This is required in order for SWIG to use FacetOptionMap instead of SWIGTYPE_p_std__mapT… etc. for this type throughout the resultant C# library. This is ok.

I am then left with just the three SWIGTYPE_p_std__mapT… classes relating to the ::size_type, ::key_type and ::mapped_type for the above map typedef. So I add this definition:-
%apply size_t { std::map<mlclient::utilities::FacetOption,std::string,std::less<mlclient::utilities::FacetOption>>::size_type };
%template(FacetOptionMap) std::map<mlclient::utilities::FacetOption,std::string,std::less<mlclient::utilities::FacetOption>>;


This fixes the size_type but still leaves me with the key_type and mapped_type SWIGTYPE classes in my C# API.

These are used in the Contains, Add and Remove function calls in FacetOptionMap. Even if I try below, it does not help:-
%apply size_t { std::map<mlclient::utilities::FacetOption,std::string,std::less<mlclient::utilities::FacetOption>>::size_type };
%apply mlclient::utilities::FacetOption { std::map<mlclient::utilities::FacetOption,std::string,std::less<mlclient::utilities::FacetOption>>::key_type };
%apply std::string { std::map<mlclient::utilities::FacetOption,std::string,std::less<mlclient::utilities::FacetOption>>::mapped_type };

%template(FacetOptionMap) std::map<mlclient::utilities::FacetOption,std::string,std::less<mlclient::utilities::FacetOption>>;



I am sure there must be a very easy way to instruct SWIG to just treat my type defs as any other map (and similarly for vectors), but for some reason only the above workarounds get anywhere near what I would like to achieve.


I’m grateful for any suggestions.

Thanks in advance.

Best regards,

Adam.



Adam Fowler BSc MBCS

Public Sector Solution Architect, EMEA
MarkLogic Corporation
Blog: http://adamfowlerml.wordpress.com/

------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Map template issues...

William S Fulton
On 14 September 2016 at 20:18, Adam Fowler <[hidden email]> wrote:

> Hello all,
>
> I’m still experiencing issues with std::map and std::vector. The std::map issue is as follows.
>
> In my original C++ header code I am using this definition:-
> typedef std::map<FacetOption,std::string> FacetOptionMap; // in namespace mlclient::utilities
>
> So I use this in my i file, as per the recommendation at the top of csharp/std_map.i:-
> %template(FacetOptionMap) std::map<mlclient::utilities::FacetOption,std::string>;
>
> This doesn’t change anything - I still have a SWIGTYPE_p_std__mapT… instead of a reasonably named collection. So I go a slight step further.
> %template(FacetOptionMap) std::map<mlclient::utilities::FacetOption,std::string,std::less<mlclient::utilities::FacetOption>>;
>
>
> This is required in order for SWIG to use FacetOptionMap instead of SWIGTYPE_p_std__mapT… etc. for this type throughout the resultant C# library. This is ok.

Maybe you are not passing the full definition of
mlclient::utilities::FacetOption to SWIG. Ensure this class is parsed
by SWIG. Also make sure you %include <std_string.i> before the
%template. If that fails, post a completely cutdown version of the
code here in one SWIG interface file.

Also if you find you are using %apply, it usually indicates some
missing type information.

William

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Loading...