Skip to content
Snippets Groups Projects
Commit 80d0acb4 authored by marco's avatar marco
Browse files

__str__ method for lists

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2354 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 2ce23552
No related branches found
No related tags found
No related merge requests found
......@@ -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>())
;
}
......@@ -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
......
#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
......@@ -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)
......
......@@ -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>())
;
}
......@@ -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>())
;
}
......@@ -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;
......
......@@ -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>())
;
}
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment