« Return to Thread: SWIG: Perl & C++: string conversions

SWIG: Perl & C++: string conversions

by Andy Karseras :: Rate this Message:

Reply to Author | View in Thread

Hi,

I am calling a C++ method (from perl) which returns a populated map of strings.

The method returns with the map correctly populated although I am
unable to assign the strings to a perl type ( if I print the returned
type, I get _p_std__string=SCALAR(0x87759c4) ).

I am using std_string.i and have defined a typemap in the interface
file as detailed in example in
http://www.swig.org/Doc1.3/Library.html, section 8.4.1.

If I create the struct and try to set it's value to one of the strings
in the map, I get:-

                              Type error in argument 2 of
my_struct_foo_set. Expected a string


I don't have a lot of experience with C++ and (obviously) a newbie to
SWIG so I'm guessing it's just something dumb.

Any ideas ?

Thanks.


Andy


Interface File
------------------

%module ConfigurationClient

%include "std_string.i"
%include "std_vector.i"
%include "std_map.i"

%template(IntVector) std::vector<int>;
%template(StringMap) std::map<std::string, std::string>;
%template(StringVector) std::vector<std::string>;

%apply const std::string& {std::string* foo};

struct my_struct
{
  std::string foo;
};


Perl Code
-------------

....
# Create map to be passed in
my $parameterNameValuesIn = ConfigurationClientc::new_StringMap();

# Pass in params
$parameterNameValuesIn =
ConfigurationClientc::ConfigurationClient_getParameterValues($self,
$parameterNameList, $parameterNameValuesIn);

# Assign the string
my $aString = ConfigurationClientc::new_my_struct();
ConfigurationClientc::my_struct_foo_set($aString,
ConfigurationClientc::StringMap_get($parameterNameValuesIn, "aKey"));
....


C++ Code (From the ConfigurationClien.h file)
--------------

...
typedef struct my_struct
{
  std::string foo;
};
...

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

 « Return to Thread: SWIG: Perl & C++: string conversions