bindings/python/chain.cpp
author Dmitriy Morozov <dmitriy@mrzv.org>
Thu, 10 May 2012 14:24:40 -0700
branchdev
changeset 246 88f7806633e0
parent 232 edbbf84fde9e
permissions -rw-r--r--
Exposed init_diagrams() to Python

#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)
    ;
}