lemon/bits/map_extender.h
changeset 899 7d166b8b8018
parent 801 e9c203fb003d
parent 718 703ebf476a1d
child 1092 dceba191c00d
equal deleted inserted replaced
9:05423e998490 10:0892aae34377
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     2  *
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library.
     3  * This file is a part of LEMON, a generic C++ optimization library.
     4  *
     4  *
     5  * Copyright (C) 2003-2008
     5  * Copyright (C) 2003-2009
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     8  *
     9  * Permission to use, modify and distribute this software is granted
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    10  * provided that this copyright notice appears in all copies. For
    34   // \ingroup graphbits
    34   // \ingroup graphbits
    35   //
    35   //
    36   // \brief Extender for maps
    36   // \brief Extender for maps
    37   template <typename _Map>
    37   template <typename _Map>
    38   class MapExtender : public _Map {
    38   class MapExtender : public _Map {
    39   public:
       
    40 
       
    41     typedef _Map Parent;
    39     typedef _Map Parent;
       
    40     typedef typename Parent::GraphType GraphType;
       
    41 
       
    42   public:
       
    43 
    42     typedef MapExtender Map;
    44     typedef MapExtender Map;
    43 
       
    44 
       
    45     typedef typename Parent::Graph Graph;
       
    46     typedef typename Parent::Key Item;
    45     typedef typename Parent::Key Item;
    47 
    46 
    48     typedef typename Parent::Key Key;
    47     typedef typename Parent::Key Key;
    49     typedef typename Parent::Value Value;
    48     typedef typename Parent::Value Value;
       
    49     typedef typename Parent::Reference Reference;
       
    50     typedef typename Parent::ConstReference ConstReference;
       
    51 
       
    52     typedef typename Parent::ReferenceMapTag ReferenceMapTag;
    50 
    53 
    51     class MapIt;
    54     class MapIt;
    52     class ConstMapIt;
    55     class ConstMapIt;
    53 
    56 
    54     friend class MapIt;
    57     friend class MapIt;
    55     friend class ConstMapIt;
    58     friend class ConstMapIt;
    56 
    59 
    57   public:
    60   public:
    58 
    61 
    59     MapExtender(const Graph& graph)
    62     MapExtender(const GraphType& graph)
    60       : Parent(graph) {}
    63       : Parent(graph) {}
    61 
    64 
    62     MapExtender(const Graph& graph, const Value& value)
    65     MapExtender(const GraphType& graph, const Value& value)
    63       : Parent(graph, value) {}
    66       : Parent(graph, value) {}
    64 
    67 
    65   private:
    68   private:
    66     MapExtender& operator=(const MapExtender& cmap) {
    69     MapExtender& operator=(const MapExtender& cmap) {
    67       return operator=<MapExtender>(cmap);
    70       return operator=<MapExtender>(cmap);
    73       return *this;
    76       return *this;
    74     }
    77     }
    75 
    78 
    76   public:
    79   public:
    77     class MapIt : public Item {
    80     class MapIt : public Item {
    78     public:
    81       typedef Item Parent;
    79 
    82 
    80       typedef Item Parent;
    83     public:
       
    84 
    81       typedef typename Map::Value Value;
    85       typedef typename Map::Value Value;
    82 
    86 
    83       MapIt() : map(NULL) {}
    87       MapIt() : map(NULL) {}
    84 
    88 
    85       MapIt(Invalid i) : Parent(i), map(NULL) {}
    89       MapIt(Invalid i) : Parent(i), map(NULL) {}
   112       Map* map;
   116       Map* map;
   113 
   117 
   114     };
   118     };
   115 
   119 
   116     class ConstMapIt : public Item {
   120     class ConstMapIt : public Item {
   117     public:
   121       typedef Item Parent;
   118 
   122 
   119       typedef Item Parent;
   123     public:
   120 
   124 
   121       typedef typename Map::Value Value;
   125       typedef typename Map::Value Value;
   122 
   126 
   123       ConstMapIt() : map(NULL) {}
   127       ConstMapIt() : map(NULL) {}
   124 
   128 
   143     protected:
   147     protected:
   144       const Map* map;
   148       const Map* map;
   145     };
   149     };
   146 
   150 
   147     class ItemIt : public Item {
   151     class ItemIt : public Item {
   148     public:
   152       typedef Item Parent;
   149 
   153 
   150       typedef Item Parent;
   154     public:
   151 
       
   152       ItemIt() : map(NULL) {}
   155       ItemIt() : map(NULL) {}
       
   156 
   153 
   157 
   154       ItemIt(Invalid i) : Parent(i), map(NULL) {}
   158       ItemIt(Invalid i) : Parent(i), map(NULL) {}
   155 
   159 
   156       explicit ItemIt(Map& _map) : map(&_map) {
   160       explicit ItemIt(Map& _map) : map(&_map) {
   157         map->notifier()->first(*this);
   161         map->notifier()->first(*this);
   174   // \ingroup graphbits
   178   // \ingroup graphbits
   175   //
   179   //
   176   // \brief Extender for maps which use a subset of the items.
   180   // \brief Extender for maps which use a subset of the items.
   177   template <typename _Graph, typename _Map>
   181   template <typename _Graph, typename _Map>
   178   class SubMapExtender : public _Map {
   182   class SubMapExtender : public _Map {
   179   public:
       
   180 
       
   181     typedef _Map Parent;
   183     typedef _Map Parent;
       
   184     typedef _Graph GraphType;
       
   185 
       
   186   public:
       
   187 
   182     typedef SubMapExtender Map;
   188     typedef SubMapExtender Map;
   183 
       
   184     typedef _Graph Graph;
       
   185 
       
   186     typedef typename Parent::Key Item;
   189     typedef typename Parent::Key Item;
   187 
   190 
   188     typedef typename Parent::Key Key;
   191     typedef typename Parent::Key Key;
   189     typedef typename Parent::Value Value;
   192     typedef typename Parent::Value Value;
       
   193     typedef typename Parent::Reference Reference;
       
   194     typedef typename Parent::ConstReference ConstReference;
       
   195 
       
   196     typedef typename Parent::ReferenceMapTag ReferenceMapTag;
   190 
   197 
   191     class MapIt;
   198     class MapIt;
   192     class ConstMapIt;
   199     class ConstMapIt;
   193 
   200 
   194     friend class MapIt;
   201     friend class MapIt;
   195     friend class ConstMapIt;
   202     friend class ConstMapIt;
   196 
   203 
   197   public:
   204   public:
   198 
   205 
   199     SubMapExtender(const Graph& _graph)
   206     SubMapExtender(const GraphType& _graph)
   200       : Parent(_graph), graph(_graph) {}
   207       : Parent(_graph), graph(_graph) {}
   201 
   208 
   202     SubMapExtender(const Graph& _graph, const Value& _value)
   209     SubMapExtender(const GraphType& _graph, const Value& _value)
   203       : Parent(_graph, _value), graph(_graph) {}
   210       : Parent(_graph, _value), graph(_graph) {}
   204 
   211 
   205   private:
   212   private:
   206     SubMapExtender& operator=(const SubMapExtender& cmap) {
   213     SubMapExtender& operator=(const SubMapExtender& cmap) {
   207       return operator=<MapExtender>(cmap);
   214       return operator=<MapExtender>(cmap);
   217       return *this;
   224       return *this;
   218     }
   225     }
   219 
   226 
   220   public:
   227   public:
   221     class MapIt : public Item {
   228     class MapIt : public Item {
   222     public:
   229       typedef Item Parent;
   223 
   230 
   224       typedef Item Parent;
   231     public:
   225       typedef typename Map::Value Value;
   232       typedef typename Map::Value Value;
   226 
   233 
   227       MapIt() : map(NULL) {}
   234       MapIt() : map(NULL) {}
   228 
   235 
   229       MapIt(Invalid i) : Parent(i), map(NULL) { }
   236       MapIt(Invalid i) : Parent(i), map(NULL) { }
   256       Map* map;
   263       Map* map;
   257 
   264 
   258     };
   265     };
   259 
   266 
   260     class ConstMapIt : public Item {
   267     class ConstMapIt : public Item {
   261     public:
   268       typedef Item Parent;
   262 
   269 
   263       typedef Item Parent;
   270     public:
   264 
   271 
   265       typedef typename Map::Value Value;
   272       typedef typename Map::Value Value;
   266 
   273 
   267       ConstMapIt() : map(NULL) {}
   274       ConstMapIt() : map(NULL) {}
   268 
   275 
   287     protected:
   294     protected:
   288       const Map* map;
   295       const Map* map;
   289     };
   296     };
   290 
   297 
   291     class ItemIt : public Item {
   298     class ItemIt : public Item {
   292     public:
   299       typedef Item Parent;
   293 
   300 
   294       typedef Item Parent;
   301     public:
   295 
       
   296       ItemIt() : map(NULL) {}
   302       ItemIt() : map(NULL) {}
       
   303 
   297 
   304 
   298       ItemIt(Invalid i) : Parent(i), map(NULL) { }
   305       ItemIt(Invalid i) : Parent(i), map(NULL) { }
   299 
   306 
   300       explicit ItemIt(Map& _map) : map(&_map) {
   307       explicit ItemIt(Map& _map) : map(&_map) {
   301         map->graph.first(*this);
   308         map->graph.first(*this);
   314 
   321 
   315     };
   322     };
   316 
   323 
   317   private:
   324   private:
   318 
   325 
   319     const Graph& graph;
   326     const GraphType& graph;
   320 
   327 
   321   };
   328   };
   322 
   329 
   323 }
   330 }
   324 
   331