include/topology/complex-traits.h
author Dmitriy Morozov <dmitriy@mrzv.org>
Fri, 01 May 2009 15:09:38 -0700
branchdev
changeset 125 0a2c2283e4a8
parent 97 0a9bd3f34419
child 179 d15c6d144645
permissions -rw-r--r--
Cleaned up traits (chain and container) for static- and dynamic-persistence

#ifndef __COMPLEX_TRAITS_H__
#define __COMPLEX_TRAITS_H__

#include <vector>
#include <map>
#include "utilities/property-maps.h"

// Class: ComplexTraits
// Class that extracts various properties of a complex.
//
// Parameter:
//   Complex -      the type whose traits we are extracting
template<class Complex_>
struct ComplexTraits
{
    /* 
     * Typedefs: Associated types
     * Types extractable by the traits class.
     *
     * Complex -            the type of the complex
     * Simplex -            the type of the simplex stored in the complex
     * Index -              the type used to refer to the elements of the complex
     * IndexComparison -    the type used to compare indices
     */
    typedef         Complex_                                                Complex;
    typedef         typename Complex::Simplex                               Simplex;
    typedef         typename Complex::Index                                 Index;
    typedef         std::less<Index>                                        IndexComparison;

    /* Typedefs: Maps
     * Maps to go from Indicies to Simplices and back.
     *
     * SimplexIndexMap -    the map from Simplex to the Index (could be implemented via a binary search, or a map)
     */
    typedef         AssociativeMap<std::map<Simplex, Index, 
                                   typename Simplex::VertexComparison> >    SimplexIndexMap;

    // Function: simplex_index_map() 
    // Initializes an SimplexIndexMap given a Complex.
    static SimplexIndexMap
                    simplex_index_map(const Complex& complex)               { return SimplexIndexMap(complex.begin(),
                                                                                                     complex.end()); } 

    static Index    begin(const Complex& complex)                           { return complex.begin(); }
    static Index    end(const Complex& complex)                             { return complex.end(); }
};


// Specializations
template<class Simplex_>
struct ComplexTraits<std::vector<Simplex_> >
{
    typedef         std::vector<Simplex_>                                   Complex;
    typedef         Simplex_                                                Simplex;
    typedef         typename Complex::const_iterator                        Index;
    typedef         std::less<Index>                                        IndexComparison;

    typedef         BinarySearchMap<Simplex, Index,
                                    typename Simplex::VertexComparison>     SimplexIndexMap;

    static SimplexIndexMap
                    simplex_index_map(const Complex& complex)               { return SimplexIndexMap(complex.begin(),
                                                                                                     complex.end()); }
    static SimplexIndexMap
                    simplex_index_map(Index bg, Index end)                  { return SimplexIndexMap(bg, end); }

    static Index    begin(const Complex& complex)                           { return complex.begin(); }
    static Index    end(const Complex& complex)                             { return complex.end(); }
};

#endif // __COMPLEX_TRAITS_H__