bindings/python/chain.cpp
author Dmitriy Morozov <dmitriy@mrzv.org>
Tue, 27 Jun 2017 09:38:20 -0700
changeset 286 0496c5f88b2a
parent 232 edbbf84fde9e
permissions -rw-r--r--
Remove 'hg up tip' from doc/get-build-install.rst

#include <boost/iterator/indirect_iterator.hpp>

#include <boost/python.hpp>
#include <boost/python/iterator.hpp>
#include <boost/python/return_internal_reference.hpp>
namespace bp = boost::python;

#include "chain.h"
namespace dp = dionysus::python;


template<class Chain>
boost::indirect_iterator<typename Chain::const_iterator>    chain_begin(Chain& c)                  { return boost::make_indirect_iterator(c.begin()); }

template<class Chain>
boost::indirect_iterator<typename Chain::const_iterator>    chain_end(Chain& c)                    { return boost::make_indirect_iterator(c.end()); }

void export_chain()
{
    bp::class_<dp::VSPChain>("SPChain")
        .def("__iter__",    bp::range<bp::return_internal_reference<1> >(&chain_begin<dp::VSPChain>, &chain_end<dp::VSPChain>))
        .def("__len__",     &dp::VSPChain::size)
    ;
    
    bp::class_<dp::VDPChain>("DPChain")
        .def("__iter__",    bp::range<bp::return_internal_reference<1> >(&chain_begin<dp::VDPChain>, &chain_end<dp::VDPChain>))
        .def("__len__",     &dp::VDPChain::size)
    ;
}