author Dmitriy Morozov <>
Thu, 18 Dec 2008 16:43:42 -0800
changeset 97 0a9bd3f34419
parent 61 include/topology/cycle.h@f905b57dd7ab
child 100 884f70adc576
permissions -rw-r--r--
Intermediate commit while converting to the new architecture * Converted Filtration into StaticPersistence and DynamicPersistenceTrails (both right now work with the underlying std::vector rather than std::list order) * Filtration is now just an auxilliary glue (a map between Complex and Persistence) * Whether chains are vectors or lists can be interchanged * Added PersistenceDiagram with a simple bottleneck_distance() function * Converted triangle, alphashapes3d, and cech-complex examples * Lots of organizational changes (factoring utilities out into containers.h, indirect.h, property-maps.h) * Trying to document along the way with NaturalDocs-type comments

 * Author: Dmitriy Morozov
 * Department of Computer Science, Duke University, 2005-2008

#ifndef __CHAIN_H__
#define __CHAIN_H__

//#include "utilities/types.h"
#include <boost/serialization/access.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/iterator/iterator_traits.hpp>
#include <boost/optional.hpp>
#include <iterator>
#include <string>

#include <utilities/containers.h>

 * Class: ChainWrapper
 * Class storing a chain of simplices. Stores items in the order defined by ConsistencyCmp. 
 * The actual order of the elements is defined by OrderCmp. Instances of those 
 * classes are not stored in Chain for efficiency, and are passed as arguments to those methods 
 * that require them.
 * \ingroup topology
 * TODO: add field (defaulting to Z_2)
template <class Container_>
class ChainWrapper: public Container_, 
                    public SizeStorage<Container_>
		/// \name Template Parameters
		/// @{
        typedef         Container_                                                                  Container;
        typedef         typename boost::iterator_value<typename Container::iterator>::type          Item;
		/// @}
		typedef 		ChainWrapper	                                                            Self;
		typedef			Container 										                            ChainRepresentation; 

		/// \name Accessor typedefs
		/// @{
		typedef			typename ChainRepresentation::iterator			                            iterator; 
		typedef			typename ChainRepresentation::const_iterator	                            const_iterator; 
		typedef			typename ChainRepresentation::const_reference	                            const_reference; 
		typedef			typename ChainRepresentation::reference			                            reference; 
		typedef			typename ChainRepresentation::pointer			                            pointer; 
		typedef			typename ChainRepresentation::const_pointer		                            const_pointer; 
        typedef         Item                                                                        value_type;
		/// @}
						                        ChainWrapper(const ChainWrapper& c);
		/// \name Whole Chain operations
		/// @{
		/** Add c to *this assuming both Chains are sorted in increasing order according to cmp. */
        template<class ConsistencyComparison>                        
		Self&			                        add(const Self& c, const ConsistencyComparison& cmp);
        void			                        swap(ChainWrapper& c); 						    ///< Swaps the contents of c and *this (like STL's swap destroys c)
        template<class ConsistencyComparison>
        void			                        sort(const ConsistencyComparison& cmp);			///< Sort elements to enforce consistency

        size_t                                  size() const                                        { return SizeStorage<Container>::size(*this); }

		using 			                        ChainRepresentation::empty;
		using 			                        ChainRepresentation::clear;
        /// @}
		/// \name Modifiers
		/// @{
		using 			                        ChainRepresentation::erase;
        template<class ConsistencyComparison>
		void			                        append(const_reference x, const ConsistencyComparison& cmp);
		/// @}
		/// \name Accessors
		/// @{
		using 			                        ChainRepresentation::begin;
		using 			                        ChainRepresentation::end;
        template<class OrderComparison>
		const_reference	                        top(const OrderComparison& cmp) const;			///< First element in cmp order

		boost::optional<const_iterator>         contains(const_reference x) const;	            ///< tests whether chain contains x
		boost::optional<iterator>               contains(reference x);	                        ///< tests whether chain contains x
		/// @}
		/// \name Debugging
		/// @{
        template<class OrderComparison>
		const_reference                         get_first(const OrderComparison& cmp) const;	///< First element in cmp order

        template<class OutputMap>
        std::string                             tostring(const OutputMap& outmap = OutputMap()) const;
		/// @}
		using 			                        ChainRepresentation::push_back;
		using 			                        ChainRepresentation::insert;
		// Serialization
		typedef			                        Container										    Parent;
		friend class 	                        boost::serialization::access;
		template<class Archive> 
		void			                        serialize(Archive& ar, boost::serialization::version_type );

#include "chain.hpp"

#endif // __CHAIN_H__