COIN-OR::LEMON - Graph Library

Changeset 822:88226d9fe821 in lemon-0.x


Ignore:
Timestamp:
09/08/04 14:06:45 (16 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1118
Message:

The MapFactories? have been removed from the code because
if we use macros then they increases only the complexity.

The pair iterators of the maps are separeted from the maps.

Some macros and comments has been changed.

Location:
src/hugo
Files:
5 added
3 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • src/hugo/full_graph.h

    r813 r822  
    1414
    1515#include <hugo/map_registry.h>
    16 #include <hugo/default_map_factory.h>
     16#include <hugo/default_map.h>
     17
     18#include <hugo/map_defines.h>
    1719
    1820namespace hugo {
     
    4850    class InEdgeIt;
    4951   
     52
     53    /// Creating map registries.
    5054    CREATE_MAP_REGISTRIES;
    51     CREATE_MAPS(DefaultMapFactory);
     55    /// Creating node and edge maps.
     56    CREATE_MAPS(DefaultMap);
    5257   
    5358  public:
  • src/hugo/list_graph.h

    r813 r822  
    1414
    1515#include <hugo/map_registry.h>
    16 #include <hugo/default_map_factory.h>
    17 
    18 #include <hugo/sym_map_factory.h>
     16#include <hugo/default_map.h>
     17
     18#include <hugo/sym_map.h>
    1919
    2020#include <hugo/map_defines.h>
     
    8080    class InEdgeIt;
    8181
     82    /// Creating map registries.
    8283    CREATE_MAP_REGISTRIES;
    83     CREATE_MAPS(DefaultMapFactory);
     84    /// Creating node and edge maps.
     85    CREATE_MAPS(DefaultMap);
    8486
    8587  public:
     
    444446    typedef SymListGraph Graph;
    445447
    446     KEEP_NODE_MAP(ListGraph);
    447     KEEP_EDGE_MAP(ListGraph);
    448 
     448    /// Importing maps from the base class ListGraph.
     449    KEEP_MAPS(ListGraph, SymListGraph);
     450
     451    /// Creating symmetric map registry.
    449452    CREATE_SYM_EDGE_MAP_REGISTRY;
    450     CREATE_SYM_EDGE_MAP_FACTORY(DefaultMapFactory);
    451     IMPORT_SYM_EDGE_MAP(SymEdgeMapFactory);
     453    /// Creating symmetric edge map.
     454    CREATE_SYM_EDGE_MAP(DefaultMap);
    452455
    453456    SymListGraph() : ListGraph() { }
     
    530533    class InEdgeIt;
    531534   
    532     CREATE_MAP_REGISTRIES;
    533     CREATE_MAPS(DefaultMapFactory);
     535    /// Creating node map registry.
     536    CREATE_NODE_MAP_REGISTRY;
     537    /// Creating node maps.
     538    CREATE_NODE_MAP(DefaultMap);
     539
     540    /// Creating empty map structure for edges.
     541    template <typename Value>
     542    class EdgeMap {
     543    public:
     544      EdgeMap() {}
     545      EdgeMap(const Graph&) {}
     546      EdgeMap(const Graph&, const Value&) {}
     547
     548      EdgeMap(const EdgeMap&) {}
     549      template <typename CMap> EdgeMap(const CMap&) {}
     550
     551      EdgeMap& operator=(const EdgeMap&) {}
     552      template <typename CMap> EdgeMap& operator=(const CMap&) {}
     553     
     554      class ConstIterator {
     555      public:
     556        bool operator==(const ConstIterator&) {return true;}
     557        bool operator!=(const ConstIterator&) {return false;}
     558      };
     559
     560      typedef ConstIterator Iterator;
     561     
     562      Iterator begin() { return Iterator();}
     563      Iterator end() { return Iterator();}
     564
     565      ConstIterator begin() const { return ConstIterator();}
     566      ConstIterator end() const { return ConstIterator();}
     567
     568    };
    534569   
    535570  public:
     
    849884
    850885
     886    /// Creating edge map registry.
    851887    CREATE_EDGE_MAP_REGISTRY;
    852     CREATE_EDGE_MAP_FACTORY(DefaultMapFactory);
    853     IMPORT_EDGE_MAP(EdgeMapFactory);
     888    /// Creating edge maps.
     889    CREATE_EDGE_MAP(DefaultMap);
     890
     891    /// Importing node maps from the NodeGraphType.
     892    IMPORT_NODE_MAP(NodeGraphType, graph.G, EdgeSet, graph);
    854893   
    855894   
     
    10911130      InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
    10921131    };
    1093 
    1094    
    1095     template <typename V> class NodeMap
    1096       : public NodeGraphType::template NodeMap<V>
    1097     {
    1098       //This is a must, the constructors need it.
    1099       typedef typename NodeGraphType::template NodeMap<V> MapImpl;
    1100       typedef V Value;
    1101     public:
    1102       NodeMap() : MapImpl() {}
    1103      
    1104       NodeMap(const EdgeSet& graph)
    1105         : MapImpl(graph.G) { }
    1106 
    1107       NodeMap(const EdgeSet& graph, const Value& value)
    1108         : MapImpl(graph.G, value) { }
    1109 
    1110       NodeMap(const NodeMap& copy)
    1111         : MapImpl(static_cast<const MapImpl&>(copy)) {}
    1112 
    1113       template<typename CMap>
    1114       NodeMap(const CMap& copy)
    1115         : MapImpl(copy) { }
    1116 
    1117       NodeMap& operator=(const NodeMap& copy) {
    1118         MapImpl::operator=(static_cast<const MapImpl&>(copy));
    1119         return *this;
    1120       }
    1121 
    1122       template <typename CMap>
    1123       NodeMap& operator=(const CMap& copy) {
    1124         MapImpl::operator=(copy);
    1125         return *this;
    1126       }
    1127 
    1128     };
     1132   
    11291133  };
    11301134
  • src/hugo/map_defines.h

    r785 r822  
    33#define MAP_DEFINES_H
    44
    5 ///\ingroup graphmapfactory
     5///\ingroup graphmaps
    66///\file
    77///\brief Defines to help creating graph maps.
     
    3030CREATE_EDGE_MAP_REGISTRY
    3131
    32 /** Creates a concrete factory type from a template map
    33  *  factory to use as node map factory.
    34  */
    35 #define CREATE_NODE_MAP_FACTORY(TemplateFactory) \
    36 typedef TemplateFactory<NodeMapRegistry> NodeMapFactory;
    37 
    38 /** Creates a concrete factory type from a template map
    39  *  factory to use as edge map factory.
    40  */
    41 #define CREATE_EDGE_MAP_FACTORY(TemplateFactory) \
    42 typedef TemplateFactory<EdgeMapRegistry> EdgeMapFactory;
    43 
    44 /** Creates both map factories.
    45  */
    46 #define CREATE_MAP_FACTORIES(TemplateFactory) \
    47 CREATE_NODE_MAP_FACTORY(TemplateFactory) \
    48 CREATE_EDGE_MAP_FACTORY(TemplateFactory)
    49 
    50 /** Import a map from a concrete map factory. The import method is
     32/** Creates a map from a template map. The import method is
    5133 *  an overloading of the map type.
    5234 *  The reason to use these macro is that the c++ does not support
     
    5436 *  supports this feature it should be fixed.
    5537 */
    56 #define IMPORT_NODE_MAP(Factory) \
    57 template <typename V> \
    58 class NodeMap : public Factory::template Map<V> { \
    59 typedef typename Factory::template Map<V> MapImpl; \
     38#define CREATE_NODE_MAP(DynMap) \
     39template <typename Value> \
     40class NodeMap : public DynMap<NodeMapRegistry, Value> { \
     41typedef DynMap<NodeMapRegistry, Value> MapImpl; \
    6042public: \
    6143NodeMap() {} \
    62 NodeMap(const Graph& g) : MapImpl(g, g.node_maps) {} \
    63 NodeMap(const Graph& g, const V& v) : MapImpl(g, g.node_maps, v) {} \
     44NodeMap(const typename MapImpl::Graph& g) \
     45  : MapImpl(g, g.node_maps) {} \
     46NodeMap(const typename MapImpl::Graph& g, const Value& v) \
     47  : MapImpl(g, g.node_maps, v) {} \
    6448NodeMap(const NodeMap& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {} \
    6549template <typename CMap> NodeMap(const CMap& copy) : MapImpl(copy) {} \
     
    7458};
    7559
    76 /** Import a map from a concrete map factory. The import method is
     60/** Creates a map from a template map. The import method is
    7761 *  an overloading of the map type.
    7862 *  The reason to use these macro is that the c++ does not support
     
    8064 *  supports this feature it should be fixed.
    8165 */
    82 #define IMPORT_EDGE_MAP(Factory) \
    83 template <typename V> \
    84 class EdgeMap : public Factory::template Map<V> { \
    85 typedef typename Factory::template Map<V> MapImpl; \
     66#define CREATE_EDGE_MAP(DynMap) \
     67template <typename Value> \
     68class EdgeMap : public DynMap<EdgeMapRegistry, Value> { \
     69typedef DynMap<EdgeMapRegistry, Value> MapImpl; \
    8670public: \
    8771EdgeMap() {} \
    88 EdgeMap(const Graph& g) : MapImpl(g, g.edge_maps) {} \
    89 EdgeMap(const Graph& g, const V& v) : MapImpl(g, g.edge_maps, v) {} \
     72EdgeMap(const typename MapImpl::Graph& g) \
     73  : MapImpl(g, g.edge_maps) {} \
     74EdgeMap(const typename MapImpl::Graph& g, const Value& v) \
     75  : MapImpl(g, g.edge_maps, v) {} \
    9076EdgeMap(const EdgeMap& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {} \
    9177template <typename CMap> EdgeMap(const CMap& copy) : MapImpl(copy) {} \
     
    10086};
    10187
    102 /** This macro creates both map factories and imports both maps.
    103  */
    104 #define CREATE_MAPS(TemplateFactory) \
    105 CREATE_MAP_FACTORIES(TemplateFactory) \
    106 IMPORT_NODE_MAP(NodeMapFactory) \
    107 IMPORT_EDGE_MAP(EdgeMapFactory)
     88/** This macro creates both maps.
     89 */
     90#define CREATE_MAPS(DynMap) \
     91CREATE_NODE_MAP(DynMap) \
     92CREATE_EDGE_MAP(DynMap)
    10893
    10994/** This macro creates MapRegistry for Symmetric Edge Maps.
     
    11499mutable EdgeMapRegistry sym_edge_maps;
    115100
    116 /** Creates a concrete factory type from a template map
    117  *  factory to use as edge map factory.
    118  */
    119 #define CREATE_SYM_EDGE_MAP_FACTORY(TemplateFactory) \
    120 typedef SymMapFactory<SymEdgeMapRegistry, TemplateFactory > \
    121 SymEdgeMapFactory;
    122 
    123 /** Import a map from a concrete map factory. The import method is
     101
     102/** Creates a map from a template map. The import method is
    124103 *  an overloading of the map type.
    125104 *  The reason to use these macro is that the c++ does not support
     
    127106 *  supports this feature it should be fixed.
    128107 */
    129 #define IMPORT_SYM_EDGE_MAP(Factory) \
    130 template <typename V> \
    131 class SymEdgeMap : public Factory::template Map<V> { \
    132 typedef typename Factory::template Map<V> MapImpl; \
    133 public: \
    134 SymEdgeMap() {} \
    135 SymEdgeMap(const Graph& g) : MapImpl(g, g.sym_edge_maps) {} \
    136 SymEdgeMap(const Graph& g, const V& v) : MapImpl(g, g.sym_edge_maps, v) {} \
    137 SymEdgeMap(const SymEdgeMap& copy) \
    138   : MapImpl(static_cast<const MapImpl&>(copy)) {} \
    139 template <typename CMap> SymEdgeMap(const CMap& copy) : MapImpl(copy) {} \
    140 SymEdgeMap& operator=(const SymEdgeMap& copy) { \
    141   MapImpl::operator=(static_cast<const MapImpl&>(copy));\
    142   return *this; \
    143 } \
    144 template <typename CMap> SymEdgeMap& operator=(const CMap& copy) { \
    145   MapImpl::operator=(copy);\
    146   return *this; \
    147 } \
    148 };
    149 
    150 
    151 #define KEEP_NODE_MAP(GraphBase) \
    152     template <typename V> class NodeMap \
    153       : public GraphBase::template NodeMap<V> \
    154     { \
    155       typedef typename GraphBase::template NodeMap<V> MapImpl; \
    156       typedef V Value; \
    157     public: \
    158       NodeMap() : MapImpl() {} \
    159 \
    160       NodeMap(const Graph& graph) \
    161         : MapImpl(static_cast<const GraphBase&>(graph)) { } \
    162 \
    163       NodeMap(const Graph& graph, const Value& value) \
    164         : MapImpl(static_cast<const GraphBase&>(graph), value) { } \
    165 \
    166       NodeMap(const NodeMap& copy) \
    167         : MapImpl(static_cast<const MapImpl&>(copy)) {} \
    168 \
    169       template<typename CMap> \
    170       NodeMap(const CMap& copy) \
    171         : MapImpl(copy) {} \
    172 \
    173       NodeMap& operator=(const NodeMap& copy) { \
    174         MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
    175         return *this; \
    176       } \
    177 \
    178       template <typename CMap> \
    179       NodeMap& operator=(const CMap& copy) { \
    180         MapImpl::operator=(copy); \
    181         return *this; \
    182       } \
    183     };
    184 
    185 #define KEEP_EDGE_MAP(GraphBase) \
    186     template <typename V> class EdgeMap \
    187       : public GraphBase::template EdgeMap<V> \
    188     { \
    189       typedef typename GraphBase::template EdgeMap<V> MapImpl; \
    190       typedef V Value; \
    191     public: \
    192       EdgeMap() : MapImpl() {} \
    193 \
    194       EdgeMap(const Graph& graph) \
    195         : MapImpl(static_cast<const GraphBase&>(graph)) { } \
    196 \
    197       EdgeMap(const Graph& graph, const Value& value) \
    198         : MapImpl(static_cast<const GraphBase&>(graph), value) { } \
    199 \
    200       EdgeMap(const EdgeMap& copy) \
    201         : MapImpl(static_cast<const MapImpl&>(copy)) {} \
    202 \
    203       template<typename CMap> \
    204       EdgeMap(const CMap& copy) \
    205         : MapImpl(copy) {} \
    206 \
    207       EdgeMap& operator=(const EdgeMap& copy) { \
    208         MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
    209         return *this; \
    210       } \
    211 \
    212       template <typename CMap> \
    213       EdgeMap& operator=(const CMap& copy) { \
    214         MapImpl::operator=(copy); \
    215         return *this; \
    216       } \
    217     };
    218 
     108#define CREATE_SYM_EDGE_MAP(DynMap) \
     109template <typename Value> \
     110class SymEdgeMap : public SymMap<DynMap, SymEdgeMapRegistry, Value> { \
     111  typedef SymMap<DynMap, SymEdgeMapRegistry, Value> MapImpl; \
     112 public: \
     113\
     114  SymEdgeMap() {} \
     115\
     116  SymEdgeMap(const typename MapImpl::Graph& g) \
     117    : MapImpl(g, g.sym_edge_maps) {} \
     118\
     119  SymEdgeMap(const typename MapImpl::Graph& g, const Value& v) \
     120    : MapImpl(g, g.sym_edge_maps, v) {} \
     121\
     122  SymEdgeMap(const SymEdgeMap& copy) \
     123    : MapImpl(static_cast<const MapImpl&>(copy)) {} \
     124\
     125  template <typename CMap> SymEdgeMap(const CMap& copy) : MapImpl(copy) {} \
     126  SymEdgeMap& operator=(const SymEdgeMap& copy) { \
     127    MapImpl::operator=(static_cast<const MapImpl&>(copy));\
     128    return *this; \
     129  } \
     130\
     131  template <typename CMap> SymEdgeMap& operator=(const CMap& copy) { \
     132    MapImpl::operator=(copy);\
     133    return *this; \
     134  } \
     135};
     136
     137
     138/** This is a macro to import an node map into a graph class.
     139 */
     140#define IMPORT_NODE_MAP(From, from, To, to) \
     141template <typename Value> \
     142class NodeMap \
     143  : public From::template NodeMap<Value> { \
     144  typedef typename From::template NodeMap<Value> MapImpl; \
     145 public: \
     146   NodeMap() : MapImpl() {} \
     147\
     148   NodeMap(const To& to) \
     149     : MapImpl(static_cast<const From&>(from)) { } \
     150\
     151   NodeMap(const To& to, const Value& value) \
     152     : MapImpl(static_cast<const From&>(from), value) { } \
     153\
     154   NodeMap(const NodeMap& copy) \
     155     : MapImpl(static_cast<const MapImpl&>(copy)) {} \
     156\
     157   template<typename CMap> \
     158   NodeMap(const CMap& copy) \
     159     : MapImpl(copy) {} \
     160\
     161   NodeMap& operator=(const NodeMap& copy) { \
     162     MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
     163     return *this; \
     164   } \
     165\
     166   template <typename CMap> \
     167   NodeMap& operator=(const CMap& copy) { \
     168     MapImpl::operator=(copy); \
     169     return *this; \
     170   } \
     171};
     172
     173/** This is a macro to import an edge map into a graph class.
     174 */
     175#define IMPORT_EDGE_MAP(From, from, To, to) \
     176template <typename Value> \
     177class EdgeMap \
     178  : public From::template EdgeMap<Value> { \
     179  typedef typename From::template EdgeMap<Value> MapImpl; \
     180 public: \
     181   EdgeMap() : MapImpl() {} \
     182\
     183   EdgeMap(const To& to) \
     184     : MapImpl(static_cast<const From&>(from)) { } \
     185\
     186   EdgeMap(const To& to, const Value& value) \
     187     : MapImpl(static_cast<const From&>(from), value) { } \
     188\
     189   EdgeMap(const EdgeMap& copy) \
     190     : MapImpl(static_cast<const MapImpl&>(copy)) {} \
     191\
     192   template<typename CMap> \
     193   EdgeMap(const CMap& copy) \
     194     : MapImpl(copy) {} \
     195\
     196   EdgeMap& operator=(const EdgeMap& copy) { \
     197     MapImpl::operator=(static_cast<const MapImpl&>(copy)); \
     198     return *this; \
     199   } \
     200\
     201   template <typename CMap> \
     202   EdgeMap& operator=(const CMap& copy) { \
     203     MapImpl::operator=(copy); \
     204     return *this; \
     205   } \
     206};
     207
     208
     209/** This is a macro to keep the node and edge maps for a graph class.
     210 */
     211#define KEEP_MAPS(From, To) \
     212IMPORT_EDGE_MAP(From, graph, To, graph) \
     213IMPORT_NODE_MAP(From, graph, To, graph)
    219214 
    220215/// @}
  • src/hugo/map_registry.h

    r786 r822  
    2929    typedef KIt KeyIt;
    3030       
    31 
    32 
    3331    /**
    3432     * MapBase is the base class of the registered maps.
  • src/hugo/smart_graph.h

    r813 r822  
    1313#include <hugo/invalid.h>
    1414
    15 #include <hugo/default_map_factory.h>
    16 #include <hugo/sym_map_factory.h>
     15#include <hugo/default_map.h>
     16#include <hugo/sym_map.h>
     17
    1718#include <hugo/map_registry.h>
    1819
     
    7374    class InEdgeIt;
    7475   
     76    /// Creating map registries.
    7577    CREATE_MAP_REGISTRIES;
    76     CREATE_MAPS(DefaultMapFactory);
     78    /// Creating node and edge maps.
     79    CREATE_MAPS(DefaultMap);
    7780   
    7881  public:
     
    315318    typedef SymSmartGraph Graph;
    316319
    317     KEEP_NODE_MAP(SmartGraph);
    318     KEEP_EDGE_MAP(SmartGraph);
    319 
     320    /// Importing maps from the base class ListGraph.
     321    KEEP_MAPS(SmartGraph, SymSmartGraph);
     322
     323    /// Creating symmetric map registry.
    320324    CREATE_SYM_EDGE_MAP_REGISTRY;
    321     CREATE_SYM_EDGE_MAP_FACTORY(DefaultMapFactory);
    322     IMPORT_SYM_EDGE_MAP(SymEdgeMapFactory);
     325    /// Creating symmetric edge map.
     326    CREATE_SYM_EDGE_MAP(DefaultMap);
     327
    323328
    324329    SymSmartGraph() : SmartGraph() { }
Note: See TracChangeset for help on using the changeset viewer.