COIN-OR::LEMON - Graph Library

Changeset 946:c94ef40a22ce in lemon-0.x for src/lemon/default_map.h


Ignore:
Timestamp:
10/28/04 00:38:50 (19 years ago)
Author:
Mihaly Barasz
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1322
Message:

The graph_factory branch (@ 1321) has been merged to trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/lemon/default_map.h

    r937 r946  
    2424///\ingroup graphmaps
    2525///\file
    26 ///\brief Graph maps that construates and destruates
     26///\brief Graph maps that construct and destruct
    2727///their elements dynamically.
    2828
     
    4242
    4343
    44   /** Macro to implement the DefaultMap.
    45    */
    46 #define DEFAULT_MAP_BODY(DynMap, Value) \
    47 { \
    48 \
    49 public: \
    50 \
    51 typedef DynMap<MapRegistry, Value> Parent; \
    52 \
    53 typedef typename MapRegistry::Graph Graph; \
    54 \
    55 DefaultMap(const Graph& g, MapRegistry& r) : Parent(g, r) {} \
    56 DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \
    57   : Parent(g, r, v) {} \
    58 DefaultMap(const DefaultMap& copy) \
    59   : Parent(static_cast<const Parent&>(copy)) {} \
    60 template <typename TT> \
    61 DefaultMap(const DefaultMap<MapRegistry, TT>& copy) \
    62   : Parent(*copy.getGraph()) { \
    63   if (Parent::getGraph()) { \
    64     for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
    65       Parent::operator[](it) = copy[it]; \
    66     } \
    67   } \
    68 } \
    69 DefaultMap& operator=(const DefaultMap& copy) { \
    70   Parent::operator=(static_cast<const Parent&>(copy)); \
    71   return *this; \
    72 } \
    73 template <typename TT> \
    74 DefaultMap& operator=(const DefaultMap<MapRegistry, TT>& copy) { \
    75   if (Parent::getGraph() != copy.getGraph()) { \
    76     Parent::clear(); \
    77     Parent::MapBase::operator=(copy); \
    78     Parent::construct(); \
    79   } \
    80   if (Parent::getGraph()) { \
    81     for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\
    82       Parent::operator[](it) = copy[it]; \
    83     } \
    84   } \
    85   return *this; \
    86 } \
    87 };
    88 
    89 
    90   template <typename MapRegistry, typename Type>
    91   class DefaultMap : public ArrayMap<MapRegistry, Type>
    92   DEFAULT_MAP_BODY(ArrayMap, Type);
    93 
    94   template <typename MapRegistry>
    95   class DefaultMap<MapRegistry, bool>
    96     : public VectorMap<MapRegistry, bool>
    97   DEFAULT_MAP_BODY(VectorMap, bool);
    98 
    99   template <typename MapRegistry>
    100   class DefaultMap<MapRegistry, char>
    101     : public VectorMap<MapRegistry, char>
    102   DEFAULT_MAP_BODY(VectorMap, char);
    103 
    104   template <typename MapRegistry>
    105   class DefaultMap<MapRegistry, int>
    106     : public VectorMap<MapRegistry, int>
    107   DEFAULT_MAP_BODY(VectorMap, int);
    108 
    109   template <typename MapRegistry>
    110   class DefaultMap<MapRegistry, short>
    111     : public VectorMap<MapRegistry, short>
    112   DEFAULT_MAP_BODY(VectorMap, short);
    113 
    114   template <typename MapRegistry>
    115   class DefaultMap<MapRegistry, long>
    116     : public VectorMap<MapRegistry, long>
    117   DEFAULT_MAP_BODY(VectorMap, long);
    118 
    119   template <typename MapRegistry>
    120   class DefaultMap<MapRegistry, float>
    121     : public VectorMap<MapRegistry, float>
    122   DEFAULT_MAP_BODY(VectorMap, float);
    123 
    124   template <typename MapRegistry>
    125   class DefaultMap<MapRegistry, double>
    126     : public VectorMap<MapRegistry, double>
    127   DEFAULT_MAP_BODY(VectorMap, double);
    128 
    129   template <typename MapRegistry>
    130   class DefaultMap<MapRegistry, long double>
    131     : public VectorMap<MapRegistry, long double>
    132   DEFAULT_MAP_BODY(VectorMap, long double);
    133 
    134   template <typename MapRegistry, typename Type>
    135   class DefaultMap<MapRegistry, Type*>
    136     : public VectorMap<MapRegistry, Type*>
    137   DEFAULT_MAP_BODY(VectorMap, Type*);
     44
     45  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap, typename _Value>
     46  struct DefaultMapSelector {
     47    typedef ArrayMap<_Graph, _Item, _ItemIt, _IdMap, _Value> Map;
     48  };
     49
     50  // bool
     51  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
     52  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, bool> {
     53    typedef VectorMap<_Graph, _Item, _IdMap, bool> Map;
     54  };
     55
     56  // char
     57  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
     58  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, char> {
     59    typedef VectorMap<_Graph, _Item, _IdMap, char> Map;
     60  };
     61
     62  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
     63  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed char> {
     64    typedef VectorMap<_Graph, _Item, _IdMap, signed char> Map;
     65  };
     66
     67  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
     68  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned char> {
     69    typedef VectorMap<_Graph, _Item, _IdMap, unsigned char> Map;
     70  };
     71
     72
     73  // int
     74  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
     75  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed int> {
     76    typedef VectorMap<_Graph, _Item, _IdMap, signed int> Map;
     77  };
     78
     79  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
     80  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned int> {
     81    typedef VectorMap<_Graph, _Item, _IdMap, unsigned int> Map;
     82  };
     83
     84
     85  // short
     86  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
     87  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed short> {
     88    typedef VectorMap<_Graph, _Item, _IdMap, signed short> Map;
     89  };
     90
     91  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
     92  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned short> {
     93    typedef VectorMap<_Graph, _Item, _IdMap, unsigned short> Map;
     94  };
     95
     96
     97  // long
     98  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
     99  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, signed long> {
     100    typedef VectorMap<_Graph, _Item, _IdMap, signed long> Map;
     101  };
     102
     103  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
     104  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, unsigned long> {
     105    typedef VectorMap<_Graph, _Item, _IdMap, unsigned long> Map;
     106  };
     107
     108  // \todo handling long long type
     109
     110
     111  // float
     112  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
     113  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, float> {
     114    typedef VectorMap<_Graph, _Item, _IdMap, float> Map;
     115  };
     116
     117
     118  // double
     119  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
     120  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, double> {
     121    typedef VectorMap<_Graph, _Item, _IdMap,  double> Map;
     122  };
     123
     124
     125  // long double
     126  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap>
     127  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, long double> {
     128    typedef VectorMap<_Graph, _Item, _IdMap, long double> Map;
     129  };
     130
     131
     132  // pointer
     133  template <typename _Graph, typename _Item, typename _ItemIt, typename _IdMap, typename _Ptr>
     134  struct DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Ptr*> {
     135    typedef VectorMap<_Graph, _Item, _IdMap, _Ptr*> Map;
     136  };
     137
     138
     139
     140  template <typename _Graph,
     141            typename _Item,
     142            typename _ItemIt,
     143            typename _IdMap,
     144            typename _Value>
     145  class DefaultMap : public DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map {
     146  public:
     147    typedef typename DefaultMapSelector<_Graph, _Item, _ItemIt, _IdMap, _Value>::Map Parent;
     148    typedef DefaultMap<_Graph, _Item, _ItemIt, _IdMap, bool> Map;
     149   
     150    typedef typename Parent::Graph Graph;
     151    typedef typename Parent::Registry Registry;
     152    typedef typename Parent::ValueType ValueType;
     153
     154    DefaultMap(const Graph& _g, Registry& _r) : Parent(_g, _r) {}
     155    DefaultMap(const Graph& _g, Registry& _r, const ValueType& _v) : Parent(_g, _r, _v) {}
     156  };
     157
     158
     159
     160  template <typename _Base>
     161  class DefaultMappableGraphExtender : public _Base {
     162  public:
     163
     164    typedef DefaultMappableGraphExtender<_Base> Graph;
     165    typedef _Base Parent;
     166
     167    typedef typename Parent::Node Node;
     168    typedef typename Parent::NodeIt NodeIt;
     169    typedef typename Parent::NodeIdMap NodeIdMap;
     170    typedef typename Parent::NodeObserverRegistry NodeObserverRegistry;
     171
     172    typedef typename Parent::Edge Edge;
     173    typedef typename Parent::EdgeIt EdgeIt;
     174    typedef typename Parent::EdgeIdMap EdgeIdMap;
     175    typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry;
     176
     177   
     178
     179    template <typename _Value>
     180    class NodeMap : public DefaultMap<Graph, Node, NodeIt, NodeIdMap, _Value> {
     181    public:
     182      typedef DefaultMappableGraphExtender<_Base> Graph;
     183
     184      typedef typename Graph::Node Node;
     185      typedef typename Graph::NodeIt NodeIt;
     186      typedef typename Graph::NodeIdMap NodeIdMap;
     187
     188      typedef DefaultMap<Graph, Node, NodeIt, NodeIdMap, _Value> Parent;
     189
     190      typedef typename Parent::Graph Graph;
     191      typedef typename Parent::ValueType ValueType;
     192
     193      NodeMap(const Graph& g)
     194        : Parent(g, g.getNodeObserverRegistry()) {}
     195      NodeMap(const Graph& g, const ValueType& v)
     196        : Parent(g, g.getNodeObserverRegistry(), v) {}
     197
     198    };
     199
     200    template <typename _Value>
     201    class EdgeMap : public DefaultMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> {
     202    public:
     203      typedef DefaultMappableGraphExtender<_Base> Graph;
     204
     205      typedef typename Graph::Edge Edge;
     206      typedef typename Graph::EdgeIt EdgeIt;
     207      typedef typename Graph::EdgeIdMap EdgeIdMap;
     208
     209      typedef DefaultMap<Graph, Edge, EdgeIt, EdgeIdMap, _Value> Parent;
     210
     211      typedef typename Parent::Graph Graph;
     212      typedef typename Parent::ValueType ValueType;
     213
     214      EdgeMap(const Graph& g)
     215        : Parent(g, g.getEdgeObserverRegistry()) {}
     216      EdgeMap(const Graph& g, const ValueType& v)
     217        : Parent(g, g.getEdgeObserverRegistry(), v) {}
     218
     219    };
     220   
     221  };
     222
    138223
    139224}
Note: See TracChangeset for help on using the changeset viewer.