COIN-OR::LEMON - Graph Library

Changeset 799:3393abe30678 in lemon-0.x


Ignore:
Timestamp:
09/03/04 17:32:03 (16 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1093
Message:
 
Location:
src/hugo
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/hugo/array_map_factory.h

    r786 r799  
    1313
    1414namespace hugo {
    15        
     15
     16
    1617/// \addtogroup graphmapfactory
    1718/// @{
    18 
    19   ///.
    20   template <typename MapRegistry> class ArrayMapFactory {
     19       
     20  /** The ArrayMapFactory template class is a factory class
     21   *  to create maps for the edge and nodes. This map factory
     22   *  uses the allocators to implement the container function.
     23   *
     24   *  The template parameter is the MapRegistry that the maps
     25   *  will belong to.
     26   */
     27
     28  template <typename MapRegistry>
     29  class ArrayMapFactory {
    2130               
    2231  public:
    2332               
     33    /// The graph type of the maps.
    2434    typedef typename MapRegistry::Graph Graph;
     35    /// The key type of the maps.
    2536    typedef typename MapRegistry::KeyType KeyType;
     37    /// The iterator to iterate on the keys.
    2638    typedef typename MapRegistry::KeyIt KeyIt;
    2739
     40    /// The MapBase of the Map which imlements the core regisitry function.
    2841    typedef typename MapRegistry::MapBase MapBase;
    2942               
     43    /** The template Map type.
     44     */
    3045    template <typename V, typename A = std::allocator<V> >
    3146    class Map : public MapBase {
     
    3348      public:
    3449
     50      /// The value type of the map.
     51      typedef V ValueType;
     52
     53      /// The value type of the map.
    3554      typedef V Value;
    36       typedef V ValueType;
     55      /// The reference type of the map;
     56      typedef Value& Reference;
     57      /// The pointer type of the map;
     58      typedef Value* Pointer;
     59
     60      /// The const value type of the map.
     61      typedef const Value ConstValue;
     62      /// The const reference type of the map;
     63      typedef const Value& ConstReference;
     64      /// The pointer type of the map;
     65      typedef const Value* ConstPointer;
     66
     67
    3768      typedef A Allocator;
    3869
    3970       
     71      /** Default constructor for the map.
     72       */
    4073      Map() : values(0), capacity(0) {}
    4174                       
     75      /** Graph and Registry initialized map constructor.
     76       */
    4277      Map(const Graph& g, MapRegistry& r) : MapBase(g, r) {
    4378        allocate_memory();
     
    4883      }
    4984
     85      /** Constructor to use default value to initialize the map.
     86       */
    5087      Map(const Graph& g, MapRegistry& r, const Value& v) : MapBase(g, r) {
    5188        allocate_memory();
     
    5693      }
    5794
     95      /** Constructor to copy a map of the same map type.
     96       */
    5897      Map(const Map& copy) : MapBase(*copy.graph, *copy.registry) {
    5998        capacity = copy.capacity;
     
    66105      }
    67106
     107      /** Constructor to copy a map of an other map type.
     108       */
    68109      template <typename CMap> Map(const CMap& copy)
    69110        : MapBase(copy), capacity(0), values(0) {
     
    76117      }
    77118
     119      /** Assign operator to copy a map of the same map type.
     120       */
    78121      Map& operator=(const Map& copy) {
    79122        if (&copy == this) return *this;
     
    92135      }
    93136
     137      /** Assign operator to copy a map an other map type.
     138       */
    94139      template <typename CMap> Map& operator=(const CMap& copy) {
    95140        if (MapBase::getGraph()) {
     
    106151      }
    107152                               
     153      /** The destructor of the map.
     154       */
    108155      virtual ~Map() {
    109156        if (capacity != 0) {
     
    114161       
    115162       
     163      /**
     164       * The subscript operator. The map can be subscripted by the
     165       * actual keys of the graph.
     166       */
    116167      Value& operator[](const KeyType& key) {
    117168        int id = MapBase::getGraph()->id(key);
     
    119170      }
    120171               
     172      /**
     173       * The const subscript operator. The map can be subscripted by the
     174       * actual keys of the graph.
     175       */
    121176      const Value& operator[](const KeyType& key) const {
    122177        int id = MapBase::getGraph()->id(key);
     
    124179      }
    125180       
    126       const Value& get(const KeyType& key) const {
    127         int id = MapBase::getGraph()->id(key);
    128         return values[id];
    129       }
    130                
     181      /** Setter function of the map. Equivalent with map[key] = val.
     182       *  This is a compatibility feature with the not dereferable maps.
     183       */
    131184      void set(const KeyType& key, const Value& val) {
    132185        int id = MapBase::getGraph()->id(key);
     
    134187      }
    135188               
     189      /** Add a new key to the map. It called by the map registry.
     190       */
    136191      void add(const KeyType& key) {
    137192        int id = MapBase::getGraph()->id(key);
     
    156211      }
    157212               
     213      /** Erase a key from the map. It called by the map registry.
     214       */
    158215      void erase(const KeyType& key) {
    159216        int id = MapBase::getGraph()->id(key);
     
    161218      }
    162219
     220      /** Clear the data structure.
     221       */
    163222      void clear() {   
    164223        if (capacity != 0) {
     
    169228      }
    170229       
     230      /** Compatible iterator with the stl maps' iterators.
     231       *  It iterates on pairs of a key and a value.
     232       */
    171233      class iterator {
    172234        friend class Map;
     
    372434    };         
    373435  };
    374  
     436
    375437/// @}
    376  
    377438
    378439}
  • src/hugo/default_map_factory.h

    r798 r799  
    77#include <hugo/vector_map_factory.h>
    88
     9///\ingroup graphmapfactory
     10///\file
     11///\brief Graph maps that construates and destruates
     12///their elements dynamically.
     13
    914namespace hugo {
     15
     16/// \addtogroup graphmapfactory
     17/// @{
    1018
    1119#define DEFAULT_MAP_BODY(Factory, Val) \
     
    1624  \
    1725    typedef typename MapRegistry::Graph Graph; \
    18     typedef typename MapRegistry::Key Key; \
     26    typedef typename MapRegistry::KeyType KeyType; \
    1927    typedef typename MapRegistry::KeyIt KeyIt; \
    2028    typedef Val Value; \
     
    96104  DEFAULT_MAP_BODY(VectorMapFactory, Type*);
    97105
     106
     107  /** The DefaultMapFactory template class is a factory class
     108   *  to create maps for the edge and nodes. This map factory
     109   *  uses the VectorMapFactory if the ValueType is a primitive
     110   *  type and the ArrayMapFactory for the other cases.
     111   *
     112   *  The template parameter is the MapRegistry that the maps
     113   *  will belong to.
     114   */
     115
    98116  template <typename MapRegistry>
    99117  class DefaultMapFactory {
    100118               
    101119  public:
    102                
     120    /// The graph type of the maps.
    103121    typedef typename MapRegistry::Graph Graph;
    104     typedef typename MapRegistry::Key Key;
     122    /// The key type of the maps.
     123    typedef typename MapRegistry::KeyType KeyType;
     124    /// The iterator to iterate on the keys.
    105125    typedef typename MapRegistry::KeyIt KeyIt;
    106126
     127    /// The MapBase of the Map which imlements the core regisitry function.
    107128    typedef typename MapRegistry::MapBase MapBase;
     129               
    108130
     131    /** The template Map type.
     132     */
    109133    template <typename V>
    110134    class Map : public DefaultMap<MapRegistry, V> {
     
    116140      typedef V Value;
    117141
     142      /** Default constructor for the map.
     143       */
    118144      Map() : MapImpl() {}
    119145
     146      /** Graph and Registry initialized map constructor.
     147       */
    120148      Map(const Graph& g, MapRegistry& r) : MapImpl(g, r) {}
    121149
     150      /** Constructor to use default value to initialize the map.
     151       */
    122152      Map(const Graph& g, MapRegistry& r, const Value& v) : MapImpl(g, r, v) {}
    123153
     154      /** Constructor to copy a map of the same map type.
     155       */
    124156      Map(const Map& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {}
    125157
     158      /** Constructor to copy a map of an other map type.
     159       */
    126160      template <typename CMap> Map(const CMap& copy) : MapImpl(copy) {}
    127161
     162      /** Assign operator to copy a map of the same map type.
     163       */
    128164      Map& operator=(const Map& copy) {
    129165        MapImpl::operator=(static_cast<const MapImpl&>(copy));
     
    131167      }
    132168
     169      /** Assign operator to copy a map an other map type.
     170       */
    133171      template <typename CMap> Map& operator=(const CMap& copy) {
    134172        MapImpl::operator=(copy);
  • src/hugo/vector_map_factory.h

    r798 r799  
    129129       * actual keys of the graph.
    130130       */
    131 <<<<<<< .mine
    132       Reference operator[](const Key& key) {
    133 =======
    134       typename Container::reference operator[](const KeyType& key) {
    135 >>>>>>> .r1091
     131      Reference operator[](const KeyType& key) {
    136132        int id = getGraph()->id(key);
    137133        return container[id];
     
    142138       * actual keys of the graph.
    143139       */
    144 <<<<<<< .mine
    145       ConstReference operator[](const Key& key) const {
    146 =======
    147       typename Container::const_reference operator[](const KeyType& key) const {
    148 >>>>>>> .r1091
     140      ConstReference operator[](const KeyType& key) const {
    149141        int id = getGraph()->id(key);
    150142        return container[id];
     
    210202        private:
    211203          Reference data;
    212           Pointer(const KeyType& key, Value& val) : data(key, val) {}
     204          Pointer(const KeyType& key, Map::Reference val) : data(key, val) {}
    213205        public:
    214206          Reference* operator->() {return &data;}
     
    301293        private:
    302294          Reference data;
    303           Pointer(const KeyType& key, const Value& val) : data(key, val) {}
     295          Pointer(const KeyType& key, Map::ConstReference val)
     296            : data(key, val) {}
    304297        public:
    305298          Reference* operator->() {return &data;}
Note: See TracChangeset for help on using the changeset viewer.