Changed Simplex::boundary() to be iterator-based (replaced it with boundary_begin() and boundary_end()) dev
authorDmitriy Morozov <dmitriy@mrzv.org>
Tue, 23 Dec 2008 11:40:38 -0800
branchdev
changeset 101 9efac05d629b
parent 97 0a9bd3f34419
child 102 0a9729f0fcbe
Changed Simplex::boundary() to be iterator-based (replaced it with boundary_begin() and boundary_end())
include/topology/filtration.h
include/topology/filtration.hpp
include/topology/simplex.h
include/topology/simplex.hpp
--- a/include/topology/filtration.h	Thu Dec 18 16:43:42 2008 -0800
+++ b/include/topology/filtration.h	Tue Dec 23 11:40:38 2008 -0800
@@ -27,7 +27,6 @@
         typedef                 typename ComplexTraits::Index                   ComplexIndex;
         typedef                 typename ComplexTraits::Simplex                 Simplex;
         typedef                 typename ComplexTraits::SimplexIndexMap         SimplexIndexMap;
-        typedef                 typename Simplex::Boundary                      SimplexBoundary;
         typedef                 std::vector<IntermediateIndex>                  IndexBoundary;
 
         // Typedefs: Order
--- a/include/topology/filtration.hpp	Thu Dec 18 16:43:42 2008 -0800
+++ b/include/topology/filtration.hpp	Tue Dec 23 11:40:38 2008 -0800
@@ -22,11 +22,10 @@
 boundary(const Index& i, Cycle& bdry, const Map& map) const
 {
     AssertMsg(bdry.empty(), "We are initializing the boundary from scratch");
-    SimplexBoundary simplex_bdry = (*i)->boundary();
-    ContainerTraits<Cycle>::reserve(bdry, simplex_bdry.size());
+    ContainerTraits<Cycle>::reserve(bdry, (*i)->boundary_end() - (*i)->boundary_begin());
     typename Map::template rebind_from<IntermediateIndex>::other    order_bdry_map(0, map.to());
 
-    for (typename SimplexBoundary::const_iterator cur = simplex_bdry.begin(); cur != simplex_bdry.end(); ++cur)
+    for (typename Simplex::BoundaryIterator cur = (*i)->boundary_begin(); cur != (*i)->boundary_end(); ++cur)
     {
         //std::cout << *cur << std::endl;
         //std::cout << simplex_index_map_[*cur] - complex_order_map_.from() << std::endl;
--- a/include/topology/simplex.h	Thu Dec 18 16:43:42 2008 -0800
+++ b/include/topology/simplex.h	Tue Dec 23 11:40:38 2008 -0800
@@ -14,6 +14,7 @@
 #include "utilities/types.h"
 
 #include <boost/compressed_pair.hpp>
+#include <boost/iterator/iterator_adaptor.hpp>
 #include <boost/serialization/access.hpp>
 
 
@@ -43,8 +44,8 @@
 		typedef		V																Vertex;
         typedef     T                                                               Data;
 		typedef		Simplex<Vertex, Data>										    Self;
-		typedef		std::list<Self>													Boundary;
-		
+		class BoundaryIterator;
+
         /* Typedefs: Internal representation
          *
          *    VertexContainer -     internal representation of the vertices
@@ -84,9 +85,10 @@
 		/// \name Core 
 		/// @{
         ///
-        /// Function: boundary()
-        /// Returns the boundary of the simplex (of type Boundary)
-		Boundary			    boundary() const;
+        /// Functions: boundary_begin(), boundary_end()
+        /// Returns the iterators over the boundary of the simplex
+        BoundaryIterator        boundary_begin() const;
+        BoundaryIterator        boundary_end() const;
         /// Function: dimension()
         /// Returns the dimension of the simplex
 		Dimension				dimension() const									{ return vertices().size() - 1; }
@@ -102,10 +104,10 @@
 		void					add(const Vertex& v);
         template<class Iterator>
         void                    join(Iterator bg, Iterator end);
-        void                    join(const Self& other)                             { join(other.vertices.begin(), other.vertices().end()); }
+        void                    join(const Self& other)                             { join(other.vertices().begin(), other.vertices().end()); }
 		/// @}
 
-		const Self&				operator=(const Self& s)							{ vdpair_ = s.vdpair_; return *this; }
+		Self&				    operator=(const Self& s)							{ vdpair_ = s.vdpair_; return *this; }
 
 		std::ostream&			operator<<(std::ostream& out) const;
 
--- a/include/topology/simplex.hpp	Thu Dec 18 16:43:42 2008 -0800
+++ b/include/topology/simplex.hpp	Tue Dec 23 11:40:38 2008 -0800
@@ -7,22 +7,54 @@
 
 /* Implementations */
 
+template<class V, class T>
+struct Simplex<V,T>::BoundaryIterator: public boost::iterator_adaptor<BoundaryIterator,                                 // Derived
+                                                                      typename VertexContainer::const_iterator,         // Base
+                                                                      Simplex<V,T>,                                     // Value
+                                                                      boost::use_default,
+                                                                      Simplex<V,T> >
+{
+    public:
+        typedef     typename VertexContainer::const_iterator                Iterator;
+        typedef     boost::iterator_adaptor<BoundaryIterator,
+                                            Iterator,
+                                            Simplex<V,T>,
+                                            boost::use_default,
+                                            Simplex<V,T> >                  Parent;
+                    
+                    BoundaryIterator()                                      {}
+        explicit    BoundaryIterator(Iterator iter, const VertexContainer& vertices):
+                        Parent(iter), vertices_(vertices)                   {}
+    
+    private:
+        friend class    boost::iterator_core_access;
+        Simplex<V,T>    dereference() const                                 
+        { 
+            typedef     std::not_equal_to<Vertex>                           NotEqualVertex;
+
+            return      Self(boost::make_filter_iterator(std::bind2nd(NotEqualVertex(), *(this->base())), vertices_.begin(), vertices_.end()),
+                             boost::make_filter_iterator(std::bind2nd(NotEqualVertex(), *(this->base())), vertices_.end(),   vertices_.end()));
+        }
+        
+        const VertexContainer&      vertices_;
+};
+
 /* Simplex */
 template<class V, class T>
-typename Simplex<V,T>::Boundary	
+typename Simplex<V,T>::BoundaryIterator
 Simplex<V,T>::
-boundary() const
+boundary_begin() const
 {
-    typedef         std::not_equal_to<Vertex>                           NotEqualVertex;
+    if (dimension() == 0)   return boundary_end();
+    return BoundaryIterator(vertices().begin(), vertices());
+}
 
-	Boundary bdry;
-    if (dimension() == 0) return bdry;
-	
-    for (typename VertexContainer::const_iterator cur = vertices().begin(); cur != vertices().end(); ++cur)
-        bdry.push_back(Self(boost::make_filter_iterator(std::bind2nd(NotEqualVertex(), *cur), vertices().begin(), vertices().end()),
-                            boost::make_filter_iterator(std::bind2nd(NotEqualVertex(), *cur), vertices().end(),   vertices().end())));
-	
-    return bdry;
+template<class V, class T>
+typename Simplex<V,T>::BoundaryIterator
+Simplex<V,T>::
+boundary_end() const
+{
+    return BoundaryIterator(vertices().end(), vertices());
 }
 
 template<class V, class T>