lundi 7 décembre 2020

Use SWIG C++ std::vector

So I have a c++ library that I use in python(https://github.com/rkrishnasanka/fluigi-swig-interface/). The issue I'm having is that I'm unable to pass a python list of Terminal in the Net objects into the constructor. I know I'm missing something simple, but any help is appreciated.

// Part of placer.hpp

class Net
{
public:

    Net();

    Net(string id, PlacementCell *source_cell, Terminal *source_terminal, vector<PlacementCell *> sink_cells, vector<Terminal *> sink_terminals);

    ~Net()
    {
        this->sinks.clear();
        this->routes.clear();
        this->sink_terminals.clear();
    }

    string id;
    PlacementCell *source;
    Terminal *source_terminal;
    int channelSpacing;
    int channelWidth;
    vector<PlacementCell *> sinks;
    vector<Terminal *> sink_terminals;
    vector<Route *> routes;
};

So I compile this with SWIG:

%module placer

%{
#include <memory>
%}

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

%{
#include "placer.hpp"
%}

%template(PortVector) std::vector<Terminal>;
%template(PlacementCellVector) std::vector<PlacementCell>;
%template(PortPointerVector) std::vector<Terminal*>;
%template(PlacementCellPointerVector) std::vector<PlacementCell*>;
%template(SinksVector) std::vector<std::string>;

%include "placer.hpp"

Aucun commentaire:

Enregistrer un commentaire