diff --git a/modules/base/pymod/wrap_base.cc b/modules/base/pymod/wrap_base.cc index 728cb5ab68cda8b8647f9afafbb1be84ecad3718..13bc81155762468dd32565533f847b5db999d129 100644 --- a/modules/base/pymod/wrap_base.cc +++ b/modules/base/pymod/wrap_base.cc @@ -20,6 +20,7 @@ #include <boost/python.hpp> #include <boost/python/suite/indexing/vector_indexing_suite.hpp> +#include <ost/export_helper/vector.hh> #include <ost/base.hh> #include <ost/platform.hh> @@ -41,12 +42,16 @@ BOOST_PYTHON_MODULE(_base) typedef std::vector<float> FloatList; class_<FloatList>("FloatList", init<>()) .def(vector_indexing_suite<FloatList>()) + .def(ost::VectorAdditions<FloatList>()) ; + class_<std::vector<String> >("StringList", init<>()) .def(vector_indexing_suite<std::vector<String> >()) ; + typedef std::vector<int> IntList; class_<std::vector<int> >("IntList", init<>()) .def(vector_indexing_suite<std::vector<int> >()) - ; + .def(ost::VectorAdditions<IntList>()) + ; } diff --git a/modules/base/src/CMakeLists.txt b/modules/base/src/CMakeLists.txt index 386e9d920a5f23f59dd187bc0d25e6db7d3faac2..3ca08186ac38dd5b8a6a563338ba7278d4610d1d 100644 --- a/modules/base/src/CMakeLists.txt +++ b/modules/base/src/CMakeLists.txt @@ -33,6 +33,7 @@ tri_matrix.hh set(OST_EXPORT_HELPERS generic_property_def.hh pair_to_tuple_conv.hh +vector.hh ) module(NAME base SOURCES ${OST_BASE_SOURCES} HEADERS ${OST_EXPORT_HELPERS} IN_DIR export_helper diff --git a/modules/base/src/export_helper/vector.hh b/modules/base/src/export_helper/vector.hh new file mode 100644 index 0000000000000000000000000000000000000000..0b262bf5561aac5523112c0ad34cd2c4b4e0e776 --- /dev/null +++ b/modules/base/src/export_helper/vector.hh @@ -0,0 +1,46 @@ +#ifndef OST_EXPORT_HELPER_VECTOR_HH +#define OST_EXPORT_HELPER_VECTOR_HH + +# include <boost/python/def_visitor.hpp> + +/* + Author: Marco Biasini + */ + +namespace ost { + + +template <typename Container> +class VectorAdditions : + public boost::python::def_visitor<VectorAdditions<Container> > { +public: + template <class Class> + void visit(Class& cl) const + { + cl + .def("__str__", &to_string) + ; + } +private: + static std::string to_string(Container& cl) + { + std::stringstream ss; + ss << "["; + bool first=true; + for (typename Container::const_iterator + i=cl.begin(), e=cl.end(); i!=e; ++i) { + if (first) { + first=false; + } else { + ss << ", "; + } + ss << (*i); + } + ss << "]"; + return ss.str(); + } +}; + +} + +#endif diff --git a/modules/mol/base/pymod/export_atom.cc b/modules/mol/base/pymod/export_atom.cc index c2133beb95fcc8cf280db30c176a075824eedf68..43e7483a79f7984d348bb85d5bd83be58e785325 100644 --- a/modules/mol/base/pymod/export_atom.cc +++ b/modules/mol/base/pymod/export_atom.cc @@ -27,7 +27,7 @@ using namespace ost; using namespace ost::mol; #include <ost/export_helper/generic_property_def.hh> - +#include <ost/export_helper/vector.hh> void export_Atom() { class_<AtomBase> atom_base("AtomBase", no_init); @@ -94,6 +94,7 @@ void export_Atom() class_<AtomHandleList>("AtomHandleList", no_init) .def(vector_indexing_suite<AtomHandleList>()) + .def(ost::VectorAdditions<AtomHandleList>()) ; class_<AtomProp>("AtomProp", init<>()) .def_readwrite("element", &AtomProp::element) diff --git a/modules/mol/base/pymod/export_atom_view.cc b/modules/mol/base/pymod/export_atom_view.cc index 036a87ae056ded83b3f30b4803315aa9f3295a89..bdee6609db8e34db9a52d055ebeac7a4547d3ae0 100644 --- a/modules/mol/base/pymod/export_atom_view.cc +++ b/modules/mol/base/pymod/export_atom_view.cc @@ -22,7 +22,7 @@ using namespace boost::python; #include <ost/mol/mol.hh> - +#include <ost/export_helper/vector.hh> using namespace ost; using namespace ost::mol; @@ -50,6 +50,7 @@ void export_AtomView() ; class_<AtomViewList>("AtomViewList", init<>()) .def(vector_indexing_suite<AtomViewList>()) + .def(ost::VectorAdditions<AtomViewList>()) ; } diff --git a/modules/mol/base/pymod/export_chain.cc b/modules/mol/base/pymod/export_chain.cc index 57e717ebac7e5a63c108eb0568c9815d09a7994e..fe2019d3affbe500583a2873ab17df6f17b3f900 100644 --- a/modules/mol/base/pymod/export_chain.cc +++ b/modules/mol/base/pymod/export_chain.cc @@ -21,7 +21,7 @@ using namespace boost::python; #include <ost/mol/mol.hh> - +#include <ost/export_helper/vector.hh> using namespace ost; using namespace ost::mol; #include <ost/export_helper/generic_property_def.hh> @@ -92,5 +92,6 @@ void export_Chain() class_<ChainHandleList>("ChainHandleList", no_init) .def(vector_indexing_suite<ChainHandleList>()) + .def(ost::VectorAdditions<ChainHandleList>()) ; } diff --git a/modules/mol/base/pymod/export_chain_view.cc b/modules/mol/base/pymod/export_chain_view.cc index 8de0f77d7a3220db2fd8abe95fdab72340108285..fa8446a5057b6140f27b79742b7bc6876ff4fae2 100644 --- a/modules/mol/base/pymod/export_chain_view.cc +++ b/modules/mol/base/pymod/export_chain_view.cc @@ -24,7 +24,7 @@ using namespace boost::python; #include <ost/mol/query.hh> #include <ost/mol/chain_handle.hh> #include <ost/mol/entity_visitor.hh> - +#include <ost/export_helper/vector.hh> using namespace ost; using namespace ost::mol; @@ -58,6 +58,7 @@ void export_ChainView() { class_<ChainViewList>("ChainViewList", no_init) .def(vector_indexing_suite<ChainViewList>()) + .def(ost::VectorAdditions<ChainViewList>()) ; void (ChainView::* apply1)(EntityVisitor&) = &ChainView::Apply; diff --git a/modules/mol/base/pymod/export_residue.cc b/modules/mol/base/pymod/export_residue.cc index 27575f800ff1b37971cde43d484557ebe3ed855d..0c28df65249210b61a1546f6895f3c343f393f7b 100644 --- a/modules/mol/base/pymod/export_residue.cc +++ b/modules/mol/base/pymod/export_residue.cc @@ -22,7 +22,7 @@ using namespace boost::python; #include <ost/mol/mol.hh> - +#include <ost/export_helper/vector.hh> using namespace ost; using namespace ost::mol; @@ -175,5 +175,6 @@ void export_Residue() class_<ResidueHandleList>("ResidueHandleList", no_init) .def(vector_indexing_suite<ResidueHandleList>()) + .def(ost::VectorAdditions<ResidueHandleList>()) ; } diff --git a/modules/mol/base/pymod/export_residue_view.cc b/modules/mol/base/pymod/export_residue_view.cc index 29943f54a99392eb06afce6d84d91ffe9e0d4da6..a23bcf88d418a6110ce291278bdf090272ca29df 100644 --- a/modules/mol/base/pymod/export_residue_view.cc +++ b/modules/mol/base/pymod/export_residue_view.cc @@ -22,7 +22,7 @@ using namespace boost::python; #include <ost/mol/mol.hh> - +#include <ost/export_helper/vector.hh> using namespace ost; using namespace ost::mol; @@ -48,6 +48,7 @@ void export_ResidueView() { class_<ResidueViewList>("ResidueViewList", no_init) .def(vector_indexing_suite<ResidueViewList>()) + .def(ost::VectorAdditions<ResidueViewList>()) ; void (ResidueView::* apply1)(EntityVisitor&) = &ResidueView::Apply;