Changeset 891:74589d20dbc3 in lemon-0.x for src
- Timestamp:
- 09/21/04 00:57:48 (21 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1199
- Location:
- src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/hugo/array_map.h
r844 r891 66 66 /** Default constructor for the map. 67 67 */ 68 ArrayMap() : values(0), capacity(0) {}68 ArrayMap() : capacity(0), values(0) {} 69 69 70 70 /** Graph and Registry initialized map constructor. … … 91 91 /** Constructor to copy a map of the same map type. 92 92 */ 93 ArrayMap(const ArrayMap& copy) : MapBase( *copy.graph, *copy.registry) {93 ArrayMap(const ArrayMap& copy) : MapBase(copy) { 94 94 capacity = copy.capacity; 95 95 if (capacity == 0) return; … … 103 103 /** Constructor to copy a map of an other map type. 104 104 */ 105 template <typename CMap> ArrayMap(const CMap& copy) 106 : MapBase(copy), capacity(0), values(0) { 107 if (MapBase::getGraph()) { 108 allocate_memory(); 109 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 110 set(it, copy[it]); 111 } 105 template <typename TT> 106 ArrayMap(const ArrayMap<MapRegistry, TT>& copy) 107 : MapBase(copy) { 108 capacity = copy.capacity; 109 if (capacity == 0) return; 110 values = allocator.allocate(capacity); 111 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 112 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it); 113 allocator.construct(&(values[id]), copy.values[id]); 112 114 } 113 115 } … … 117 119 ArrayMap& operator=(const ArrayMap& copy) { 118 120 if (© == this) return *this; 121 119 122 if (capacity != 0) { 120 123 MapBase::destroy(); 121 124 allocator.deallocate(values, capacity); 122 125 } 126 127 MapBase::operator=(copy); 128 123 129 capacity = copy.capacity; 124 130 if (capacity == 0) return *this; 125 131 values = allocator.allocate(capacity); 132 126 133 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 127 134 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it); 128 135 allocator.construct(&(values[id]), copy.values[id]); 129 136 } 137 130 138 return *this; 131 139 } 132 140 133 /** Assign operator to copy a map an other map type. 134 */ 135 template <typename CMap> ArrayMap& operator=(const CMap& copy) { 141 /** Assign operator to copy a map of an other map type. 142 */ 143 template <typename TT> 144 ArrayMap& operator=(const ArrayMap<MapRegistry, TT>& copy) { 136 145 if (capacity != 0) { 137 146 MapBase::destroy(); 138 147 allocator.deallocate(values, capacity); 139 148 } 149 140 150 MapBase::operator=(copy); 141 if (MapBase::getGraph()) { 142 allocate_memory(); 143 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 144 set(it, copy[it]); 145 } 146 } 151 152 capacity = copy.capacity; 153 if (capacity == 0) return *this; 154 values = allocator.allocate(capacity); 155 156 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 157 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it); 158 allocator.construct(&(values[id]), copy.values[id]); 159 } 160 147 161 return *this; 148 162 } -
src/hugo/default_map.h
r822 r891 30 30 */ 31 31 #define DEFAULT_MAP_BODY(DynMap, Value) \ 32 33 typedef DynMap<MapRegistry, Value> MapImpl;\34 35 public:\36 37 typedef typename MapRegistry::Graph Graph;\38 39 DefaultMap() : MapImpl() {}\40 41 DefaultMap(const Graph& g, MapRegistry& r) : MapImpl(g, r) {} \42 43 DefaultMap(const Graph& g, MapRegistry& r, const Value& v)\44 : MapImpl(g, r, v) {}\45 \46 DefaultMap(const DefaultMap& copy)\47 : MapImpl(static_cast<const MapImpl&>(copy)) {}\48 \49 template <typename CMap> DefaultMap(const CMap& copy) : MapImpl(copy) {}\50 \51 DefaultMap& operator=(const DefaultMap& copy) {\52 MapImpl::operator=(static_cast<const MapImpl&>(copy)); \53 return *this; \32 { \ 33 \ 34 public: \ 35 \ 36 typedef DynMap<MapRegistry, Value> Parent; \ 37 \ 38 typedef typename MapRegistry::Graph Graph; \ 39 \ 40 DefaultMap() : Parent() {} \ 41 DefaultMap(const Graph& g, MapRegistry& r) : Parent(g, r) {} \ 42 DefaultMap(const Graph& g, MapRegistry& r, const Value& v) \ 43 : Parent(g, r, v) {} \ 44 DefaultMap(const DefaultMap& copy) \ 45 : Parent(static_cast<const Parent&>(copy)) {} \ 46 template <typename TT> \ 47 DefaultMap(const DefaultMap<MapRegistry, TT>& copy) { \ 48 Parent::MapBase::operator= \ 49 (static_cast<const typename Parent::MapBase&>(copy)); \ 50 if (Parent::getGraph()) { \ 51 for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\ 52 Parent::add(it); \ 53 Parent::operator[](it) = copy[it]; \ 54 54 } \ 55 \ 56 template <typename CMap> DefaultMap& operator=(const CMap& copy) { \ 57 MapImpl::operator=(copy); \ 58 return *this; \ 55 } \ 56 } \ 57 DefaultMap& operator=(const DefaultMap& copy) { \ 58 Parent::operator=(static_cast<const Parent&>(copy)); \ 59 return *this; \ 60 } \ 61 template <typename TT> \ 62 DefaultMap& operator=(const DefaultMap<MapRegistry, TT>& copy) { \ 63 Parent::clear(); \ 64 Parent::MapBase::operator=(copy); \ 65 if (Parent::getGraph()) { \ 66 for (typename Parent::KeyIt it(*Parent::getGraph()); it!=INVALID; ++it) {\ 67 Parent::add(it); \ 68 Parent::operator[](it) = copy[it]; \ 59 69 } \ 60 \ 61 }; 70 } \ 71 return *this; \ 72 } \ 73 }; 62 74 63 75 -
src/hugo/graph_wrapper.h
r888 r891 287 287 return GraphWrapper<Graph>::tail(e); } 288 288 289 KEEP_MAPS(Parent, RevGraphWrapper);289 // KEEP_MAPS(Parent, RevGraphWrapper); 290 290 291 291 }; … … 494 494 } 495 495 496 KEEP_MAPS(Parent, SubGraphWrapper);496 // KEEP_MAPS(Parent, SubGraphWrapper); 497 497 }; 498 498 … … 559 559 return this->graph->tail(e); } 560 560 561 KEEP_MAPS(Parent, UndirGraphWrapper);561 // KEEP_MAPS(Parent, UndirGraphWrapper); 562 562 563 563 }; … … 566 566 /// 567 567 ///\warning Graph wrappers are in even more experimental state than the other 568 ///parts of the lib. Use them at you own risk.568 ///parts of the lib. Use them at your own risk. 569 569 /// 570 570 /// An undirected graph template. … … 582 582 } 583 583 584 KEEP_MAPS(Parent, UndirGraph);584 // KEEP_MAPS(Parent, UndirGraph); 585 585 }; 586 586 … … 895 895 /// one for the backward edges. 896 896 class EdgeMap { 897 template <typename TT> friend class EdgeMap; 897 898 typename Graph::template EdgeMap<T> forward_map, backward_map; 898 899 public: 899 900 typedef T ValueType; 900 901 typedef Edge KeyType; 902 901 903 EdgeMap(const SubBidirGraphWrapper<Graph, 902 904 ForwardFilterMap, BackwardFilterMap>& g) : 903 905 forward_map(*(g.graph)), backward_map(*(g.graph)) { } 906 904 907 EdgeMap(const SubBidirGraphWrapper<Graph, 905 908 ForwardFilterMap, BackwardFilterMap>& g, T a) : 906 909 forward_map(*(g.graph), a), backward_map(*(g.graph), a) { } 910 911 template <typename TT> 912 EdgeMap(const EdgeMap<TT>& copy) 913 : forward_map(copy.forward_map), backward_map(copy.backward_map) {} 914 915 template <typename TT> 916 EdgeMap& operator=(const EdgeMap<TT>& copy) { 917 forward_map = copy.forward_map; 918 backward_map = copy.backward_map; 919 return *this; 920 } 921 907 922 void set(Edge e, T a) { 908 923 if (!e.backward) … … 911 926 backward_map.set(e, a); 912 927 } 913 T operator[](Edge e) const { 928 929 typename Graph::template EdgeMap<T>::ConstReferenceType 930 operator[](Edge e) const { 914 931 if (!e.backward) 915 932 return forward_map[e]; … … 917 934 return backward_map[e]; 918 935 } 936 937 typename Graph::template EdgeMap<T>::ReferenceType 938 operator[](Edge e) { 939 if (!e.backward) 940 return forward_map[e]; 941 else 942 return backward_map[e]; 943 } 944 919 945 void update() { 920 946 forward_map.update(); … … 924 950 925 951 926 KEEP_NODE_MAP(Parent, SubBidirGraphWrapper);952 // KEEP_NODE_MAP(Parent, SubBidirGraphWrapper); 927 953 928 954 }; … … 966 992 return 2*this->graph->edgeNum(); 967 993 } 968 KEEP_MAPS(Parent, BidirGraphWrapper);994 // KEEP_MAPS(Parent, BidirGraphWrapper); 969 995 }; 970 996 … … 992 1018 Parent::setGraph(gr); 993 1019 } 994 KEEP_MAPS(Parent, BidirGraph);1020 // KEEP_MAPS(Parent, BidirGraph); 995 1021 }; 996 1022 … … 1107 1133 }; 1108 1134 1109 KEEP_MAPS(Parent, ResGraphWrapper);1135 // KEEP_MAPS(Parent, ResGraphWrapper); 1110 1136 }; 1111 1137 … … 1169 1195 } 1170 1196 1171 KEEP_MAPS(Parent, ErasingFirstGraphWrapper);1197 // KEEP_MAPS(Parent, ErasingFirstGraphWrapper); 1172 1198 }; 1173 1199 -
src/hugo/list_graph.h
r880 r891 443 443 typedef SymListGraph Graph; 444 444 445 /// Importing maps from the base class ListGraph.446 KEEP_MAPS(ListGraph, SymListGraph);447 448 445 /// Creating symmetric map registry. 449 446 CREATE_SYM_EDGE_MAP_REGISTRY; -
src/hugo/map_defines.h
r877 r891 39 39 template <typename Value> \ 40 40 class NodeMap : public DynMap<NodeMapRegistry, Value> { \ 41 typedef DynMap<NodeMapRegistry, Value> MapImpl;\42 public:\41 public: \ 42 typedef DynMap<NodeMapRegistry, Value> Parent; \ 43 43 NodeMap() {} \ 44 NodeMap(const typename MapImpl::Graph& g) \ 45 : MapImpl(g, g.node_maps) {} \ 46 NodeMap(const typename MapImpl::Graph& g, const Value& v) \ 47 : MapImpl(g, g.node_maps, v) {} \ 48 NodeMap(const NodeMap& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {} \ 49 template <typename CMap> NodeMap(const CMap& copy) : MapImpl(copy) {} \ 44 NodeMap(const typename Parent::Graph& g) \ 45 : Parent(g, g.node_maps) {} \ 46 NodeMap(const typename Parent::Graph& g, const Value& v) \ 47 : Parent(g, g.node_maps, v) {} \ 48 NodeMap(const NodeMap& copy) : Parent(static_cast<const Parent&>(copy)) {} \ 49 template <typename TT> \ 50 NodeMap(const NodeMap<TT>& copy) \ 51 : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \ 50 52 NodeMap& operator=(const NodeMap& copy) { \ 51 MapImpl::operator=(static_cast<const MapImpl&>(copy));\ 52 return *this; \ 53 } \ 54 template <typename CMap> NodeMap& operator=(const CMap& copy) { \ 55 MapImpl::operator=(copy);\ 53 Parent::operator=(static_cast<const Parent&>(copy));\ 54 return *this; \ 55 } \ 56 template <typename TT> \ 57 NodeMap& operator=(const NodeMap<TT>& copy) { \ 58 Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\ 56 59 return *this; \ 57 60 } \ … … 67 70 template <typename Value> \ 68 71 class EdgeMap : public DynMap<EdgeMapRegistry, Value> { \ 69 typedef DynMap<EdgeMapRegistry, Value> MapImpl; \ 70 public: \ 72 public: \ 73 typedef DynMap<EdgeMapRegistry, Value> Parent; \ 74 \ 71 75 EdgeMap() {} \ 72 EdgeMap(const typename MapImpl::Graph& g) \ 73 : MapImpl(g, g.edge_maps) {} \ 74 EdgeMap(const typename MapImpl::Graph& g, const Value& v) \ 75 : MapImpl(g, g.edge_maps, v) {} \ 76 EdgeMap(const EdgeMap& copy) : MapImpl(static_cast<const MapImpl&>(copy)) {} \ 77 template <typename CMap> EdgeMap(const CMap& copy) : MapImpl(copy) {} \ 76 EdgeMap(const typename Parent::Graph& g) \ 77 : Parent(g, g.edge_maps) {} \ 78 EdgeMap(const typename Parent::Graph& g, const Value& v) \ 79 : Parent(g, g.edge_maps, v) {} \ 80 EdgeMap(const EdgeMap& copy) : Parent(static_cast<const Parent&>(copy)) {} \ 81 template <typename TT> \ 82 EdgeMap(const EdgeMap<TT>& copy) \ 83 : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \ 78 84 EdgeMap& operator=(const EdgeMap& copy) { \ 79 MapImpl::operator=(static_cast<const MapImpl&>(copy));\ 80 return *this; \ 81 } \ 82 template <typename CMap> EdgeMap& operator=(const CMap& copy) { \ 83 MapImpl::operator=(copy);\ 85 Parent::operator=(static_cast<const Parent&>(copy));\ 86 return *this; \ 87 } \ 88 template <typename TT> \ 89 EdgeMap& operator=(const EdgeMap<TT>& copy) { \ 90 Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\ 84 91 return *this; \ 85 92 } \ … … 109 116 template <typename Value> \ 110 117 class 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 118 public: \ 119 typedef SymMap<DynMap, SymEdgeMapRegistry, Value> Parent; \ 120 \ 121 SymEdgeMap() {} \ 122 SymEdgeMap(const typename Parent::Graph& g) \ 123 : Parent(g, g.sym_edge_maps) {} \ 124 SymEdgeMap(const typename Parent::Graph& g, const Value& v) \ 125 : Parent(g, g.sym_edge_maps, v) {} \ 126 SymEdgeMap(const SymEdgeMap& copy) \ 127 : Parent(static_cast<const Parent&>(copy)) {} \ 128 template <typename TT> \ 129 SymEdgeMap(const NodeMap<TT>& copy) \ 130 : Parent(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy)) {} \ 131 SymEdgeMap& operator=(const SymEdgeMap& copy) { \ 132 Parent::operator=(static_cast<const Parent&>(copy));\ 133 return *this; \ 134 } \ 135 template <typename TT> \ 136 SymEdgeMap& operator=(const SymEdgeMap<TT>& copy) { \ 137 Parent::operator=(static_cast<const typename SymEdgeMap<TT>::Parent&>(copy));\ 138 return *this; \ 139 } \ 140 }; 137 141 138 142 /** This is a macro to import an node map into a graph class. … … 140 144 #define IMPORT_NODE_MAP(From, from, To, to) \ 141 145 template <typename Value> \ 142 class 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 } \ 146 class NodeMap : public From::template NodeMap<Value> { \ 147 \ 148 public: \ 149 typedef typename From::template NodeMap<Value> Parent; \ 150 \ 151 NodeMap() : Parent() {} \ 152 NodeMap(const To& to) \ 153 : Parent(static_cast<const From&>(from)) { } \ 154 NodeMap(const To& to, const Value& value) \ 155 : Parent(static_cast<const From&>(from), value) { } \ 156 NodeMap(const NodeMap& copy) \ 157 : Parent(static_cast<const Parent&>(copy)) {} \ 158 template <typename TT> \ 159 NodeMap(const NodeMap<TT>& copy) \ 160 : Parent(static_cast<const typename NodeMap<TT>::Parent&>(copy)) {} \ 161 NodeMap& operator=(const NodeMap& copy) { \ 162 Parent::operator=(static_cast<const Parent&>(copy)); \ 163 return *this; \ 164 } \ 165 template <typename TT> \ 166 NodeMap& operator=(const NodeMap<TT>& copy) { \ 167 Parent::operator=(static_cast<const typename NodeMap<TT>::Parent&>(copy));\ 168 return *this; \ 169 } \ 171 170 }; 172 171 … … 175 174 #define IMPORT_EDGE_MAP(From, from, To, to) \ 176 175 template <typename Value> \ 177 class 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 } \ 176 class EdgeMap : public From::template EdgeMap<Value> { \ 177 \ 178 public: \ 179 typedef typename From::template EdgeMap<Value> Parent; \ 180 \ 181 EdgeMap() : Parent() {} \ 182 EdgeMap(const To& to) \ 183 : Parent(static_cast<const From&>(from)) { } \ 184 EdgeMap(const To& to, const Value& value) \ 185 : Parent(static_cast<const From&>(from), value) { } \ 186 EdgeMap(const EdgeMap& copy) \ 187 : Parent(static_cast<const Parent&>(copy)) {} \ 188 template <typename TT> \ 189 EdgeMap(const EdgeMap<TT>& copy) \ 190 : Parent(static_cast<const typename EdgeMap<TT>::Parent&>(copy)) {} \ 191 EdgeMap& operator=(const EdgeMap& copy) { \ 192 Parent::operator=(static_cast<const Parent&>(copy)); \ 193 return *this; \ 194 } \ 195 template <typename TT> \ 196 EdgeMap& operator=(const EdgeMap<TT>& copy) { \ 197 Parent::operator=(static_cast<const typename EdgeMap<TT>::Parent&>(copy));\ 198 return *this; \ 199 } \ 206 200 }; 207 201 -
src/hugo/map_registry.h
r822 r891 71 71 * Assign operator. 72 72 */ 73 74 73 const MapBase& operator=(const MapBase& copy) { 75 74 if (registry) { -
src/hugo/smart_graph.h
r880 r891 318 318 typedef SymSmartGraph Graph; 319 319 320 /// Importing maps from the base class ListGraph.321 KEEP_MAPS(SmartGraph, SymSmartGraph);322 323 320 /// Creating symmetric map registry. 324 321 CREATE_SYM_EDGE_MAP_REGISTRY; -
src/hugo/sym_map.h
r844 r891 104 104 : MapImpl(static_cast<const MapImpl&>(copy)) {} 105 105 106 /** Constructor to copy a map of an other map type.107 */108 template <typename CMap> SymMap(const CMap& copy)109 : MapImpl(copy) {}110 111 106 /** Assign operator to copy a map of the same map type. 112 107 */ … … 116 111 } 117 112 118 /** Assign operator to copy a map of an other map type.119 */120 template <typename CMap> SymMap& operator=(const CMap& copy) {121 MapImpl::operator=(copy);122 return *this;123 }124 125 113 /** Add a new key to the map. It called by the map registry. 126 114 */ -
src/hugo/vector_map.h
r844 r891 33 33 template <typename MapRegistry, typename Value> 34 34 class VectorMap : public MapRegistry::MapBase { 35 template <typename MR, typename T> friend class VectorMap; 35 36 public: 36 37 … … 83 84 : MapBase(g, r), container(KeyInfo<Graph, KeyIt>::maxId(g)+1, v) {} 84 85 85 /** Constructor to copy a map of an other map type.86 */ 87 template <typename CMap> VectorMap(const CMap& copy) : MapBase(copy) {88 if (MapBase::getGraph()) {89 container.resize(KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph())+1); 90 91 set(it, copy[it]);92 }86 /** Assign operator to copy a map of an other map type. 87 */ 88 template <typename TT> 89 VectorMap(const VectorMap<MapRegistry, TT>& c) 90 : MapBase(c), container(c.container.size()) { 91 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 92 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it); 93 container[id] = c.container[id]; 93 94 } 94 95 } 95 96 96 /** Assign operator to copy a map an other map type. 97 */ 98 template <typename CMap> VectorMap& operator=(const CMap& copy) { 99 container.clear(); 100 this->MapBase::operator=(copy); 101 if (MapBase::getGraph()) { 102 container.resize(KeyInfo<Graph, KeyIt>::maxId(*MapBase::getGraph())+1); 103 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 104 set(it, copy[it]); 105 } 97 /** Assign operator to copy a map of an other map type. 98 */ 99 template <typename TT> 100 VectorMap& operator=(const VectorMap<MapRegistry, TT>& c) { 101 container.resize(c.container.size()); 102 MapBase::operator=(c); 103 for (KeyIt it(*MapBase::getGraph()); it != INVALID; ++it) { 104 int id = KeyInfo<Graph, KeyIt>::id(*MapBase::getGraph(), it); 105 container[id] = c.container[id]; 106 106 } 107 107 return *this; 108 108 } 109 110 /** The destructor of the map.111 */112 virtual ~VectorMap() {113 }114 115 109 /** 116 110 * The subscript operator. The map can be subscripted by the -
src/test/graph_test.h
r856 r891 1 // -*- c++ -*- 1 2 #ifndef HUGO_TEST_GRAPH_TEST_H 2 3 #define HUGO_TEST_GRAPH_TEST_H … … 10 11 namespace hugo { 11 12 12 13 template<class Graph> void checkCompileStaticGraph(Graph &G) 14 { 15 typedef typename Graph::Node Node; 16 typedef typename Graph::NodeIt NodeIt; 17 typedef typename Graph::Edge Edge; 18 typedef typename Graph::EdgeIt EdgeIt; 19 typedef typename Graph::InEdgeIt InEdgeIt; 20 typedef typename Graph::OutEdgeIt OutEdgeIt; 13 struct DummyType { 14 int value; 15 DummyType() {} 16 DummyType(int p) : value(p) {} 17 DummyType& operator=(int p) { value = p; return *this;} 18 }; 19 20 21 template<class Graph> void checkCompileStaticGraph(Graph &G) 22 { 23 typedef typename Graph::Node Node; 24 typedef typename Graph::NodeIt NodeIt; 25 typedef typename Graph::Edge Edge; 26 typedef typename Graph::EdgeIt EdgeIt; 27 typedef typename Graph::InEdgeIt InEdgeIt; 28 typedef typename Graph::OutEdgeIt OutEdgeIt; 21 29 22 { 23 Node i; Node j(i); Node k(INVALID); 24 i=j; 25 bool b; b=true; 26 b=(i==INVALID); b=(i!=INVALID); 27 b=(i==j); b=(i!=j); b=(i<j); 28 } 29 { 30 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G); 31 i=j; 32 j=G.first(i); 33 j=++i; 34 bool b; b=true; 35 b=(i==INVALID); b=(i!=INVALID); 36 Node n(i); 37 n=i; 38 b=(i==j); b=(i!=j); b=(i<j); 39 //Node ->NodeIt conversion 40 NodeIt ni(G,n); 41 } 42 { 43 Edge i; Edge j(i); Edge k(INVALID); 44 i=j; 45 bool b; b=true; 46 b=(i==INVALID); b=(i!=INVALID); 47 b=(i==j); b=(i!=j); b=(i<j); 48 } 49 { 50 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G); 51 i=j; 52 j=G.first(i); 53 j=++i; 54 bool b; b=true; 55 b=(i==INVALID); b=(i!=INVALID); 56 Edge e(i); 57 e=i; 58 b=(i==j); b=(i!=j); b=(i<j); 59 //Edge ->EdgeIt conversion 60 EdgeIt ei(G,e); 61 } 62 { 63 Node n; 64 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n); 65 i=j; 66 j=G.first(i,n); 67 j=++i; 68 bool b; b=true; 69 b=(i==INVALID); b=(i!=INVALID); 70 Edge e(i); 71 e=i; 72 b=(i==j); b=(i!=j); b=(i<j); 73 //Edge ->InEdgeIt conversion 74 InEdgeIt ei(G,e); 75 } 76 { 77 Node n; 78 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n); 79 i=j; 80 j=G.first(i,n); 81 j=++i; 82 bool b; b=true; 83 b=(i==INVALID); b=(i!=INVALID); 84 Edge e(i); 85 e=i; 86 b=(i==j); b=(i!=j); b=(i<j); 87 //Edge ->OutEdgeIt conversion 88 OutEdgeIt ei(G,e); 89 } 90 { 91 Node n,m; 92 n=m=INVALID; 93 Edge e; 94 e=INVALID; 95 n=G.tail(e); 96 n=G.head(e); 97 } 98 // id tests 99 { Node n; int i=G.id(n); i=i; } 100 { Edge e; int i=G.id(e); i=i; } 101 //NodeMap tests 102 { 103 Node k; 104 typename Graph::template NodeMap<int> m(G); 105 //Const map 106 typename Graph::template NodeMap<int> const &cm = m; 107 //Inicialize with default value 108 typename Graph::template NodeMap<int> mdef(G,12); 109 //Copy 110 typename Graph::template NodeMap<int> mm(cm); 111 //Copy from another type 112 typename Graph::template NodeMap<double> dm(cm); 113 int v; 114 v=m[k]; m[k]=v; m.set(k,v); 115 v=cm[k]; 30 { 31 Node i; Node j(i); Node k(INVALID); 32 i=j; 33 bool b; b=true; 34 b=(i==INVALID); b=(i!=INVALID); 35 b=(i==j); b=(i!=j); b=(i<j); 36 } 37 { 38 NodeIt i; NodeIt j(i); NodeIt k(INVALID); NodeIt l(G); 39 i=j; 40 j=G.first(i); 41 j=++i; 42 bool b; b=true; 43 b=(i==INVALID); b=(i!=INVALID); 44 Node n(i); 45 n=i; 46 b=(i==j); b=(i!=j); b=(i<j); 47 //Node ->NodeIt conversion 48 NodeIt ni(G,n); 49 } 50 { 51 Edge i; Edge j(i); Edge k(INVALID); 52 i=j; 53 bool b; b=true; 54 b=(i==INVALID); b=(i!=INVALID); 55 b=(i==j); b=(i!=j); b=(i<j); 56 } 57 { 58 EdgeIt i; EdgeIt j(i); EdgeIt k(INVALID); EdgeIt l(G); 59 i=j; 60 j=G.first(i); 61 j=++i; 62 bool b; b=true; 63 b=(i==INVALID); b=(i!=INVALID); 64 Edge e(i); 65 e=i; 66 b=(i==j); b=(i!=j); b=(i<j); 67 //Edge ->EdgeIt conversion 68 EdgeIt ei(G,e); 69 } 70 { 71 Node n; 72 InEdgeIt i; InEdgeIt j(i); InEdgeIt k(INVALID); InEdgeIt l(G,n); 73 i=j; 74 j=G.first(i,n); 75 j=++i; 76 bool b; b=true; 77 b=(i==INVALID); b=(i!=INVALID); 78 Edge e(i); 79 e=i; 80 b=(i==j); b=(i!=j); b=(i<j); 81 //Edge ->InEdgeIt conversion 82 InEdgeIt ei(G,e); 83 } 84 { 85 Node n; 86 OutEdgeIt i; OutEdgeIt j(i); OutEdgeIt k(INVALID); OutEdgeIt l(G,n); 87 i=j; 88 j=G.first(i,n); 89 j=++i; 90 bool b; b=true; 91 b=(i==INVALID); b=(i!=INVALID); 92 Edge e(i); 93 e=i; 94 b=(i==j); b=(i!=j); b=(i<j); 95 //Edge ->OutEdgeIt conversion 96 OutEdgeIt ei(G,e); 97 } 98 { 99 Node n,m; 100 n=m=INVALID; 101 Edge e; 102 e=INVALID; 103 n=G.tail(e); 104 n=G.head(e); 105 } 106 // id tests 107 { Node n; int i=G.id(n); i=i; } 108 { Edge e; int i=G.id(e); i=i; } 109 //NodeMap tests 110 { 111 Node k; 112 typename Graph::template NodeMap<int> m(G); 113 //Const map 114 typename Graph::template NodeMap<int> const &cm = m; 115 //Inicialize with default value 116 typename Graph::template NodeMap<int> mdef(G,12); 117 //Copy 118 typename Graph::template NodeMap<int> mm(cm); 119 //Copy from another type 120 typename Graph::template NodeMap<double> dm(cm); 121 //Copy to more complex type 122 typename Graph::template NodeMap<DummyType> em(cm); 123 int v; 124 v=m[k]; m[k]=v; m.set(k,v); 125 v=cm[k]; 116 126 117 m=cm; 118 dm=cm; //Copy from another type 119 { 120 //Check the typedef's 121 typename Graph::template NodeMap<int>::ValueType val; 122 val=1; 123 typename Graph::template NodeMap<int>::KeyType key; 124 key = typename Graph::NodeIt(G); 125 } 126 } 127 { //bool NodeMap 128 Node k; 129 typename Graph::template NodeMap<bool> m(G); 130 typename Graph::template NodeMap<bool> const &cm = m; //Const map 131 //Inicialize with default value 132 typename Graph::template NodeMap<bool> mdef(G,12); 133 typename Graph::template NodeMap<bool> mm(cm); //Copy 134 typename Graph::template NodeMap<int> dm(cm); //Copy from another type 135 bool v; 136 v=m[k]; m[k]=v; m.set(k,v); 137 v=cm[k]; 127 m=cm; 128 dm=cm; //Copy from another type 129 em=cm; //Copy to more complex type 130 { 131 //Check the typedef's 132 typename Graph::template NodeMap<int>::ValueType val; 133 val=1; 134 typename Graph::template NodeMap<int>::KeyType key; 135 key = typename Graph::NodeIt(G); 136 } 137 } 138 { //bool NodeMap 139 Node k; 140 typename Graph::template NodeMap<bool> m(G); 141 typename Graph::template NodeMap<bool> const &cm = m; //Const map 142 //Inicialize with default value 143 typename Graph::template NodeMap<bool> mdef(G,12); 144 typename Graph::template NodeMap<bool> mm(cm); //Copy 145 typename Graph::template NodeMap<int> dm(cm); //Copy from another type 146 bool v; 147 v=m[k]; m[k]=v; m.set(k,v); 148 v=cm[k]; 138 149 139 140 141 142 143 144 145 146 147 148 149 150 }151 //EdgeMap tests152 {153 154 155 156 157 158 159 160 161 162 150 m=cm; 151 dm=cm; //Copy from another type 152 m=dm; //Copy to another type 153 154 { 155 //Check the typedef's 156 typename Graph::template NodeMap<bool>::ValueType val; 157 val=true; 158 typename Graph::template NodeMap<bool>::KeyType key; 159 key= typename Graph::NodeIt(G); 160 } 161 } 162 //EdgeMap tests 163 { 164 Edge k; 165 typename Graph::template EdgeMap<int> m(G); 166 typename Graph::template EdgeMap<int> const &cm = m; //Const map 167 //Inicialize with default value 168 typename Graph::template EdgeMap<int> mdef(G,12); 169 typename Graph::template EdgeMap<int> mm(cm); //Copy 170 typename Graph::template EdgeMap<double> dm(cm); //Copy from another type 171 int v; 172 v=m[k]; m[k]=v; m.set(k,v); 173 v=cm[k]; 163 174 164 165 166 167 168 169 170 171 172 173 }174 { //bool EdgeMap175 176 177 178 179 180 181 182 183 184 175 m=cm; 176 dm=cm; //Copy from another type 177 { 178 //Check the typedef's 179 typename Graph::template EdgeMap<int>::ValueType val; 180 val=1; 181 typename Graph::template EdgeMap<int>::KeyType key; 182 key= typename Graph::EdgeIt(G); 183 } 184 } 185 { //bool EdgeMap 186 Edge k; 187 typename Graph::template EdgeMap<bool> m(G); 188 typename Graph::template EdgeMap<bool> const &cm = m; //Const map 189 //Inicialize with default value 190 typename Graph::template EdgeMap<bool> mdef(G,12); 191 typename Graph::template EdgeMap<bool> mm(cm); //Copy 192 typename Graph::template EdgeMap<int> dm(cm); //Copy from another type 193 bool v; 194 v=m[k]; m[k]=v; m.set(k,v); 195 v=cm[k]; 185 196 186 187 188 189 190 191 192 193 194 195 196 }197 }198 199 template<class Graph> void checkCompileGraph(Graph &G)200 {201 checkCompileStaticGraph(G);202 203 typedef typename Graph::Node Node;204 typedef typename Graph::NodeIt NodeIt;205 typedef typename Graph::Edge Edge;206 typedef typename Graph::EdgeIt EdgeIt;207 typedef typename Graph::InEdgeIt InEdgeIt;208 typedef typename Graph::OutEdgeIt OutEdgeIt;197 m=cm; 198 dm=cm; //Copy from another type 199 m=dm; //Copy to another type 200 { 201 //Check the typedef's 202 typename Graph::template EdgeMap<bool>::ValueType val; 203 val=true; 204 typename Graph::template EdgeMap<bool>::KeyType key; 205 key= typename Graph::EdgeIt(G); 206 } 207 } 208 } 209 210 template<class Graph> void checkCompileGraph(Graph &G) 211 { 212 checkCompileStaticGraph(G); 213 214 typedef typename Graph::Node Node; 215 typedef typename Graph::NodeIt NodeIt; 216 typedef typename Graph::Edge Edge; 217 typedef typename Graph::EdgeIt EdgeIt; 218 typedef typename Graph::InEdgeIt InEdgeIt; 219 typedef typename Graph::OutEdgeIt OutEdgeIt; 209 220 210 Node n,m;211 n=G.addNode();212 m=G.addNode();213 Edge e;214 e=G.addEdge(n,m);221 Node n,m; 222 n=G.addNode(); 223 m=G.addNode(); 224 Edge e; 225 e=G.addEdge(n,m); 215 226 216 // G.clear();217 }218 219 template<class Graph> void checkCompileGraphEraseEdge(Graph &G)220 {221 typename Graph::Edge e;222 G.erase(e);223 }224 225 template<class Graph> void checkCompileGraphEraseNode(Graph &G)226 {227 typename Graph::Node n;228 G.erase(n);229 }230 231 template<class Graph> void checkCompileErasableGraph(Graph &G)232 {233 checkCompileGraph(G);234 checkCompileGraphEraseNode(G);235 checkCompileGraphEraseEdge(G);236 }237 238 template<class Graph> void checkCompileGraphFindEdge(Graph &G)239 {240 typedef typename Graph::NodeIt Node;241 typedef typename Graph::NodeIt NodeIt;242 243 G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G)));244 G.findEdge(Node(),Node(),G.findEdge(Node(),Node()));245 }246 247 template<class Graph> void checkGraphNodeList(Graph &G, int nn)248 {249 typename Graph::NodeIt n(G);250 for(int i=0;i<nn;i++) {251 252 253 }254 check(n==INVALID,"Wrong Node list linking.");255 }256 257 template<class Graph> void checkGraphEdgeList(Graph &G, int nn)258 {259 typedef typename Graph::EdgeIt EdgeIt;260 261 EdgeIt e(G);262 for(int i=0;i<nn;i++) {263 264 265 }266 check(e==INVALID,"Wrong Edge list linking.");267 }268 269 template<class Graph> void checkGraphOutEdgeList(Graph &G,270 typename Graph::Node n,271 int nn)272 {273 typename Graph::OutEdgeIt e(G,n);274 for(int i=0;i<nn;i++) {275 276 277 }278 check(e==INVALID,"Wrong OutEdge list linking.");279 }280 281 template<class Graph> void checkGraphInEdgeList(Graph &G,282 typename Graph::Node n,283 int nn)284 {285 typename Graph::InEdgeIt e(G,n);286 for(int i=0;i<nn;i++) {287 288 289 }290 check(e==INVALID,"Wrong InEdge list linking.");291 }292 293 ///\file294 ///\todo Check head(), tail() as well;227 // G.clear(); 228 } 229 230 template<class Graph> void checkCompileGraphEraseEdge(Graph &G) 231 { 232 typename Graph::Edge e; 233 G.erase(e); 234 } 235 236 template<class Graph> void checkCompileGraphEraseNode(Graph &G) 237 { 238 typename Graph::Node n; 239 G.erase(n); 240 } 241 242 template<class Graph> void checkCompileErasableGraph(Graph &G) 243 { 244 checkCompileGraph(G); 245 checkCompileGraphEraseNode(G); 246 checkCompileGraphEraseEdge(G); 247 } 248 249 template<class Graph> void checkCompileGraphFindEdge(Graph &G) 250 { 251 typedef typename Graph::NodeIt Node; 252 typedef typename Graph::NodeIt NodeIt; 253 254 G.findEdge(NodeIt(G),++NodeIt(G),G.findEdge(NodeIt(G),++NodeIt(G))); 255 G.findEdge(Node(),Node(),G.findEdge(Node(),Node())); 256 } 257 258 template<class Graph> void checkGraphNodeList(Graph &G, int nn) 259 { 260 typename Graph::NodeIt n(G); 261 for(int i=0;i<nn;i++) { 262 check(n!=INVALID,"Wrong Node list linking."); 263 ++n; 264 } 265 check(n==INVALID,"Wrong Node list linking."); 266 } 267 268 template<class Graph> void checkGraphEdgeList(Graph &G, int nn) 269 { 270 typedef typename Graph::EdgeIt EdgeIt; 271 272 EdgeIt e(G); 273 for(int i=0;i<nn;i++) { 274 check(e!=INVALID,"Wrong Edge list linking."); 275 ++e; 276 } 277 check(e==INVALID,"Wrong Edge list linking."); 278 } 279 280 template<class Graph> void checkGraphOutEdgeList(Graph &G, 281 typename Graph::Node n, 282 int nn) 283 { 284 typename Graph::OutEdgeIt e(G,n); 285 for(int i=0;i<nn;i++) { 286 check(e!=INVALID,"Wrong OutEdge list linking."); 287 ++e; 288 } 289 check(e==INVALID,"Wrong OutEdge list linking."); 290 } 291 292 template<class Graph> void checkGraphInEdgeList(Graph &G, 293 typename Graph::Node n, 294 int nn) 295 { 296 typename Graph::InEdgeIt e(G,n); 297 for(int i=0;i<nn;i++) { 298 check(e!=INVALID,"Wrong InEdge list linking."); 299 ++e; 300 } 301 check(e==INVALID,"Wrong InEdge list linking."); 302 } 303 304 ///\file 305 ///\todo Check head(), tail() as well; 295 306 296 307 -
src/test/graph_wrapper_test.cc
r878 r891 19 19 20 20 21 //Compile SmartGraph22 21 typedef SmartGraph Graph; 22 23 //Compile GraphWrapper 23 24 typedef GraphWrapper<Graph> GW; 24 25 template void checkCompileStaticGraph<GW>(GW &); 25 //template void checkCompileGraphFindEdge<SmartGraph>(SmartGraph &);26 26 27 //Compile SymSmartGraph27 //Compile RevGraphWrapper 28 28 typedef RevGraphWrapper<Graph> RevGW; 29 29 template void checkCompileStaticGraph<RevGW>(RevGW &); 30 //template void checkCompileGraphFindEdge<SymSmartGraph>(SymSmartGraph &); 30 31 //Compile SubGraphWrapper 32 typedef SubGraphWrapper<Graph, Graph::NodeMap<bool>, 33 Graph::EdgeMap<bool> > SubGW; 34 template void checkCompileStaticGraph<SubGW>(SubGW &); 35 36 //Compile UndirGraphWrapper 37 /// \bug UndirGraphWrapper cannot pass the StaticGraph test 38 //typedef UndirGraphWrapper<Graph> UndirGW; 39 //template void checkCompileStaticGraph<UndirGW>(UndirGW &); 40 41 //Compile UndirGraph 42 //typedef UndirGraph<Graph> UndirG; 43 //template void checkCompileStaticGraph<UndirG>(UndirG &); 44 45 //typedef SubBidirGraphWrapper<Graph, Graph::EdgeMap<bool>, 46 /// \bug SubBidirGraphWrapper cannot pass the StaticGraph test 47 // Graph::EdgeMap<bool> > SubBDGW; 48 //template void checkCompileStaticGraph<SubBDGW>(SubBDGW &); 49 50 //Compile BidirGraphWrapper 51 //typedef BidirGraphWrapper<Graph> BidirGW; 52 //template void checkCompileStaticGraph<BidirGW>(BidirGW &); 53 54 //Compile BidirGraph 55 //typedef BidirGraph<Graph> BidirG; 56 //template void checkCompileStaticGraph<BidirG>(BidirG &); 57 58 //Compile ResGraphWrapper 59 //typedef ResGraphWrapper<Graph, int, Graph::EdgeMap<int>, 60 // Graph::EdgeMap<int> > ResGW; 61 //template void checkCompileStaticGraph<ResGW>(ResGW &); 62 63 //Compile ErasingFirstGraphWrapper 64 typedef ErasingFirstGraphWrapper<Graph, Graph::NodeMap<Graph::Edge> > ErasingFirstGW; 65 template void checkCompileStaticGraph<ErasingFirstGW>(ErasingFirstGW &); 31 66 32 67
Note: See TracChangeset
for help on using the changeset viewer.