Changeset 1705:3f63d9db307b in lemon-0.x
- Timestamp:
- 10/05/05 15:18:51 (18 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2232
- Location:
- lemon
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/graph_reader.h
r1540 r1705 123 123 /// Construct a new GraphReader. It reads into the given graph 124 124 /// and it uses the given reader as the default skipper. 125 GraphReader(std::istream& _is, 126 typename SmartParameter<Graph>::Type _graph, 125 GraphReader(std::istream& _is, Graph& _graph, 127 126 const DefaultSkipper& _skipper = DefaultSkipper()) 128 127 : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper), … … 138 137 /// Construct a new GraphReader. It reads into the given graph 139 138 /// and it uses the given reader as the default skipper. 140 GraphReader(const std::string& _filename, 141 typename SmartParameter<Graph>::Type _graph, 139 GraphReader(const std::string& _filename, Graph& _graph, 142 140 const DefaultSkipper& _skipper = DefaultSkipper()) 143 141 : reader(new LemonReader(_filename)), own_reader(true), … … 154 152 /// Construct a new GraphReader. It reads into the given graph 155 153 /// and it uses the given reader as the default skipper. 156 GraphReader(LemonReader& _reader, 157 typename SmartParameter<Graph>::Type _graph, 154 GraphReader(LemonReader& _reader, Graph& _graph, 158 155 const DefaultSkipper& _skipper = DefaultSkipper()) 159 156 : reader(_reader), own_reader(false), skipper(_skipper), -
lemon/lemon_reader.h
r1627 r1705 37 37 #include <lemon/bits/item_reader.h> 38 38 39 #include <lemon/xy.h> 40 39 41 #include <lemon/concept_check.h> 40 42 #include <lemon/concept/maps.h> … … 95 97 }; 96 98 97 template <typename M1, typename M2> 98 class WriteComposeMap { 99 template <typename Map> 100 struct Ref { typedef Map& Type; }; 101 template <typename Map> 102 struct Arg { typedef Map& Type; }; 103 104 template <typename Graph, typename Map> 105 class ForwardComposeMap { 99 106 public: 100 typedef True NeedCopy; 107 typedef typename Graph::UndirEdge Key; 108 typedef typename Map::Value Value; 109 110 ForwardComposeMap(const Graph& _graph, typename Arg<Map>::Type _map) 111 : graph(_graph), map(_map) {} 101 112 102 typedef typename M2::Key Key; 103 typedef typename M1::Value Value; 104 105 WriteComposeMap(typename SmartParameter<M1>::Type _m1, const M2& _m2) 106 : m1(_m1), m2(_m2) {} 113 void set(const Key& key, const Value& val) { 114 map.set(graph.direct(key, true), val); 115 } 116 117 private: 118 typename Ref<Map>::Type map; 119 const Graph& graph; 120 }; 121 122 template <typename Graph, typename Map> 123 ForwardComposeMap<Graph, Map> 124 forwardComposeMap(const Graph& graph, const Map& map) { 125 return ForwardComposeMap<Graph, Map>(graph, map); 126 } 127 128 template <typename Graph, typename Map> 129 ForwardComposeMap<Graph, Map> 130 forwardComposeMap(const Graph& graph, Map& map) { 131 return ForwardComposeMap<Graph, Map>(graph, map); 132 } 133 134 template <typename Graph, typename Map> 135 class BackwardComposeMap { 136 public: 137 typedef typename Graph::UndirEdge Key; 138 typedef typename Map::Value Value; 139 140 BackwardComposeMap(const Graph& _graph, typename Arg<Map>::Type _map) 141 : graph(_graph), map(_map) {} 107 142 108 void set(const Key& key, const Value& val ue) {109 m 1.set(m2[key], value);143 void set(const Key& key, const Value& val) { 144 map.set(graph.direct(key, false), val); 110 145 } 111 146 112 147 private: 113 114 typename SmartReference<M1>::Type m1; 115 typename SmartConstReference<M2>::Type m2; 116 117 }; 118 119 template <typename M1, typename M2> 120 WriteComposeMap<M1, M2> writeComposeMap(M1& m1, const M2& m2) { 121 return WriteComposeMap<M1, M2>(m1, m2); 122 } 123 124 template <typename M1, typename M2> 125 WriteComposeMap<M1, M2> writeComposeMap(const M1& m1, const M2& m2) { 126 return WriteComposeMap<M1, M2>(m1, m2); 127 } 128 148 typename Ref<Map>::Type map; 149 const Graph& graph; 150 }; 151 152 153 template <typename Graph, typename Map> 154 BackwardComposeMap<Graph, Map> 155 backwardComposeMap(const Graph& graph, const Map& map) { 156 return BackwardComposeMap<Graph, Map>(graph, map); 157 } 158 159 template <typename Graph, typename Map> 160 BackwardComposeMap<Graph, Map> 161 backwardComposeMap(const Graph& graph, Map& map) { 162 return BackwardComposeMap<Graph, Map>(graph, map); 163 } 164 165 template <typename Graph, typename Map> 166 struct Ref<ForwardComposeMap<Graph, Map> > { 167 typedef ForwardComposeMap<Graph, Map> Type; 168 }; 169 template <typename Graph, typename Map> 170 struct Arg<ForwardComposeMap<Graph, Map> > { 171 typedef const ForwardComposeMap<Graph, Map>& Type; 172 }; 173 174 template <typename Graph, typename Map> 175 struct Ref<BackwardComposeMap<Graph, Map> > { 176 typedef BackwardComposeMap<Graph, Map> Type; 177 }; 178 template <typename Graph, typename Map> 179 struct Arg<BackwardComposeMap<Graph, Map> > { 180 typedef const BackwardComposeMap<Graph, Map>& Type; 181 }; 182 183 template <typename Map> 184 struct Ref<XMap<Map> > { 185 typedef XMap<Map> Type; 186 }; 187 template <typename Map> 188 struct Arg<XMap<Map> > { 189 typedef const XMap<Map>& Type; 190 }; 191 192 template <typename Map> 193 struct Ref<YMap<Map> > { 194 typedef YMap<Map> Type; 195 }; 196 template <typename Map> 197 struct Arg<YMap<Map> > { 198 typedef const YMap<Map>& Type; 199 }; 200 129 201 } 130 202 … … 433 505 typedef std::map<Value, Item, _reader_bits::Less<Value> > Inverse; 434 506 435 typename SmartReference<Map>::Type map;507 typename _reader_bits::Ref<Map>::Type map; 436 508 Reader reader; 437 509 Inverse inverse; 438 510 439 MapReaderInverter(typename SmartParameter<Map>::Type _map,511 MapReaderInverter(typename _reader_bits::Arg<Map>::Type _map, 440 512 const Reader& _reader) 441 513 : map(_map), reader(_reader) {} … … 527 599 typedef _Item Item; 528 600 529 typename SmartReference<Map>::Type map;601 typename _reader_bits::Ref<Map>::Type map; 530 602 Reader reader; 531 603 532 MapReader(typename SmartParameter<Map>::Type _map,604 MapReader(typename _reader_bits::Arg<Map>::Type _map, 533 605 const Reader& _reader) 534 606 : map(_map), reader(_reader) {} … … 660 732 /// the section when the \c section_id and the \c _id are the same. 661 733 NodeSetReader(LemonReader& _reader, 662 typename SmartParameter<Graph>::Type_graph,734 Graph& _graph, 663 735 const std::string& _id = std::string(), 664 736 const DefaultSkipper& _skipper = DefaultSkipper()) … … 689 761 return _readMap< 690 762 typename Traits::template Reader<typename Map::Value>, Map, 691 typename SmartParameter<Map>::Type>(name, map);763 typename _reader_bits::Arg<Map>::Type>(name, map); 692 764 } 693 765 … … 696 768 return _readMap< 697 769 typename Traits::template Reader<typename Map::Value>, Map, 698 typename SmartParameter<Map>::Type>(name, map);770 typename _reader_bits::Arg<Map>::Type>(name, map); 699 771 } 700 772 … … 705 777 NodeSetReader& readNodeMap(std::string name, Map& map, 706 778 const Reader& reader = Reader()) { 707 return _readMap<Reader, Map, typename SmartParameter<Map>::Type>779 return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type> 708 780 (name, map, reader); 709 781 } … … 712 784 NodeSetReader& readNodeMap(std::string name, const Map& map, 713 785 const Reader& reader = Reader()) { 714 return _readMap<Reader, Map, typename SmartParameter<Map>::Type>786 return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type> 715 787 (name, map, reader); 716 788 } … … 818 890 MapReaders readers; 819 891 820 typename SmartReference<Graph>::Typegraph;892 Graph& graph; 821 893 std::string id; 822 894 SkipReader<Node, DefaultSkipper> skipper; … … 868 940 template <typename NodeIdReader> 869 941 EdgeSetReader(LemonReader& _reader, 870 typename SmartParameter<Graph>::Type_graph,942 Graph& _graph, 871 943 const NodeIdReader& _nodeIdReader, 872 944 const std::string& _id = std::string(), … … 899 971 return _readMap< 900 972 typename Traits::template Reader<typename Map::Value>, Map, 901 typename SmartParameter<Map>::Type>(name, map);973 typename _reader_bits::Arg<Map>::Type>(name, map); 902 974 } 903 975 … … 906 978 return _readMap< 907 979 typename Traits::template Reader<typename Map::Value>, Map, 908 typename SmartParameter<Map>::Type>(name, map);980 typename _reader_bits::Arg<Map>::Type>(name, map); 909 981 } 910 982 … … 916 988 const Reader& reader = Reader()) { 917 989 return _readMap<Reader, Map, 918 typename SmartParameter<Map>::Type>(name, map, reader);990 typename _reader_bits::Arg<Map>::Type>(name, map, reader); 919 991 } 920 992 … … 923 995 const Reader& reader = Reader()) { 924 996 return _readMap<Reader, Map, 925 typename SmartParameter<Map>::Type>(name, map, reader);997 typename _reader_bits::Arg<Map>::Type>(name, map, reader); 926 998 } 927 999 … … 1033 1105 MapReaders readers; 1034 1106 1035 typename SmartReference<Graph>::Typegraph;1107 Graph& graph; 1036 1108 std::string id; 1037 1109 SkipReader<Edge, DefaultSkipper> skipper; … … 1090 1162 template <typename NodeIdReader> 1091 1163 UndirEdgeSetReader(LemonReader& _reader, 1092 typename SmartParameter<Graph>::Type_graph,1164 Graph& _graph, 1093 1165 const NodeIdReader& _nodeIdReader, 1094 1166 const std::string& _id = std::string(), … … 1121 1193 return _readMap< 1122 1194 typename Traits::template Reader<typename Map::Value>, Map, 1123 typename SmartParameter<Map>::Type>(name, map);1195 typename _reader_bits::Arg<Map>::Type>(name, map); 1124 1196 } 1125 1197 … … 1128 1200 return _readMap< 1129 1201 typename Traits::template Reader<typename Map::Value>, Map, 1130 typename SmartParameter<Map>::Type>(name, map);1202 typename _reader_bits::Arg<Map>::Type>(name, map); 1131 1203 } 1132 1204 … … 1137 1209 UndirEdgeSetReader& readUndirEdgeMap(std::string name, Map& map, 1138 1210 const Reader& reader = Reader()) { 1139 return _readMap<Reader, Map, typename SmartParameter<Map>::Type>1211 return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type> 1140 1212 (name, map, reader); 1141 1213 } … … 1144 1216 UndirEdgeSetReader& readUndirEdgeMap(std::string name, const Map& map, 1145 1217 const Reader& reader = Reader()) { 1146 return _readMap<Reader, Map, typename SmartParameter<Map>::Type >1218 return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type > 1147 1219 (name, map, reader); 1148 1220 } … … 1190 1262 return _readDirMap< 1191 1263 typename Traits::template Reader<typename Map::Value>, Map, 1192 typename SmartParameter<Map>::Type>(name, map);1264 typename _reader_bits::Arg<Map>::Type>(name, map); 1193 1265 } 1194 1266 … … 1197 1269 return _readDirMap< 1198 1270 typename Traits::template Reader<typename Map::Value>, Map, 1199 typename SmartParameter<Map>::Type>(name, map);1271 typename _reader_bits::Arg<Map>::Type>(name, map); 1200 1272 } 1201 1273 … … 1206 1278 UndirEdgeSetReader& readEdgeMap(std::string name, Map& map, 1207 1279 const Reader& reader = Reader()) { 1208 return _readDirMap<Reader, Map, typename SmartParameter<Map>::Type>1280 return _readDirMap<Reader, Map, typename _reader_bits::Arg<Map>::Type> 1209 1281 (name, map, reader); 1210 1282 } … … 1213 1285 UndirEdgeSetReader& readEdgeMap(std::string name, const Map& map, 1214 1286 const Reader& reader = Reader()) { 1215 return _readDirMap<Reader, Map, typename SmartParameter<Map>::Type>1287 return _readDirMap<Reader, Map, typename _reader_bits::Arg<Map>::Type> 1216 1288 (name, map, reader); 1217 1289 } … … 1225 1297 checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>(); 1226 1298 readMap("+" + name, 1227 _reader_bits:: writeComposeMap(map, forwardMap(graph)), reader);1299 _reader_bits::forwardComposeMap(graph, map), reader); 1228 1300 readMap("-" + name, 1229 _reader_bits:: writeComposeMap(map, backwardMap(graph)), reader);1301 _reader_bits::backwardComposeMap(graph, map), reader); 1230 1302 return *this; 1231 1303 } … … 1337 1409 MapReaders readers; 1338 1410 1339 typename SmartReference<Graph>::Typegraph;1411 Graph& graph; 1340 1412 std::string id; 1341 1413 SkipReader<UndirEdge, DefaultSkipper> skipper; -
lemon/lemon_writer.h
r1690 r1705 36 36 #include <lemon/utility.h> 37 37 #include <lemon/maps.h> 38 #include <lemon/xy.h> 38 39 39 40 #include <lemon/concept_check.h> … … 85 86 }; 86 87 88 template <typename Map> 89 struct Ref { typedef const Map& Type; }; 90 91 template <typename Graph, typename Map> 92 class ForwardComposeMap { 93 public: 94 typedef typename Graph::UndirEdge Key; 95 typedef typename Map::Value Value; 96 97 ForwardComposeMap(const Graph& _graph, const Map& _map) 98 : graph(_graph), map(_map) {} 99 100 Value operator[](const Key& key) { 101 return map[graph.direct(key, false)]; 102 } 103 104 private: 105 typename Ref<Map>::Type map; 106 const Graph& graph; 107 }; 108 109 template <typename Graph, typename Map> 110 ForwardComposeMap<Graph, Map> 111 forwardComposeMap(const Graph& graph, const Map& map) { 112 return ForwardComposeMap<Graph, Map>(graph, map); 113 } 114 115 template <typename Graph, typename Map> 116 class BackwardComposeMap { 117 public: 118 typedef typename Graph::UndirEdge Key; 119 typedef typename Map::Value Value; 120 121 BackwardComposeMap(const Graph& _graph, const Map& _map) 122 : graph(_graph), map(_map) {} 123 124 Value operator[](const Key& key) { 125 return map[graph.direct(key, false)]; 126 } 127 128 private: 129 typename Ref<Map>::Type map; 130 const Graph& graph; 131 }; 132 133 template <typename Graph, typename Map> 134 BackwardComposeMap<Graph, Map> 135 backwardComposeMap(const Graph& graph, const Map& map) { 136 return BackwardComposeMap<Graph, Map>(graph, map); 137 } 138 139 template <typename Graph, typename Map> 140 struct Ref<ForwardComposeMap<Graph, Map> > { 141 typedef ForwardComposeMap<Graph, Map> Type; 142 }; 143 144 template <typename Graph, typename Map> 145 struct Ref<BackwardComposeMap<Graph, Map> > { 146 typedef BackwardComposeMap<Graph, Map> Type; 147 }; 148 149 template <typename Map> 150 struct Ref<XMap<Map> > { 151 typedef XMap<Map> Type; 152 }; 153 template <typename Map> 154 struct Ref<ConstXMap<Map> > { 155 typedef ConstXMap<Map> Type; 156 }; 157 158 template <typename Map> 159 struct Ref<YMap<Map> > { 160 typedef YMap<Map> Type; 161 }; 162 template <typename Map> 163 struct Ref<ConstYMap<Map> > { 164 typedef ConstYMap<Map> Type; 165 }; 166 87 167 } 88 168 … … 235 315 typedef _Item Item; 236 316 237 typename SmartConstReference<Map>::Type map;317 typename _writer_bits::Ref<Map>::Type map; 238 318 Writer writer; 239 319 … … 454 534 bool forceIdMap; 455 535 456 typename SmartConstReference<Graph>::Typegraph;536 const Graph& graph; 457 537 std::string id; 458 538 … … 628 708 bool forceIdMap; 629 709 630 typename SmartConstReference<Graph>::Typegraph;710 const Graph& graph; 631 711 std::string id; 632 712 … … 747 827 checkConcept<concept::ReadMap<Edge, typename Map::Value>, Map>(); 748 828 checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>(); 749 writeUndirEdge("+" + name, composeMap(forwardMap(graph), map), writer); 750 writeUndirEdge("-" + name, composeMap(backwardMap(graph), map), writer); 829 writeUndirEdge("+" + name, 830 _writer_bits::forwardComposeMap(graph, map), writer); 831 writeUndirEdge("-" + name, 832 _writer_bits::backwardComposeMap(graph, map), writer); 751 833 return *this; 752 834 } … … 854 936 bool forceIdMap; 855 937 856 typename SmartConstReference<Graph>::Typegraph;938 const Graph& graph; 857 939 std::string id; 858 940 -
lemon/maps.h
r1695 r1705 39 39 /// Base class of maps. 40 40 /// It provides the necessary <tt>typedef</tt>s required by the map concept. 41 template<typename K, typename T , typename _NeedCopy = False>41 template<typename K, typename T> 42 42 class MapBase { 43 43 public: 44 /// \e45 typedef _NeedCopy NeedCopy;46 44 ///\e 47 45 typedef K Key; … … 55 53 /// or if you have to provide a writable map, but 56 54 /// data written to it will sent to <tt>/dev/null</tt>... 57 template<typename K, typename T , typename NC = False>58 class NullMap : public MapBase<K, T , NC> {59 public: 60 typedef MapBase<K, T , NC> Parent;55 template<typename K, typename T> 56 class NullMap : public MapBase<K, T> { 57 public: 58 typedef MapBase<K, T> Parent; 61 59 typedef typename Parent::Key Key; 62 60 typedef typename Parent::Value Value; … … 69 67 70 68 template <typename K, typename V> 71 NullMap<K, V , True> nullMap() {72 return NullMap<K, V , True>();69 NullMap<K, V> nullMap() { 70 return NullMap<K, V>(); 73 71 } 74 72 … … 79 77 /// In other aspects it is equivalent to the \ref NullMap. 80 78 /// \todo set could be used to set the value. 81 template<typename K, typename T , typename NC = False>82 class ConstMap : public MapBase<K, T , NC> {79 template<typename K, typename T> 80 class ConstMap : public MapBase<K, T> { 83 81 private: 84 82 T v; 85 83 public: 86 84 87 typedef MapBase<K, T , NC> Parent;85 typedef MapBase<K, T> Parent; 88 86 typedef typename Parent::Key Key; 89 87 typedef typename Parent::Value Value; … … 117 115 ///\relates ConstMap 118 116 template<typename K, typename V> 119 inline ConstMap<K, V , True> constMap(const V &v) {120 return ConstMap<K, V , True>(v);117 inline ConstMap<K, V> constMap(const V &v) { 118 return ConstMap<K, V>(v); 121 119 } 122 120 … … 127 125 128 126 //\todo to document later 129 template<typename K, typename V, V v , typename NC>130 class ConstMap<K, Const<V, v> , NC > : public MapBase<K, V, NC> {131 public: 132 typedef MapBase<K, V , False> Parent;127 template<typename K, typename V, V v> 128 class ConstMap<K, Const<V, v> > : public MapBase<K, V> { 129 public: 130 typedef MapBase<K, V> Parent; 133 131 typedef typename Parent::Key Key; 134 132 typedef typename Parent::Value Value; … … 144 142 ///\relates ConstMap 145 143 template<typename K, typename V, V v> 146 inline ConstMap<K, Const<V, v> , True> constMap() {147 return ConstMap<K, Const<V, v> , True>();144 inline ConstMap<K, Const<V, v> > constMap() { 145 return ConstMap<K, Const<V, v> >(); 148 146 } 149 147 … … 226 224 /// This mapping gives back the given key as value without any 227 225 /// modification. 228 template <typename T , typename NC = False>229 class IdentityMap : public MapBase<T, T , NC> {230 public: 231 typedef MapBase<T, T , NC> Parent;226 template <typename T> 227 class IdentityMap : public MapBase<T, T> { 228 public: 229 typedef MapBase<T, T> Parent; 232 230 typedef typename Parent::Key Key; 233 231 typedef typename Parent::Value Value; … … 243 241 ///\relates IdentityMap 244 242 template<typename T> 245 inline IdentityMap<T , True> identityMap() {246 return IdentityMap<T , True>();243 inline IdentityMap<T> identityMap() { 244 return IdentityMap<T>(); 247 245 } 248 246 … … 253 251 ///converts the \c Value of a maps to type \c T. 254 252 ///Its \c Key is inherited from \c M. 255 template <typename M, typename T , typename NC = False>256 class ConvertMap : public MapBase<typename M::Key, T , NC> {257 typename SmartConstReference<M>::Typem;258 public: 259 typedef MapBase<typename M::Key, T , NC> Parent;253 template <typename M, typename T> 254 class ConvertMap : public MapBase<typename M::Key, T> { 255 const M& m; 256 public: 257 typedef MapBase<typename M::Key, T> Parent; 260 258 typedef typename Parent::Key Key; 261 259 typedef typename Parent::Value Value; … … 281 279 ///\todo The order of the template parameters are changed. 282 280 template<typename T, typename M> 283 inline ConvertMap<M, T , True> convertMap(const M &m) {284 return ConvertMap<M, T , True>(m);281 inline ConvertMap<M, T> convertMap(const M &m) { 282 return ConvertMap<M, T>(m); 285 283 } 286 284 … … 291 289 ///The \c Key and \c Value of M2 must be convertible to those of \c M1. 292 290 293 template<typename M1, typename M2 , typename NC = False>294 class AddMap : public MapBase<typename M1::Key, typename M1::Value , NC> {295 typename SmartConstReference<M1>::Typem1;296 typename SmartConstReference<M2>::Typem2;297 298 public: 299 typedef MapBase<typename M1::Key, typename M1::Value , NC> Parent;291 template<typename M1, typename M2> 292 class AddMap : public MapBase<typename M1::Key, typename M1::Value> { 293 const M1& m1; 294 const M2& m2; 295 296 public: 297 typedef MapBase<typename M1::Key, typename M1::Value> Parent; 300 298 typedef typename Parent::Key Key; 301 299 typedef typename Parent::Value Value; … … 314 312 ///\todo Wrong scope in Doxygen when \c \\relates is used 315 313 template<typename M1, typename M2> 316 inline AddMap<M1, M2 , True> addMap(const M1 &m1,const M2 &m2) {317 return AddMap<M1, M2 , True>(m1,m2);314 inline AddMap<M1, M2> addMap(const M1 &m1,const M2 &m2) { 315 return AddMap<M1, M2>(m1,m2); 318 316 } 319 317 … … 333 331 /// AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v); 334 332 ///\endcode 335 template<typename M, typename C = typename M::Value , typename NC = False>336 class ShiftMap : public MapBase<typename M::Key, typename M::Value , NC> {337 typename SmartConstReference<M>::Typem;333 template<typename M, typename C = typename M::Value> 334 class ShiftMap : public MapBase<typename M::Key, typename M::Value> { 335 const M& m; 338 336 C v; 339 337 public: 340 typedef MapBase<typename M::Key, typename M::Value , NC> Parent;338 typedef MapBase<typename M::Key, typename M::Value> Parent; 341 339 typedef typename Parent::Key Key; 342 340 typedef typename Parent::Value Value; … … 357 355 ///\todo A better name is required. 358 356 template<typename M, typename C> 359 inline ShiftMap<M, C , True> shiftMap(const M &m,const C &v) {360 return ShiftMap<M, C , True>(m,v);357 inline ShiftMap<M, C> shiftMap(const M &m,const C &v) { 358 return ShiftMap<M, C>(m,v); 361 359 } 362 360 … … 368 366 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. 369 367 370 template<typename M1, typename M2 , typename NC = False>371 class SubMap : public MapBase<typename M1::Key, typename M1::Value , NC> {372 typename SmartConstReference<M1>::Typem1;373 typename SmartConstReference<M2>::Typem2;374 public: 375 typedef MapBase<typename M1::Key, typename M1::Value , NC> Parent;368 template<typename M1, typename M2> 369 class SubMap : public MapBase<typename M1::Key, typename M1::Value> { 370 const M1& m1; 371 const M2& m2; 372 public: 373 typedef MapBase<typename M1::Key, typename M1::Value> Parent; 376 374 typedef typename Parent::Key Key; 377 375 typedef typename Parent::Value Value; … … 388 386 ///\relates SubMap 389 387 template<typename M1, typename M2> 390 inline SubMap<M1, M2 , True> subMap(const M1 &m1, const M2 &m2) {391 return SubMap<M1, M2 , True>(m1, m2);388 inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) { 389 return SubMap<M1, M2>(m1, m2); 392 390 } 393 391 … … 400 398 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. 401 399 402 template<typename M1, typename M2 , typename NC = False>403 class MulMap : public MapBase<typename M1::Key, typename M1::Value , NC> {404 typename SmartConstReference<M1>::Typem1;405 typename SmartConstReference<M2>::Typem2;406 public: 407 typedef MapBase<typename M1::Key, typename M1::Value , NC> Parent;400 template<typename M1, typename M2> 401 class MulMap : public MapBase<typename M1::Key, typename M1::Value> { 402 const M1& m1; 403 const M2& m2; 404 public: 405 typedef MapBase<typename M1::Key, typename M1::Value> Parent; 408 406 typedef typename Parent::Key Key; 409 407 typedef typename Parent::Value Value; … … 419 417 ///\relates MulMap 420 418 template<typename M1, typename M2> 421 inline MulMap<M1, M2 , True> mulMap(const M1 &m1,const M2 &m2) {422 return MulMap<M1, M2 , True>(m1,m2);419 inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) { 420 return MulMap<M1, M2>(m1,m2); 423 421 } 424 422 … … 438 436 /// MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v); 439 437 ///\endcode 440 template<typename M, typename C = typename M::Value , typename NC = False>441 class ScaleMap : public MapBase<typename M::Key, typename M::Value , NC> {442 typename SmartConstReference<M>::Typem;438 template<typename M, typename C = typename M::Value> 439 class ScaleMap : public MapBase<typename M::Key, typename M::Value> { 440 const M& m; 443 441 C v; 444 442 public: 445 typedef MapBase<typename M::Key, typename M::Value , NC> Parent;443 typedef MapBase<typename M::Key, typename M::Value> Parent; 446 444 typedef typename Parent::Key Key; 447 445 typedef typename Parent::Value Value; … … 462 460 ///\todo A better name is required. 463 461 template<typename M, typename C> 464 inline ScaleMap<M, C , True> scaleMap(const M &m,const C &v) {465 return ScaleMap<M, C , True>(m,v);462 inline ScaleMap<M, C> scaleMap(const M &m,const C &v) { 463 return ScaleMap<M, C>(m,v); 466 464 } 467 465 … … 473 471 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. 474 472 475 template<typename M1, typename M2 , typename NC = False>476 class DivMap : public MapBase<typename M1::Key, typename M1::Value , NC> {477 typename SmartConstReference<M1>::Typem1;478 typename SmartConstReference<M2>::Typem2;479 public: 480 typedef MapBase<typename M1::Key, typename M1::Value , NC> Parent;473 template<typename M1, typename M2> 474 class DivMap : public MapBase<typename M1::Key, typename M1::Value> { 475 const M1& m1; 476 const M2& m2; 477 public: 478 typedef MapBase<typename M1::Key, typename M1::Value> Parent; 481 479 typedef typename Parent::Key Key; 482 480 typedef typename Parent::Value Value; … … 492 490 ///\relates DivMap 493 491 template<typename M1, typename M2> 494 inline DivMap<M1, M2 , True> divMap(const M1 &m1,const M2 &m2) {495 return DivMap<M1, M2 , True>(m1,m2);492 inline DivMap<M1, M2> divMap(const M1 &m1,const M2 &m2) { 493 return DivMap<M1, M2>(m1,m2); 496 494 } 497 495 … … 513 511 ///\todo Check the requirements. 514 512 515 template <typename M1, typename M2 , typename NC = False>516 class ComposeMap : public MapBase<typename M2::Key, typename M1::Value , NC> {517 typename SmartConstReference<M1>::Typem1;518 typename SmartConstReference<M2>::Typem2;519 public: 520 typedef MapBase<typename M2::Key, typename M1::Value , NC> Parent;513 template <typename M1, typename M2> 514 class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> { 515 const M1& m1; 516 const M2& m2; 517 public: 518 typedef MapBase<typename M2::Key, typename M1::Value> Parent; 521 519 typedef typename Parent::Key Key; 522 520 typedef typename Parent::Value Value; … … 532 530 ///\relates ComposeMap 533 531 template <typename M1, typename M2> 534 inline ComposeMap<M1, M2 , True> composeMap(const M1 &m1,const M2 &m2) {535 return ComposeMap<M1, M2 , True>(m1,m2);532 inline ComposeMap<M1, M2> composeMap(const M1 &m1,const M2 &m2) { 533 return ComposeMap<M1, M2>(m1,m2); 536 534 } 537 535 … … 562 560 typename V = typename F::result_type, 563 561 typename NC = False> 564 class CombineMap : public MapBase<typename M1::Key, V , NC> {565 typename SmartConstReference<M1>::Typem1;566 typename SmartConstReference<M2>::Typem2;562 class CombineMap : public MapBase<typename M1::Key, V> { 563 const M1& m1; 564 const M2& m2; 567 565 F f; 568 566 public: 569 typedef MapBase<typename M1::Key, V , NC> Parent;567 typedef MapBase<typename M1::Key, V> Parent; 570 568 typedef typename Parent::Key Key; 571 569 typedef typename Parent::Value Value; … … 594 592 ///\relates CombineMap 595 593 template<typename M1, typename M2, typename F, typename V> 596 inline CombineMap<M1, M2, F, V , True>594 inline CombineMap<M1, M2, F, V> 597 595 combineMap(const M1& m1,const M2& m2, const F& f) { 598 return CombineMap<M1, M2, F, V , True>(m1,m2,f);596 return CombineMap<M1, M2, F, V>(m1,m2,f); 599 597 } 600 598 601 599 template<typename M1, typename M2, typename F> 602 inline CombineMap<M1, M2, F, typename F::result_type , True>600 inline CombineMap<M1, M2, F, typename F::result_type> 603 601 combineMap(const M1& m1, const M2& m2, const F& f) { 604 602 return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f); … … 606 604 607 605 template<typename M1, typename M2, typename K1, typename K2, typename V> 608 inline CombineMap<M1, M2, V (*)(K1, K2), V , True>606 inline CombineMap<M1, M2, V (*)(K1, K2), V> 609 607 combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) { 610 608 return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f); … … 619 617 ///The unary \c - operator must be defined for \c Value, of course. 620 618 621 template<typename M , typename NC = False>622 class NegMap : public MapBase<typename M::Key, typename M::Value , NC> {623 typename SmartConstReference<M>::Typem;624 public: 625 typedef MapBase<typename M::Key, typename M::Value , NC> Parent;619 template<typename M> 620 class NegMap : public MapBase<typename M::Key, typename M::Value> { 621 const M& m; 622 public: 623 typedef MapBase<typename M::Key, typename M::Value> Parent; 626 624 typedef typename Parent::Key Key; 627 625 typedef typename Parent::Value Value; … … 637 635 ///\relates NegMap 638 636 template <typename M> 639 inline NegMap<M , True> negMap(const M &m) {640 return NegMap<M , True>(m);637 inline NegMap<M> negMap(const M &m) { 638 return NegMap<M>(m); 641 639 } 642 640 … … 665 663 666 664 667 template<typename M , typename NC = False>668 class AbsMap : public MapBase<typename M::Key, typename M::Value , NC> {669 typename SmartConstReference<M>::Typem;670 public: 671 typedef MapBase<typename M::Key, typename M::Value , NC> Parent;665 template<typename M> 666 class AbsMap : public MapBase<typename M::Key, typename M::Value> { 667 const M& m; 668 public: 669 typedef MapBase<typename M::Key, typename M::Value> Parent; 672 670 typedef typename Parent::Key Key; 673 671 typedef typename Parent::Value Value; … … 687 685 ///\relates AbsMap 688 686 template<typename M> 689 inline AbsMap<M , True> absMap(const M &m) {690 return AbsMap<M , True>(m);687 inline AbsMap<M> absMap(const M &m) { 688 return AbsMap<M>(m); 691 689 } 692 690 … … 708 706 typename V = typename F::result_type, 709 707 typename NC = False> 710 class FunctorMap : public MapBase<K, V , NC> {708 class FunctorMap : public MapBase<K, V> { 711 709 F f; 712 710 public: 713 typedef MapBase<K, V , NC> Parent;711 typedef MapBase<K, V> Parent; 714 712 typedef typename Parent::Key Key; 715 713 typedef typename Parent::Value Value; … … 728 726 ///\relates FunctorMap 729 727 template<typename K, typename V, typename F> inline 730 FunctorMap<F, K, V , True> functorMap(const F &f) {731 return FunctorMap<F, K, V , True>(f);728 FunctorMap<F, K, V> functorMap(const F &f) { 729 return FunctorMap<F, K, V>(f); 732 730 } 733 731 734 732 template <typename F> inline 735 FunctorMap<F, typename F::argument_type, typename F::result_type , True>733 FunctorMap<F, typename F::argument_type, typename F::result_type> 736 734 functorMap(const F &f) { 737 735 return FunctorMap<F, typename F::argument_type, 738 typename F::result_type , True>(f);736 typename F::result_type>(f); 739 737 } 740 738 741 739 template <typename K, typename V> inline 742 FunctorMap<V (*)(K), K, V , True> functorMap(V (*f)(K)) {743 return FunctorMap<V (*)(K), K, V , True>(f);740 FunctorMap<V (*)(K), K, V> functorMap(V (*f)(K)) { 741 return FunctorMap<V (*)(K), K, V>(f); 744 742 } 745 743 … … 754 752 ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist. 755 753 756 template <typename M , typename NC = False>757 class MapFunctor : public MapBase<typename M::Key, typename M::Value , NC> {758 typename SmartConstReference<M>::Typem;759 public: 760 typedef MapBase<typename M::Key, typename M::Value , NC> Parent;754 template <typename M> 755 class MapFunctor : public MapBase<typename M::Key, typename M::Value> { 756 const M& m; 757 public: 758 typedef MapBase<typename M::Key, typename M::Value> Parent; 761 759 typedef typename Parent::Key Key; 762 760 typedef typename Parent::Value Value; … … 780 778 ///\relates MapFunctor 781 779 template<typename M> 782 inline MapFunctor<M , True> mapFunctor(const M &m) {783 return MapFunctor<M , True>(m);780 inline MapFunctor<M> mapFunctor(const M &m) { 781 return MapFunctor<M>(m); 784 782 } 785 783 … … 796 794 ///The \c Key and \c Value of M2 must be convertible from those of \c M1. 797 795 798 template<typename M1, typename M2 , typename NC = False>799 class ForkMap : public MapBase<typename M1::Key, typename M1::Value , NC> {800 typename SmartConstReference<M1>::Typem1;801 typename SmartConstReference<M2>::Typem2;802 public: 803 typedef MapBase<typename M1::Key, typename M1::Value , NC> Parent;796 template<typename M1, typename M2> 797 class ForkMap : public MapBase<typename M1::Key, typename M1::Value> { 798 const M1& m1; 799 const M2& m2; 800 public: 801 typedef MapBase<typename M1::Key, typename M1::Value> Parent; 804 802 typedef typename Parent::Key Key; 805 803 typedef typename Parent::Value Value; … … 819 817 ///\todo Wrong scope in Doxygen when \c \\relates is used 820 818 template <typename M1, typename M2> 821 inline ForkMap<M1, M2 , True> forkMap(const M1 &m1,const M2 &m2) {822 return ForkMap<M1, M2 , True>(m1,m2);819 inline ForkMap<M1, M2> forkMap(const M1 &m1,const M2 &m2) { 820 return ForkMap<M1, M2>(m1,m2); 823 821 } 824 822 … … 835 833 ///its Value is <tt>bool</tt>. 836 834 837 template <typename M , typename NC = False>838 class NotMap : public MapBase<typename M::Key, bool , NC> {839 typename SmartConstReference<M>::Typem;840 public: 841 typedef MapBase<typename M::Key, bool , NC> Parent;835 template <typename M> 836 class NotMap : public MapBase<typename M::Key, bool> { 837 const M& m; 838 public: 839 typedef MapBase<typename M::Key, bool> Parent; 842 840 typedef typename Parent::Key Key; 843 841 typedef typename Parent::Value Value; … … 853 851 ///\relates NotMap 854 852 template <typename M> 855 inline NotMap<M , True> notMap(const M &m) {856 return NotMap<M , True>(m);853 inline NotMap<M> notMap(const M &m) { 854 return NotMap<M>(m); 857 855 } 858 856 -
lemon/utility.h
r1696 r1705 140 140 struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T> {}; 141 141 142 // smart referencing143 144 template <typename _Type, typename Enable = void>145 struct SmartReference {146 typedef _Type& Type;147 };148 149 template <typename _Type>150 struct SmartReference<151 _Type,152 typename enable_if<typename _Type::NeedCopy, void>::type153 > {154 typedef _Type Type;155 };156 157 template <typename _Type, typename Enable = void>158 struct SmartConstReference {159 typedef const _Type& Type;160 };161 162 template <typename _Type>163 struct SmartConstReference<164 _Type,165 typename enable_if<typename _Type::NeedCopy, void>::type166 > {167 typedef const _Type Type;168 };169 170 template <typename _Type, typename Enable = void>171 struct SmartParameter {172 typedef _Type& Type;173 };174 175 template <typename _Type>176 struct SmartParameter<177 _Type,178 typename enable_if<typename _Type::NeedCopy, void>::type179 > {180 typedef const _Type& Type;181 };182 183 142 } // namespace lemon 184 143
Note: See TracChangeset
for help on using the changeset viewer.