COIN-OR::LEMON - Graph Library

Ignore:
Location:
lemon
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lemon/bits/map_extender.h

    r765 r867  
    8585      typedef typename Map::Value Value;
    8686
    87       MapIt() {}
    88 
    89       MapIt(Invalid i) : Parent(i) { }
    90 
    91       explicit MapIt(Map& _map) : map(_map) {
    92         map.notifier()->first(*this);
     87      MapIt() : map(NULL) {}
     88
     89      MapIt(Invalid i) : Parent(i), map(NULL) {}
     90
     91      explicit MapIt(Map& _map) : map(&_map) {
     92        map->notifier()->first(*this);
    9393      }
    9494
    9595      MapIt(const Map& _map, const Item& item)
     96        : Parent(item), map(&_map) {}
     97
     98      MapIt& operator++() {
     99        map->notifier()->next(*this);
     100        return *this;
     101      }
     102
     103      typename MapTraits<Map>::ConstReturnValue operator*() const {
     104        return (*map)[*this];
     105      }
     106
     107      typename MapTraits<Map>::ReturnValue operator*() {
     108        return (*map)[*this];
     109      }
     110
     111      void set(const Value& value) {
     112        map->set(*this, value);
     113      }
     114
     115    protected:
     116      Map* map;
     117
     118    };
     119
     120    class ConstMapIt : public Item {
     121      typedef Item Parent;
     122
     123    public:
     124
     125      typedef typename Map::Value Value;
     126
     127      ConstMapIt() : map(NULL) {}
     128
     129      ConstMapIt(Invalid i) : Parent(i), map(NULL) {}
     130
     131      explicit ConstMapIt(Map& _map) : map(&_map) {
     132        map->notifier()->first(*this);
     133      }
     134
     135      ConstMapIt(const Map& _map, const Item& item)
    96136        : Parent(item), map(_map) {}
    97137
    98       MapIt& operator++() {
    99         map.notifier()->next(*this);
     138      ConstMapIt& operator++() {
     139        map->notifier()->next(*this);
    100140        return *this;
    101141      }
     
    105145      }
    106146
    107       typename MapTraits<Map>::ReturnValue operator*() {
    108         return map[*this];
    109       }
    110 
    111       void set(const Value& value) {
    112         map.set(*this, value);
    113       }
    114 
    115     protected:
    116       Map& map;
    117 
    118     };
    119 
    120     class ConstMapIt : public Item {
    121       typedef Item Parent;
    122 
    123     public:
    124 
    125       typedef typename Map::Value Value;
    126 
    127       ConstMapIt() {}
    128 
    129       ConstMapIt(Invalid i) : Parent(i) { }
    130 
    131       explicit ConstMapIt(Map& _map) : map(_map) {
    132         map.notifier()->first(*this);
    133       }
    134 
    135       ConstMapIt(const Map& _map, const Item& item)
    136         : Parent(item), map(_map) {}
    137 
    138       ConstMapIt& operator++() {
    139         map.notifier()->next(*this);
    140         return *this;
    141       }
    142 
    143       typename MapTraits<Map>::ConstReturnValue operator*() const {
    144         return map[*this];
    145       }
    146 
    147     protected:
    148       const Map& map;
     147    protected:
     148      const Map* map;
    149149    };
    150150
     
    153153
    154154    public:
    155 
    156       ItemIt() {}
    157 
    158       ItemIt(Invalid i) : Parent(i) { }
    159 
    160       explicit ItemIt(Map& _map) : map(_map) {
    161         map.notifier()->first(*this);
     155      ItemIt() : map(NULL) {}
     156
     157
     158      ItemIt(Invalid i) : Parent(i), map(NULL) {}
     159
     160      explicit ItemIt(Map& _map) : map(&_map) {
     161        map->notifier()->first(*this);
    162162      }
    163163
    164164      ItemIt(const Map& _map, const Item& item)
    165         : Parent(item), map(_map) {}
     165        : Parent(item), map(&_map) {}
    166166
    167167      ItemIt& operator++() {
    168         map.notifier()->next(*this);
    169         return *this;
    170       }
    171 
    172     protected:
    173       const Map& map;
     168        map->notifier()->next(*this);
     169        return *this;
     170      }
     171
     172    protected:
     173      const Map* map;
    174174
    175175    };
     
    232232      typedef typename Map::Value Value;
    233233
    234       MapIt() {}
    235 
    236       MapIt(Invalid i) : Parent(i) { }
    237 
    238       explicit MapIt(Map& _map) : map(_map) {
    239         map.graph.first(*this);
     234      MapIt() : map(NULL) {}
     235
     236      MapIt(Invalid i) : Parent(i), map(NULL) { }
     237
     238      explicit MapIt(Map& _map) : map(&_map) {
     239        map->graph.first(*this);
    240240      }
    241241
    242242      MapIt(const Map& _map, const Item& item)
    243         : Parent(item), map(_map) {}
     243        : Parent(item), map(&_map) {}
    244244
    245245      MapIt& operator++() {
    246         map.graph.next(*this);
     246        map->graph.next(*this);
    247247        return *this;
    248248      }
    249249
    250250      typename MapTraits<Map>::ConstReturnValue operator*() const {
    251         return map[*this];
     251        return (*map)[*this];
    252252      }
    253253
    254254      typename MapTraits<Map>::ReturnValue operator*() {
    255         return map[*this];
     255        return (*map)[*this];
    256256      }
    257257
    258258      void set(const Value& value) {
    259         map.set(*this, value);
    260       }
    261 
    262     protected:
    263       Map& map;
     259        map->set(*this, value);
     260      }
     261
     262    protected:
     263      Map* map;
    264264
    265265    };
     
    272272      typedef typename Map::Value Value;
    273273
    274       ConstMapIt() {}
    275 
    276       ConstMapIt(Invalid i) : Parent(i) { }
    277 
    278       explicit ConstMapIt(Map& _map) : map(_map) {
    279         map.graph.first(*this);
     274      ConstMapIt() : map(NULL) {}
     275
     276      ConstMapIt(Invalid i) : Parent(i), map(NULL) { }
     277
     278      explicit ConstMapIt(Map& _map) : map(&_map) {
     279        map->graph.first(*this);
    280280      }
    281281
    282282      ConstMapIt(const Map& _map, const Item& item)
    283         : Parent(item), map(_map) {}
     283        : Parent(item), map(&_map) {}
    284284
    285285      ConstMapIt& operator++() {
    286         map.graph.next(*this);
     286        map->graph.next(*this);
    287287        return *this;
    288288      }
    289289
    290290      typename MapTraits<Map>::ConstReturnValue operator*() const {
    291         return map[*this];
    292       }
    293 
    294     protected:
    295       const Map& map;
     291        return (*map)[*this];
     292      }
     293
     294    protected:
     295      const Map* map;
    296296    };
    297297
     
    300300
    301301    public:
    302 
    303       ItemIt() {}
    304 
    305       ItemIt(Invalid i) : Parent(i) { }
    306 
    307       explicit ItemIt(Map& _map) : map(_map) {
    308         map.graph.first(*this);
     302      ItemIt() : map(NULL) {}
     303
     304
     305      ItemIt(Invalid i) : Parent(i), map(NULL) { }
     306
     307      explicit ItemIt(Map& _map) : map(&_map) {
     308        map->graph.first(*this);
    309309      }
    310310
    311311      ItemIt(const Map& _map, const Item& item)
    312         : Parent(item), map(_map) {}
     312        : Parent(item), map(&_map) {}
    313313
    314314      ItemIt& operator++() {
    315         map.graph.next(*this);
    316         return *this;
    317       }
    318 
    319     protected:
    320       const Map& map;
     315        map->graph.next(*this);
     316        return *this;
     317      }
     318
     319    protected:
     320      const Map* map;
    321321
    322322    };
  • lemon/path.h

    r606 r867  
    7171    template <typename CPath>
    7272    Path(const CPath& cpath) {
    73       copyPath(*this, cpath);
     73      pathCopy(cpath, *this);
    7474    }
    7575
     
    7979    template <typename CPath>
    8080    Path& operator=(const CPath& cpath) {
    81       copyPath(*this, cpath);
     81      pathCopy(cpath, *this);
    8282      return *this;
    8383    }
     
    259259    template <typename CPath>
    260260    SimplePath(const CPath& cpath) {
    261       copyPath(*this, cpath);
     261      pathCopy(cpath, *this);
    262262    }
    263263
     
    268268    template <typename CPath>
    269269    SimplePath& operator=(const CPath& cpath) {
    270       copyPath(*this, cpath);
     270      pathCopy(cpath, *this);
    271271      return *this;
    272272    }
     
    438438    template <typename CPath>
    439439    ListPath(const CPath& cpath) : first(0), last(0) {
    440       copyPath(*this, cpath);
     440      pathCopy(cpath, *this);
    441441    }
    442442
     
    454454    template <typename CPath>
    455455    ListPath& operator=(const CPath& cpath) {
    456       copyPath(*this, cpath);
     456      pathCopy(cpath, *this);
    457457      return *this;
    458458    }
     
    764764    template <typename CPath>
    765765    StaticPath(const CPath& cpath) : arcs(0) {
    766       copyPath(*this, cpath);
     766      pathCopy(cpath, *this);
    767767    }
    768768
     
    780780    template <typename CPath>
    781781    StaticPath& operator=(const CPath& cpath) {
    782       copyPath(*this, cpath);
     782      pathCopy(cpath, *this);
    783783      return *this;
    784784    }
     
    929929    };
    930930
    931     template <typename Target, typename Source,
    932               bool buildEnable = BuildTagIndicator<Target>::value>
     931    template <typename From, typename To,
     932              bool buildEnable = BuildTagIndicator<To>::value>
    933933    struct PathCopySelectorForward {
    934       static void copy(Target& target, const Source& source) {
    935         target.clear();
    936         for (typename Source::ArcIt it(source); it != INVALID; ++it) {
    937           target.addBack(it);
     934      static void copy(const From& from, To& to) {
     935        to.clear();
     936        for (typename From::ArcIt it(from); it != INVALID; ++it) {
     937          to.addBack(it);
    938938        }
    939939      }
    940940    };
    941941
    942     template <typename Target, typename Source>
    943     struct PathCopySelectorForward<Target, Source, true> {
    944       static void copy(Target& target, const Source& source) {
    945         target.clear();
    946         target.build(source);
    947       }
    948     };
    949 
    950     template <typename Target, typename Source,
    951               bool buildEnable = BuildTagIndicator<Target>::value>
     942    template <typename From, typename To>
     943    struct PathCopySelectorForward<From, To, true> {
     944      static void copy(const From& from, To& to) {
     945        to.clear();
     946        to.build(from);
     947      }
     948    };
     949
     950    template <typename From, typename To,
     951              bool buildEnable = BuildTagIndicator<To>::value>
    952952    struct PathCopySelectorBackward {
    953       static void copy(Target& target, const Source& source) {
    954         target.clear();
    955         for (typename Source::RevArcIt it(source); it != INVALID; ++it) {
    956           target.addFront(it);
     953      static void copy(const From& from, To& to) {
     954        to.clear();
     955        for (typename From::RevArcIt it(from); it != INVALID; ++it) {
     956          to.addFront(it);
    957957        }
    958958      }
    959959    };
    960960
    961     template <typename Target, typename Source>
    962     struct PathCopySelectorBackward<Target, Source, true> {
    963       static void copy(Target& target, const Source& source) {
    964         target.clear();
    965         target.buildRev(source);
     961    template <typename From, typename To>
     962    struct PathCopySelectorBackward<From, To, true> {
     963      static void copy(const From& from, To& to) {
     964        to.clear();
     965        to.buildRev(from);
    966966      }
    967967    };
    968968
    969969   
    970     template <typename Target, typename Source,
    971               bool revEnable = RevPathTagIndicator<Source>::value>
     970    template <typename From, typename To,
     971              bool revEnable = RevPathTagIndicator<From>::value>
    972972    struct PathCopySelector {
    973       static void copy(Target& target, const Source& source) {
    974         PathCopySelectorForward<Target, Source>::copy(target, source);
     973      static void copy(const From& from, To& to) {
     974        PathCopySelectorForward<From, To>::copy(from, to);
    975975      }     
    976976    };
    977977
    978     template <typename Target, typename Source>
    979     struct PathCopySelector<Target, Source, true> {
    980       static void copy(Target& target, const Source& source) {
    981         PathCopySelectorBackward<Target, Source>::copy(target, source);
     978    template <typename From, typename To>
     979    struct PathCopySelector<From, To, true> {
     980      static void copy(const From& from, To& to) {
     981        PathCopySelectorBackward<From, To>::copy(from, to);
    982982      }     
    983983    };
     
    988988  /// \brief Make a copy of a path.
    989989  ///
    990   ///  This function makes a copy of a path.
    991   template <typename Target, typename Source>
    992   void copyPath(Target& target, const Source& source) {
    993     checkConcept<concepts::PathDumper<typename Source::Digraph>, Source>();
    994     _path_bits::PathCopySelector<Target, Source>::copy(target, source);
     990  /// This function makes a copy of a path.
     991  template <typename From, typename To>
     992  void pathCopy(const From& from, To& to) {
     993    checkConcept<concepts::PathDumper<typename From::Digraph>, From>();
     994    _path_bits::PathCopySelector<From, To>::copy(from, to);
     995  }
     996
     997  /// \brief Deprecated version of \ref pathCopy().
     998  ///
     999  /// Deprecated version of \ref pathCopy() (only for reverse compatibility).
     1000  template <typename To, typename From>
     1001  void copyPath(To& to, const From& from) {
     1002    pathCopy(from, to);
    9951003  }
    9961004
     
    10161024  /// \brief The source of a path
    10171025  ///
    1018   /// This function returns the source of the given path.
     1026  /// This function returns the source node of the given path.
     1027  /// If the path is empty, then it returns \c INVALID.
    10191028  template <typename Digraph, typename Path>
    10201029  typename Digraph::Node pathSource(const Digraph& digraph, const Path& path) {
    1021     return digraph.source(path.front());
     1030    return path.empty() ? INVALID : digraph.source(path.front());
    10221031  }
    10231032
    10241033  /// \brief The target of a path
    10251034  ///
    1026   /// This function returns the target of the given path.
     1035  /// This function returns the target node of the given path.
     1036  /// If the path is empty, then it returns \c INVALID.
    10271037  template <typename Digraph, typename Path>
    10281038  typename Digraph::Node pathTarget(const Digraph& digraph, const Path& path) {
    1029     return digraph.target(path.back());
     1039    return path.empty() ? INVALID : digraph.target(path.back());
    10301040  }
    10311041
Note: See TracChangeset for help on using the changeset viewer.