is this likely to work
"Duce, Richard via Swig-user" <[email protected]> Tue, 20 Sep 2022 17:25:31 +0000
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <DM6PR12MB260407D0B2C48512487F1C4F834C9@DM6PR12MB2604.namprd12.prod.outlook.com> |
[AMD Official Use Only - General]
Hi everyone.
Im a new swig user, posted a question last week and got a helpful reply from William. Thank you for that.
That got me over my first problem. On to the next.
Im using c++ and perl.
From the c++ I can pass back to the perl a std_vector<std::string>
The c++ func is
std::vector<std::string> getStopList() { return m_StopList;}
where
std::vector<std::string> m_StopList;
I added a template in the .i file like...
using namespace std;
%include <std_string.i>
%include <std_vector.i>
namespace std {
%template(StdStrVector) vector<std::string>;
}
And I can issue the getStopList command in perl and get back the vector of strings..
So far so good
Then I tried a more complicated case using std_ordered_map
William , as recommended I created a swig_4.0.2/share/swig/4.0.2/perl5/std_unordered_map.i
and with the following template entries, the wrap cxx now seems to compile ok.
using namespace std;
%include <std_string.i>
%include <std_vector.i>
%include <std_unordered_map.i>
typedef std::unordered_map<std::string,std::string> StrUnOrdMap_t;
%template(StrUnOrdMap_t) unordered_map<std::string,std::string>;
In fact, the structure in the c++
is a unordered_map of unordered_maps of unordered_maps of unordered_maps
Defined in c++ with these typedefs
typedef std::unordered_map<std::string,std::string> StrUnOrdMap_t;
typedef std::unordered_map<std::string,StrUnOrdMap_t> instToNet_t;
typedef std::unordered_map<std::string,instToNet_t> portToInstToNet_t;
typedef std::unordered_map<std::string,portToInstToNet_t> cellToPortToInstNet_t;
and this top level definition
cellToPortToInstNet_t m_CellPortMap;
the c++ for this seems to compile fine (and in fact runs fine, I can see the contents getting written out from within the c++ as a debugging step just fine)
so... my interface file becomes
using namespace std;
%include <std_string.i>
%include <std_vector.i>
%include <std_unordered_map.i>
typedef std::unordered_map<std::string,std::string> StrUnOrdMap_t;
%template(StrUnOrdMap_t) unordered_map<std::string,std::string>;
typedef std::unordered_map<std::string,StrUnOrdMap_t> instToNet_t;
%template(instToNet_t) unordered_map<std::string,StrUnOrdMap_t>;
typedef std::unordered_map<std::string,instToNet_t> portToInstToNet_t;
%template(portToInstToNet_t) unordered_map<std::string,instToNet_t>;
typedef std::unordered_map<std::string,portToInstToNet_t> cellToPortToInstNet_t;
%template(cellToPortToInstNet_t) unordered_map<std::string,portToInstToNet_t>;
The swig command I use is ...
Swig -c++ -perl myinterface.i
And the created wrap.cxx compiles fine.
I have a c++ func to attempt to get the top level of the structure
cellToPortToInstNet_t getCellPortMap() { return m_CellPortMap;}
and attempt to run it in the perl from ....
my $cellPortMap = $gvFile->getCellPortMap();
while there are no error messages, and everything compiles ok..
the returned perl structure is empty.
I then attempted to add a helper (?) function in the interface file.
%{
cellToPortToInstNet_t getCellPortMap();
%}
But that doesn't seem to help.
The returned structure is perl is empty (although I know it has the right contents in the c++)
So.. a couple of questions.
Is this likely to work ? (multilevel unordered_maps?)
Any recommendations to fix the issues. ?
Thanks again for any help
Richard
_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user