Hereinafter pif stands for Python InterFace. First I have a common header file called conv_pif.hpp that has Boost headers and C ++ Std Library headers, etc. Then for each boost python module, I have a file (here is the corresponding genocpp example) of the form string_pif.cpp, where the line corresponds approximately to the name of the module.
****************************************************************************************
geno_pif.cpp
****************************************************************************************
#include "conv_pif.hpp"
#include <boost/python.hpp>
#include "geno.hpp"
void export_cppvec_conv();
void export_geno()
{
boost::python::def("write_geno_table_affy6_to_file", write_geno_table_affy6_to_file);
}
BOOST_PYTHON_MODULE(genocpp)
{
export_geno();
export_cppvec_conv();
}
*****************************************************************************************
The export_cppvec_conv function matches a (templated) converter to / from C ++ vectors to python lists. I have the actual converters in the cppvec_conv_pif.cpp file. In particular, this defines export_cppvec_conv, which uses template conversion, so I can leave without including it in geno_pif.cpp. For illustration, the contents of export_cppvec_conv are as follows: cppvec_to_python_list and cppvec_from_python_list are defined in the body cppvec_conv_pif.cpp.
******************************************
cppvec_conv_pif.cpp (extract)
******************************************
void export_cppvec_conv()
{
boost::python::to_python_converter<vector<double>, cppvec_to_python_list<double> >();
cppvec_from_python_list<double>();
boost::python::to_python_converter<vector<int>, cppvec_to_python_list<int> >();
cppvec_from_python_list<int>();
boost::python::to_python_converter<vector<string>, cppvec_to_python_list<string> >();
cppvec_from_python_list<string>();
}
******************************************
, genocpp.
, , geno geno.hpp.
, Scons,
******************************************
Sconstruct
******************************************
import commands, glob, os
common_files = """geno print"""
def pyversion():
pystr = commands.getoutput('python -V')
version = pystr.split(' ')[1]
major, minor = version.split('.')[:2]
return major + '.' + minor
common_base = Split(common_files)
common = [f + ".cpp" for f in common_base]
pif_conv = Split("cppvec_conv cppmap_conv cppset_conv")
pif_conv_files = [t+"_pif.cpp" for t in pif_conv]
pif = Split("geno")
pif_files = [t+"_pif.cpp" for t in pif]
boost_python_env = Environment(
CPPPATH=["/usr/include/python"+pyversion(), "."],
CXXFLAGS='-ftemplate-depth-100 -fPIC -Wall -Werror -pedantic -pipe -O3 -ffast-math -march=opteron',
CPPDEFINES=['BOOST_PYTHON_DYNAMIC_LIB'],
LIBPATH=["/usr/lib/python"+pyversion()+"/config"],
LIBS=["python"+pyversion(), "m", "boost_python"],
SHLIBPREFIX="",
SHOBJSUFFIX = ".bpo"
)
boost_python_env.SharedLibrary(target='genocpp', source = common + pif_conv_files + pif_files)
, pif_files geno_pif.cpp. , . , , -. - , , ?
, Faheem