Last active
August 26, 2016 10:05
-
-
Save nschloe/c6d1dcb0837031183da0da5423ea23f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.0) | |
project(mytest) | |
FIND_PACKAGE(SWIG REQUIRED) | |
INCLUDE(${SWIG_USE_FILE}) | |
if (NOT MSVC) | |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | |
endif() | |
FIND_PACKAGE(PythonLibs 2 REQUIRED) | |
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}) | |
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) | |
SET(CMAKE_SWIG_FLAGS "-keyword") | |
SET_SOURCE_FILES_PROPERTIES(mytest.i PROPERTIES CPLUSPLUS ON) | |
SWIG_ADD_MODULE(mytest python mytest.i) | |
SWIG_LINK_LIBRARIES( | |
mytest | |
${PYTHON_LIBRARIES} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MYTEST_HPP | |
#define MYTEST_HPP | |
#include <iostream> | |
#include <vector> | |
#include <memory> | |
class MyBaseClass { | |
public: | |
virtual void eval() const = 0; | |
}; | |
class MyTestClass: public MyBaseClass { | |
public: | |
virtual void eval() const { | |
std::cout << "MyTestClass::eval()" << std::endl; | |
} | |
}; | |
void | |
mytest(const std::vector<std::shared_ptr<MyBaseClass>> & a) { | |
std::cout << "length: " << a.size() << std::endl; | |
} | |
#endif // MYTEST_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%module mytest | |
%{ | |
#define SWIG_FILE_WITH_INIT | |
#include "mytest.hpp" | |
%} | |
%include <std_shared_ptr.i> | |
%shared_ptr(MyBaseClass); | |
%shared_ptr(MyTestClass); | |
%include <std_vector.i> | |
namespace std { | |
%template(List) vector<std::shared_ptr<MyBaseClass>>; | |
} | |
%include "mytest.hpp" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment