|
From: Andy K. <aka...@gm...> - 2009-06-10 15:53:19
|
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; }; ... |