include/topology/complex-traits.h
author Dmitriy Morozov <dmitriy@mrzv.org>
Thu, 09 Jul 2009 07:47:22 -0700
branchdev
changeset 141 cda0b85ffc50
parent 97 0a9bd3f34419
child 179 d15c6d144645
permissions -rw-r--r--
Fixed plot.py in tools/plot-values

#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__