COIN-OR::LEMON - Graph Library

Changeset 2031:080d51024ac5 in lemon-0.x for lemon/bits/graph_extender.h


Ignore:
Timestamp:
04/03/06 11:45:23 (18 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2670
Message:

Correcting the structure of the graph's and adaptor's map.
The template assign operators and map iterators can be used for adaptors also.

Some bugfix in the adaptors

New class SwapBpUGraphAdaptor which swaps the two nodeset of the graph.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/bits/graph_extender.h

    r1999 r2031  
    104104
    105105      explicit NodeIt(const Graph& _graph) : graph(&_graph) {
    106         _graph.first(*static_cast<Node*>(this));
     106        _graph.first(static_cast<Node&>(*this));
    107107      }
    108108
     
    127127
    128128      explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
    129         _graph.first(*static_cast<Edge*>(this));
     129        _graph.first(static_cast<Edge&>(*this));
    130130      }
    131131
     
    233233      }
    234234
    235 
    236       /// \brief Template assign operator.
    237       ///
    238       /// The given parameter should be conform to the ReadMap
    239       /// concecpt and could be indiced by the current item set of
    240       /// the NodeMap. In this case the value for each item
    241       /// is assigned by the value of the given ReadMap.
    242235      template <typename CMap>
    243236      NodeMap& operator=(const CMap& cmap) {
    244         checkConcept<concept::ReadMap<Node, _Value>, CMap>();
    245         const typename Parent::Notifier* notifier = Parent::getNotifier();
    246         Node it;
    247         for (notifier->first(it); it != INVALID; notifier->next(it)) {
    248           Parent::set(it, cmap[it]);
    249         }
     237        Parent::operator=(cmap);
    250238        return *this;
    251239      }
     
    271259      template <typename CMap>
    272260      EdgeMap& operator=(const CMap& cmap) {
    273         checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
    274         const typename Parent::Notifier* notifier = Parent::getNotifier();
    275         Edge it;
    276         for (notifier->first(it); it != INVALID; notifier->next(it)) {
    277           Parent::set(it, cmap[it]);
    278         }
     261        Parent::operator=(cmap);
    279262        return *this;
    280263      }
     
    432415
    433416      explicit NodeIt(const Graph& _graph) : graph(&_graph) {
    434         _graph.first(*static_cast<Node*>(this));
     417        _graph.first(static_cast<Node&>(*this));
    435418      }
    436419
     
    455438
    456439      explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
    457         _graph.first(*static_cast<Edge*>(this));
     440        _graph.first(static_cast<Edge&>(*this));
    458441      }
    459442
     
    526509
    527510      explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {
    528         _graph.first(*static_cast<UEdge*>(this));
     511        _graph.first(static_cast<UEdge&>(*this));
    529512      }
    530513
     
    623606      }
    624607
    625 
    626       /// \brief Template assign operator.
    627       ///
    628       /// The given parameter should be conform to the ReadMap
    629       /// concecpt and could be indiced by the current item set of
    630       /// the NodeMap. In this case the value for each item
    631       /// is assigned by the value of the given ReadMap.
    632608      template <typename CMap>
    633609      NodeMap& operator=(const CMap& cmap) {
    634         checkConcept<concept::ReadMap<Node, _Value>, CMap>();
    635         const typename Parent::Notifier* notifier = Parent::getNotifier();
    636         Node it;
    637         for (notifier->first(it); it != INVALID; notifier->next(it)) {
    638           Parent::set(it, cmap[it]);
    639         }
     610        Parent::operator=(cmap);
    640611        return *this;
    641612      }
     
    661632      template <typename CMap>
    662633      EdgeMap& operator=(const CMap& cmap) {
    663         checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
    664         const typename Parent::Notifier* notifier = Parent::getNotifier();
    665         Edge it;
    666         for (notifier->first(it); it != INVALID; notifier->next(it)) {
    667           Parent::set(it, cmap[it]);
    668         }
     634        Parent::operator=(cmap);
    669635        return *this;
    670636      }
     
    681647      UEdgeMap(const Graph& graph)
    682648        : Parent(graph) {}
     649
    683650      UEdgeMap(const Graph& graph, const _Value& value)
    684651        : Parent(graph, value) {}
     
    690657      template <typename CMap>
    691658      UEdgeMap& operator=(const CMap& cmap) {
    692         checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
    693         const typename Parent::Notifier* notifier = Parent::getNotifier();
    694         Edge it;
    695         for (notifier->first(it); it != INVALID; notifier->next(it)) {
    696           Parent::set(it, cmap[it]);
    697         }
     659        Parent::operator=(cmap);
    698660        return *this;
    699661      }
     662
    700663    };
    701664
     
    11051068      }
    11061069   
    1107 
    1108       /// \brief Template assign operator.
    1109       ///
    1110       /// The given parameter should be conform to the ReadMap
    1111       /// concept and could be indiced by the current item set of
    1112       /// the ANodeMap. In this case the value for each item
    1113       /// is assigned by the value of the given ReadMap.
    11141070      template <typename CMap>
    11151071      ANodeMap& operator=(const CMap& cmap) {
    1116         checkConcept<concept::ReadMap<ANode, _Value>, CMap>();
    1117         const typename Parent::Graph* graph = Parent::getGraph();
    1118         ANode it;
    1119         for (graph->first(it); it != INVALID; graph->next(it)) {
    1120           Parent::set(it, cmap[it]);
    1121         }
     1072        Parent::operator=(cmap);
    11221073        return *this;
    11231074      }
     
    11411092      }
    11421093   
    1143 
    1144       /// \brief Template assign operator.
    1145       ///
    1146       /// The given parameter should be conform to the ReadMap
    1147       /// concept and could be indiced by the current item set of
    1148       /// the BNodeMap. In this case the value for each item
    1149       /// is assigned by the value of the given ReadMap.
    11501094      template <typename CMap>
    11511095      BNodeMap& operator=(const CMap& cmap) {
    1152         checkConcept<concept::ReadMap<BNode, _Value>, CMap>();
    1153         const typename Parent::Graph* graph = Parent::getGraph();
    1154         BNode it;
    1155         for (graph->first(it); it != INVALID; graph->next(it)) {
    1156           Parent::set(it, cmap[it]);
    1157         }
     1096        Parent::operator=(cmap);
    11581097        return *this;
    11591098      }
     
    11611100    };
    11621101
    1163   protected:
     1102  public:
    11641103
    11651104    template <typename _Value>
    1166     class NodeMapBase {
     1105    class NodeMap {
    11671106    public:
    11681107      typedef BpUGraphExtender Graph;
     
    11781117      typedef True ReferenceMapTag;
    11791118
    1180       NodeMapBase(const Graph& graph)
    1181         : aNodeMap(graph), bNodeMap(graph) {}
    1182       NodeMapBase(const Graph& graph, const _Value& value)
    1183         : aNodeMap(graph, value), bNodeMap(graph, value) {}
     1119      NodeMap(const Graph& _graph)
     1120        : graph(_graph), aNodeMap(_graph), bNodeMap(_graph) {}
     1121      NodeMap(const Graph& _graph, const _Value& _value)
     1122        : graph(_graph), aNodeMap(_graph, _value), bNodeMap(_graph, _value) {}
     1123
     1124      NodeMap& operator=(const NodeMap& cmap) {
     1125        return operator=<NodeMap>(cmap);
     1126      }
     1127   
     1128      template <typename CMap>
     1129      NodeMap& operator=(const CMap& cmap) {
     1130        checkConcept<concept::ReadMap<Node, _Value>, CMap>();
     1131        const typename Parent::Notifier* notifier = Parent::getNotifier();
     1132        Edge it;
     1133        for (graph.first(it); it != INVALID; graph.next(it)) {
     1134          Parent::set(it, cmap[it]);
     1135        }
     1136        return *this;
     1137      }
    11841138
    11851139      ConstReference operator[](const Key& node) const {
     
    12071161      }
    12081162
    1209       const Graph* getGraph() const {
    1210         return aNodeMap.getGraph();
    1211       }
    1212 
     1163      class MapIt : public NodeIt {
     1164      public:
     1165
     1166        typedef NodeIt Parent;
     1167       
     1168        explicit MapIt(NodeMap& _map)
     1169          : Parent(_map.graph), map(_map) {}
     1170       
     1171        typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
     1172          return map[*this];
     1173        }
     1174       
     1175        typename MapTraits<NodeMap>::ReturnValue operator*() {
     1176          return map[*this];
     1177        }
     1178       
     1179        void set(const Value& value) {
     1180          map.set(*this, value);
     1181        }
     1182
     1183      private:
     1184        NodeMap& map;
     1185      };
     1186
     1187      class ConstMapIt : public NodeIt {
     1188      public:
     1189
     1190        typedef NodeIt Parent;
     1191       
     1192        explicit ConstMapIt(const NodeMap& _map)
     1193          : Parent(_map.graph), map(_map) {}
     1194       
     1195        typename MapTraits<NodeMap>::ConstReturnValue operator*() const {
     1196          return map[*this];
     1197        }
     1198       
     1199      private:
     1200        const NodeMap& map;
     1201      };
     1202
     1203      class ItemIt : public NodeIt {
     1204      public:
     1205
     1206        typedef NodeIt Parent;
     1207
     1208        explicit ItemIt(const NodeMap& _map)
     1209          : Parent(_map.graph) {}
     1210       
     1211      };
     1212     
    12131213    private:
     1214      const Graph& graph;
    12141215      ANodeMap<_Value> aNodeMap;
    12151216      BNodeMap<_Value> bNodeMap;
    12161217    };
    12171218   
    1218   public:
    1219 
    1220     template <typename _Value>
    1221     class NodeMap
    1222       : public MapExtender<NodeMapBase<_Value> > {
    1223     public:
    1224       typedef BpUGraphExtender Graph;
    1225       typedef MapExtender< NodeMapBase<_Value> > Parent;
    1226    
    1227       NodeMap(const Graph& graph)
    1228         : Parent(graph) {}
    1229       NodeMap(const Graph& graph, const _Value& value)
    1230         : Parent(graph, value) {}
    1231    
    1232       NodeMap& operator=(const NodeMap& cmap) {
    1233         return operator=<NodeMap>(cmap);
    1234       }
    1235    
    1236 
    1237       /// \brief Template assign operator.
    1238       ///
    1239       /// The given parameter should be conform to the ReadMap
    1240       /// concept and could be indiced by the current item set of
    1241       /// the NodeMap. In this case the value for each item
    1242       /// is assigned by the value of the given ReadMap.
    1243       template <typename CMap>
    1244       NodeMap& operator=(const CMap& cmap) {
    1245         checkConcept<concept::ReadMap<Node, _Value>, CMap>();
    1246         const typename Parent::Notifier* notifier = Parent::getNotifier();
    1247         Edge it;
    1248         for (notifier->first(it); it != INVALID; notifier->next(it)) {
    1249           Parent::set(it, cmap[it]);
    1250         }
    1251         return *this;
    1252       }
    1253    
    1254     };
    1255 
    1256 
    12571219
    12581220    template <typename _Value>
     
    12741236      template <typename CMap>
    12751237      EdgeMap& operator=(const CMap& cmap) {
    1276         checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
    1277         const typename Parent::Notifier* notifier = Parent::getNotifier();
    1278         Edge it;
    1279         for (notifier->first(it); it != INVALID; notifier->next(it)) {
    1280           Parent::set(it, cmap[it]);
    1281         }
     1238        Parent::operator=(cmap);
    12821239        return *this;
    12831240      }
     
    13021259      template <typename CMap>
    13031260      UEdgeMap& operator=(const CMap& cmap) {
    1304         checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
    1305         const typename Parent::Notifier* notifier = Parent::getNotifier();
    1306         Edge it;
    1307         for (notifier->first(it); it != INVALID; notifier->next(it)) {
    1308           Parent::set(it, cmap[it]);
    1309         }
     1261        Parent::operator=(cmap);
    13101262        return *this;
    13111263      }
Note: See TracChangeset for help on using the changeset viewer.