src/hugo/sym_map.h
author ladanyi
Tue, 14 Sep 2004 09:02:33 +0000
changeset 846 a7a406fdb006
parent 822 88226d9fe821
child 891 74589d20dbc3
permissions -rw-r--r--
Set 'svn:ignore' property.
deba@822
     1
// -*- c++ -*-
deba@822
     2
#ifndef SYM_MAP_H
deba@822
     3
#define SYM_MAP_H
deba@822
     4
deba@822
     5
///\ingroup graphmaps
deba@822
     6
///\file
deba@822
     7
///\brief Graph maps that construates and destruates
deba@822
     8
///their elements dynamically.
deba@822
     9
deba@822
    10
namespace hugo {
deba@822
    11
deba@822
    12
/// \addtogroup graphmaps
deba@822
    13
/// @{
deba@822
    14
deba@822
    15
  /** The SymEdgeIt is wrapper class for the EdgeIt. It can be used to
deba@822
    16
   *  iterate on the symmetric maps when all of the edge - reverse edge pair
deba@822
    17
   *  has different parity.
deba@822
    18
   */
deba@822
    19
deba@844
    20
deba@822
    21
  template <typename Graph, typename Edge, typename EdgeIt>
deba@822
    22
  class SymEdgeIt : public EdgeIt {
deba@822
    23
  public:
deba@822
    24
deba@822
    25
    /** Default constructor.
deba@822
    26
     */
deba@822
    27
    SymEdgeIt() 
deba@822
    28
      : EdgeIt() {}
deba@822
    29
deba@822
    30
    /** Graph initialized constructor.
deba@822
    31
     */
deba@822
    32
    SymEdgeIt(const Graph& graph) 
deba@822
    33
      : EdgeIt(graph) {
deba@844
    34
      while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
deba@822
    35
	EdgeIt::operator++();
deba@822
    36
      }
deba@822
    37
    }
deba@822
    38
deba@822
    39
    /** Creating invelid SymEdgeIt.
deba@822
    40
     */
deba@822
    41
    SymEdgeIt(Invalid invalid) 
deba@822
    42
      : EdgeIt(invalid) {}
deba@822
    43
deba@822
    44
    /** SymEdgeIt from the given Edge.
deba@822
    45
     */
deba@822
    46
    SymEdgeIt(const Graph& graph, const Edge& edge)
deba@822
    47
      : EdgeIt(graph, edge) {
deba@844
    48
      while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
deba@822
    49
	EdgeIt::operator++();
deba@822
    50
      }
deba@822
    51
    }
deba@822
    52
deba@822
    53
    /** Increase operator.
deba@822
    54
     */
deba@822
    55
    SymEdgeIt& operator++() {
deba@822
    56
      EdgeIt::operator++();
deba@844
    57
      while ( (EdgeIt::n & 1) && EdgeIt::n != -1) {
deba@822
    58
	EdgeIt::operator++();
deba@822
    59
      }
deba@822
    60
      return *this;
deba@822
    61
    }
deba@822
    62
  };
deba@822
    63
deba@822
    64
  /** The SymMap template class is graph map structure what
deba@822
    65
   *  wraps an other map structure to use as symmetric map structure.
deba@822
    66
   *
deba@822
    67
   *  The template parameter is the MapRegistry that the maps
deba@822
    68
   *  will belong to and the ValueType.
deba@822
    69
   */
deba@822
    70
  template <template <typename, typename> class DynMap, 
deba@822
    71
	    typename MapRegistry, typename Value>
deba@822
    72
  class SymMap : public DynMap<MapRegistry, Value>{
deba@822
    73
deba@822
    74
  private:
deba@822
    75
deba@822
    76
    typedef DynMap<MapRegistry, Value> MapImpl;
deba@822
    77
deba@822
    78
  public:
deba@822
    79
		
deba@822
    80
    /// The graph type of the maps. 
deba@822
    81
    typedef typename MapRegistry::Graph Graph;
deba@822
    82
deba@822
    83
    typedef typename MapImpl::KeyType KeyType;
deba@822
    84
deba@822
    85
  public:
deba@822
    86
deba@822
    87
deba@822
    88
    /** Default constructor for the map.
deba@822
    89
     */
deba@822
    90
    SymMap() : MapImpl() {}
deba@822
    91
deba@822
    92
    /** Graph and Registry initialized map constructor.
deba@822
    93
     */
deba@822
    94
    SymMap(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
deba@822
    95
deba@822
    96
    /** Constructor to use default value to initialize the map. 
deba@822
    97
     */
deba@822
    98
    SymMap(const Graph& g, MapRegistry& r, const Value& v) 
deba@822
    99
      : MapImpl(g, r, v) {}
deba@822
   100
deba@822
   101
    /** Constructor to copy a map of the same map type.
deba@822
   102
     */
deba@822
   103
    SymMap(const SymMap& copy) 
deba@822
   104
      : MapImpl(static_cast<const MapImpl&>(copy)) {}
deba@822
   105
deba@822
   106
    /** Constructor to copy a map of an other map type.
deba@822
   107
     */
deba@822
   108
    template <typename CMap> SymMap(const CMap& copy) 
deba@822
   109
      : MapImpl(copy) {}
deba@822
   110
deba@822
   111
    /** Assign operator to copy a map of the same map type.
deba@822
   112
     */
deba@822
   113
    SymMap& operator=(const SymMap& copy) {
deba@822
   114
      MapImpl::operator=(static_cast<const MapImpl&>(copy));
deba@822
   115
      return *this;
deba@822
   116
    }
deba@822
   117
deba@822
   118
    /** Assign operator to copy a map of an other map type.
deba@822
   119
     */
deba@822
   120
    template <typename CMap> SymMap& operator=(const CMap& copy) {
deba@822
   121
      MapImpl::operator=(copy);
deba@822
   122
      return *this;
deba@822
   123
    }
deba@822
   124
   
deba@822
   125
    /** Add a new key to the map. It called by the map registry.
deba@822
   126
     */
deba@822
   127
    void add(const KeyType& key) {
deba@822
   128
      int id = MapImpl::getGraph()->id(key);
deba@822
   129
      if (id & 1) return;
deba@822
   130
      MapImpl::add(key);
deba@822
   131
    }
deba@822
   132
		
deba@822
   133
    /** Erase a key from the map. It called by the map registry.
deba@822
   134
     */
deba@822
   135
    void erase(const KeyType& key) {
deba@822
   136
      int id = MapImpl::getGraph()->id(key);
deba@822
   137
      if (id & 1) return;
deba@822
   138
      MapImpl::add(key);
deba@822
   139
    }
deba@822
   140
  };
deba@822
   141
deba@822
   142
  /// @}
deba@822
   143
}
deba@822
   144
deba@822
   145
#endif