author Dmitriy Morozov <>
Fri, 21 Aug 2009 14:26:56 -0700
changeset 166 1f3d54b2315b
parent 130 580eaa850c4f
child 181 1ee6edc17cb6
permissions -rw-r--r--
Exposed store argument to CohomologyPersistence.add() in Python

#ifndef __PYTHON_SIMPLEX_H__
#define __PYTHON_SIMPLEX_H__

#include <topology/simplex.h>

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

namespace dionysus {
namespace python   {

 * SimplexVD is a base class for Python simplices (it's exposed to python as Simplex)
 * SimplexObject is the representation of Python simplices in C++; i.e. it wraps bp::object and exposes a simplex-like interface.
typedef                             int                                         Vertex;
// typedef                             double                                      Data;
typedef                             Empty<>                                     Data;
typedef                             Simplex<Vertex, Data>                       SimplexVD;

// Wrapper around bp::object that acts like a simplex
class SimplexObject: public bp::object
        typedef                 SimplexObject                                   Self;
        typedef                 bp::object                                      Parent;
        typedef                 SimplexVD::BoundaryIterator                     BoundaryIterator;

                                SimplexObject(Parent o = Parent()): Parent(o)   {}

        BoundaryIterator        boundary_begin() const                          { return bp::extract<const SimplexVD&>(*this)().boundary_begin(); }
        BoundaryIterator        boundary_end() const                            { return bp::extract<const SimplexVD&>(*this)().boundary_end(); }

                                operator SimplexVD() const                      { return bp::extract<const SimplexVD&>(*this); }
                                operator bp::object() const                     { return *this; }

        bp::object              getattribute(const char* name) const            { return this->attr(name); }

        class                   VertexComparison: public SimplexVD::VertexComparison
                typedef         Self                                            first_argument_type;
                typedef         Self                                            second_argument_type;
                typedef         bool                                            result_type;

                bool            operator()(const SimplexObject& s1, const SimplexObject& s2) const  
                { return SimplexVD::VertexComparison::operator()(bp::extract<const SimplexVD&>(s1), bp::extract<const SimplexVD&>(s2)); }

struct SimplexObjectToSimplexVD
    static PyObject* convert (const SimplexObject& so)
        return (PyObject*) &so;

} } // namespace dionysus::python