Made ListRandomAccessIterator generic with respect to value, and moved it to utils.h
--- a/bindings/python/filtration.cpp Fri Jul 24 11:08:48 2009 -0700
+++ b/bindings/python/filtration.cpp Sun May 17 20:05:26 2009 -0700
@@ -7,7 +7,7 @@
namespace bp = boost::python;
-#include "filtration.h" // defines ListFiltration, ListTraits, ListRandomAccessIterator
+#include "filtration.h" // defines ListFiltration, ListTraits
#include "utils.h" // defines PythonCmp
namespace dp = dionysus::python;
--- a/bindings/python/filtration.h Fri Jul 24 11:08:48 2009 -0700
+++ b/bindings/python/filtration.h Sun May 17 20:05:26 2009 -0700
@@ -4,48 +4,19 @@
#include <topology/filtration.h>
#include <boost/python.hpp>
#include "simplex.h"
+#include "utils.h" // for ListRandomAccessIterator
namespace bp = boost::python;
namespace dionysus {
namespace python {
-// Random access iterator into python's list (using integer indices)
-class ListRandomAccessIterator:
- public boost::iterator_adaptor<ListRandomAccessIterator, // Derived
- boost::counting_iterator<unsigned>, // Base
- SimplexObject, // Value
- boost::use_default,
- SimplexObject>
-{
- public:
- typedef ListRandomAccessIterator Self;
- typedef boost::iterator_adaptor<ListRandomAccessIterator,
- boost::counting_iterator<unsigned>,
- SimplexObject,
- boost::use_default,
- SimplexObject> Parent;
-
- ListRandomAccessIterator() {}
-
- ListRandomAccessIterator(bp::list l, unsigned i):
- Parent(i), l_(l) {}
-
- private:
- friend class boost::iterator_core_access;
- friend class FiltrationPythonIterator;
-
- Parent::reference dereference() const { return bp::object(l_[*(this->base())]); }
-
- bp::list l_;
-};
-
// ComplexTraits describing complexes of type list
struct ListTraits
{
typedef bp::list Complex;
typedef SimplexObject Simplex;
- typedef ListRandomAccessIterator Index;
+ typedef ListRandomAccessIterator<Simplex> Index;
typedef std::less<Index> IndexComparison;
typedef BinarySearchMap<SimplexVD, Index,
--- a/bindings/python/utils.h Fri Jul 24 11:08:48 2009 -0700
+++ b/bindings/python/utils.h Sun May 17 20:05:26 2009 -0700
@@ -7,6 +7,39 @@
namespace dionysus {
namespace python {
+// Random access iterator into python's list (using integer indices)
+template<class Value>
+class ListRandomAccessIterator:
+ public boost::iterator_adaptor<ListRandomAccessIterator<Value>, // Derived
+ boost::counting_iterator<unsigned>, // Base
+ Value, // Value
+ boost::use_default,
+ Value>
+{
+ public:
+ typedef ListRandomAccessIterator Self;
+ typedef boost::iterator_adaptor<ListRandomAccessIterator,
+ boost::counting_iterator<unsigned>,
+ Value,
+ boost::use_default,
+ Value> Parent;
+
+ ListRandomAccessIterator() {}
+
+ ListRandomAccessIterator(bp::list l, unsigned i):
+ Parent(i), l_(l) {}
+
+ private:
+ friend class boost::iterator_core_access;
+ friend class FiltrationPythonIterator;
+
+ typename Parent::reference
+ dereference() const { return bp::object(l_[*(this->base())]); }
+
+ bp::list l_;
+};
+
+// Adaptor of a Pyhon object to act as a C++-style comparison functor
struct PythonCmp
{
template<class T>
@@ -14,7 +47,7 @@
PythonCmp(bp::object cmp): cmp_(cmp) {}
- bp::object cmp_;
+ bp::object cmp_;
};
} } // namespace dionysus::python