src/lemon/default_map.h
author ladanyi
Mon, 11 Oct 2004 18:02:48 +0000
changeset 942 75fdd0c6866d
parent 921 818510fa3d99
child 946 c94ef40a22ce
permissions -rw-r--r--
Naming and coding style fixes and various other changes.
alpar@906
     1
/* -*- C++ -*-
alpar@921
     2
 * src/lemon/default_map.h - Part of LEMON, a generic C++ optimization library
alpar@906
     3
 *
alpar@906
     4
 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@906
     5
 * (Egervary Combinatorial Optimization Research Group, EGRES).
alpar@906
     6
 *
alpar@906
     7
 * Permission to use, modify and distribute this software is granted
alpar@906
     8
 * provided that this copyright notice appears in all copies. For
alpar@906
     9
 * precise terms see the accompanying LICENSE file.
alpar@906
    10
 *
alpar@906
    11
 * This software is provided "AS IS" with no warranty of any kind,
alpar@906
    12
 * express or implied, and with no claim as to its suitability for any
alpar@906
    13
 * purpose.
alpar@906
    14
 *
alpar@906
    15
 */
alpar@906
    16
alpar@921
    17
#ifndef LEMON_DEFAULT_MAP_H
alpar@921
    18
#define LEMON_DEFAULT_MAP_H
deba@822
    19
deba@822
    20
alpar@921
    21
#include <lemon/array_map.h>
alpar@921
    22
#include <lemon/vector_map.h>
deba@822
    23
deba@822
    24
///\ingroup graphmaps
deba@822
    25
///\file
deba@822
    26
///\brief Graph maps that construates and destruates
deba@822
    27
///their elements dynamically.
deba@822
    28
alpar@921
    29
namespace lemon {
deba@822
    30
deba@822
    31
/// \addtogroup graphmaps
deba@822
    32
/// @{
deba@822
    33
deba@822
    34
  /** The ArrayMap template class is graph map structure what
deba@822
    35
   *  automatically updates the map when a key is added to or erased from
deba@822
    36
   *  the map. This map uses the VectorMap if the ValueType is a primitive
deba@822
    37
   *  type and the ArrayMap for the other cases.
deba@822
    38
   *
deba@822
    39
   *  The template parameter is the MapRegistry that the maps
deba@822
    40
   *  will belong to and the ValueType.
deba@822
    41
   */
deba@822
    42
deba@822
    43
deba@822
    44
  /** Macro to implement the DefaultMap.
deba@822
    45
   */
deba@822
    46
#define DEFAULT_MAP_BODY(DynMap, Value) \
deba@891
    47
{ \
deba@891
    48
\
deba@891
    49
public: \
deba@891
    50
\
deba@891
    51
typedef DynMap<MapRegistry, Value> Parent; \
deba@891
    52
\
deba@891
    53
typedef typename MapRegistry::Graph Graph; \
deba@891
    54
\
deba@891
    55
DefaultMap(const Graph& g, MapRegistry& r) : Parent(g, r) {} \
deba@891
    56
DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
deba@891
    57
  : Parent(g, r, v) {} \
deba@891
    58
DefaultMap(const DefaultMap& copy) \
deba@891
    59
  : Parent(static_cast<const Parent&>(copy)) {} \
deba@891
    60
template <typename TT> \
deba@897
    61
DefaultMap(const DefaultMap<MapRegistry, TT>& copy) \
deba@937
    62
  : Parent(*copy.getGraph()) { \
deba@891
    63
  if (Parent::getGraph()) { \
deba@891
    64
    for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
deba@891
    65
      Parent::operator[](it) = copy[it]; \
deba@822
    66
    } \
deba@891
    67
  } \
deba@891
    68
} \
deba@891
    69
DefaultMap& operator=(const DefaultMap& copy) { \
deba@891
    70
  Parent::operator=(static_cast<const Parent&>(copy)); \
deba@891
    71
  return *this; \
deba@891
    72
} \
deba@891
    73
template <typename TT> \
deba@891
    74
DefaultMap& operator=(const DefaultMap<MapRegistry, TT>& copy) { \
deba@897
    75
  if (Parent::getGraph() != copy.getGraph()) { \
deba@897
    76
    Parent::clear(); \
deba@897
    77
    Parent::MapBase::operator=(copy); \
deba@897
    78
    Parent::construct(); \
deba@897
    79
  } \
deba@891
    80
  if (Parent::getGraph()) { \
deba@891
    81
    for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
deba@891
    82
      Parent::operator[](it) = copy[it]; \
deba@822
    83
    } \
deba@891
    84
  } \
deba@891
    85
  return *this; \
deba@891
    86
} \
deba@891
    87
};
deba@822
    88
deba@822
    89
deba@822
    90
  template <typename MapRegistry, typename Type>
deba@822
    91
  class DefaultMap : public ArrayMap<MapRegistry, Type> 
deba@822
    92
  DEFAULT_MAP_BODY(ArrayMap, Type);
deba@822
    93
deba@822
    94
  template <typename MapRegistry>
deba@822
    95
  class DefaultMap<MapRegistry, bool> 
deba@822
    96
    : public VectorMap<MapRegistry, bool> 
deba@822
    97
  DEFAULT_MAP_BODY(VectorMap, bool);
deba@822
    98
deba@822
    99
  template <typename MapRegistry>
deba@822
   100
  class DefaultMap<MapRegistry, char> 
deba@822
   101
    : public VectorMap<MapRegistry, char> 
deba@822
   102
  DEFAULT_MAP_BODY(VectorMap, char);
deba@822
   103
deba@822
   104
  template <typename MapRegistry>
deba@822
   105
  class DefaultMap<MapRegistry, int> 
deba@822
   106
    : public VectorMap<MapRegistry, int> 
deba@822
   107
  DEFAULT_MAP_BODY(VectorMap, int);
deba@822
   108
deba@822
   109
  template <typename MapRegistry>
deba@822
   110
  class DefaultMap<MapRegistry, short> 
deba@822
   111
    : public VectorMap<MapRegistry, short> 
deba@822
   112
  DEFAULT_MAP_BODY(VectorMap, short);
deba@822
   113
deba@822
   114
  template <typename MapRegistry>
deba@822
   115
  class DefaultMap<MapRegistry, long> 
deba@822
   116
    : public VectorMap<MapRegistry, long> 
deba@822
   117
  DEFAULT_MAP_BODY(VectorMap, long);
deba@822
   118
deba@822
   119
  template <typename MapRegistry>
deba@822
   120
  class DefaultMap<MapRegistry, float> 
deba@822
   121
    : public VectorMap<MapRegistry, float> 
deba@822
   122
  DEFAULT_MAP_BODY(VectorMap, float);
deba@822
   123
deba@822
   124
  template <typename MapRegistry>
deba@822
   125
  class DefaultMap<MapRegistry, double> 
deba@822
   126
    : public VectorMap<MapRegistry, double> 
deba@822
   127
  DEFAULT_MAP_BODY(VectorMap, double);
deba@822
   128
deba@822
   129
  template <typename MapRegistry>
deba@822
   130
  class DefaultMap<MapRegistry, long double> 
deba@822
   131
    : public VectorMap<MapRegistry, long double> 
deba@822
   132
  DEFAULT_MAP_BODY(VectorMap, long double);
deba@822
   133
deba@822
   134
  template <typename MapRegistry, typename Type>
deba@822
   135
  class DefaultMap<MapRegistry, Type*>
deba@822
   136
    : public VectorMap<MapRegistry, Type*> 
deba@822
   137
  DEFAULT_MAP_BODY(VectorMap, Type*);
deba@822
   138
deba@822
   139
}
deba@822
   140
deba@822
   141
#endif