Changeset 1705:3f63d9db307b in lemon-0.x for lemon/maps.h
- Timestamp:
- 10/05/05 15:18:51 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2232
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.