lemon/maps.h
changeset 1512 e54392395480
parent 1439 2c43106bef85
child 1531 a3b20dd847b5
equal deleted inserted replaced
1:e541a29cdea4 2:432d193514ac
   144     typedef std::map<K,T,Compare> parent;
   144     typedef std::map<K,T,Compare> parent;
   145     T v;
   145     T v;
   146     typedef typename parent::value_type PairType;
   146     typedef typename parent::value_type PairType;
   147 
   147 
   148   public:
   148   public:
       
   149     ///\e
   149     typedef K Key;
   150     typedef K Key;
       
   151     ///\e
   150     typedef T Value;
   152     typedef T Value;
       
   153     ///\e
   151     typedef T& Reference;
   154     typedef T& Reference;
       
   155     ///\e
   152     typedef const T& ConstReference;
   156     typedef const T& ConstReference;
   153 
   157 
   154 
   158 
   155     StdMap() : v() {}
   159     StdMap() : v() {}
   156     /// Constructor with specified default value
   160     /// Constructor with specified default value
   224     typename SmartConstReference<M>::Type m;
   228     typename SmartConstReference<M>::Type m;
   225   public:
   229   public:
   226 
   230 
   227     typedef True NeedCopy;
   231     typedef True NeedCopy;
   228 
   232 
       
   233     ///\e
   229     typedef typename M::Key Key;
   234     typedef typename M::Key Key;
       
   235     ///\e
   230     typedef T Value;
   236     typedef T Value;
   231 
   237 
   232     ///Constructor
   238     ///Constructor
   233 
   239 
   234     ///Constructor
   240     ///Constructor
   269 
   275 
   270   public:
   276   public:
   271 
   277 
   272     typedef True NeedCopy;
   278     typedef True NeedCopy;
   273 
   279 
       
   280     ///\e
   274     typedef typename M1::Key Key;
   281     typedef typename M1::Key Key;
       
   282     ///\e
   275     typedef typename M1::Value Value;
   283     typedef typename M1::Value Value;
   276 
   284 
   277     ///Constructor
   285     ///Constructor
   278 
   286 
   279     ///\e
   287     ///\e
   316     typename SmartConstReference<M>::Type m;
   324     typename SmartConstReference<M>::Type m;
   317     typename M::Value v;
   325     typename M::Value v;
   318   public:
   326   public:
   319 
   327 
   320     typedef True NeedCopy;
   328     typedef True NeedCopy;
       
   329     ///\e
   321     typedef typename M::Key Key;
   330     typedef typename M::Key Key;
       
   331     ///\e
   322     typedef typename M::Value Value;
   332     typedef typename M::Value Value;
   323 
   333 
   324     ///Constructor
   334     ///Constructor
   325 
   335 
   326     ///Constructor
   336     ///Constructor
   354     typename SmartConstReference<M1>::Type m1;
   364     typename SmartConstReference<M1>::Type m1;
   355     typename SmartConstReference<M2>::Type m2;
   365     typename SmartConstReference<M2>::Type m2;
   356   public:
   366   public:
   357 
   367 
   358     typedef True NeedCopy;
   368     typedef True NeedCopy;
       
   369     ///\e
   359     typedef typename M1::Key Key;
   370     typedef typename M1::Key Key;
       
   371     ///\e
   360     typedef typename M1::Value Value;
   372     typedef typename M1::Value Value;
   361 
   373 
   362     ///Constructor
   374     ///Constructor
   363 
   375 
   364     ///\e
   376     ///\e
   392     typename SmartConstReference<M1>::Type m1;
   404     typename SmartConstReference<M1>::Type m1;
   393     typename SmartConstReference<M2>::Type m2;
   405     typename SmartConstReference<M2>::Type m2;
   394   public:
   406   public:
   395 
   407 
   396     typedef True NeedCopy;
   408     typedef True NeedCopy;
       
   409     ///\e
   397     typedef typename M1::Key Key;
   410     typedef typename M1::Key Key;
       
   411     ///\e
   398     typedef typename M1::Value Value;
   412     typedef typename M1::Value Value;
   399 
   413 
   400     ///Constructor
   414     ///Constructor
   401 
   415 
   402     ///\e
   416     ///\e
   436     typename SmartConstReference<M>::Type m;
   450     typename SmartConstReference<M>::Type m;
   437     typename M::Value v;
   451     typename M::Value v;
   438   public:
   452   public:
   439 
   453 
   440     typedef True NeedCopy;
   454     typedef True NeedCopy;
       
   455     ///\e
   441     typedef typename M::Key Key;
   456     typedef typename M::Key Key;
       
   457     ///\e
   442     typedef typename M::Value Value;
   458     typedef typename M::Value Value;
   443 
   459 
   444     ///Constructor
   460     ///Constructor
   445 
   461 
   446     ///Constructor
   462     ///Constructor
   474     typename SmartConstReference<M1>::Type m1;
   490     typename SmartConstReference<M1>::Type m1;
   475     typename SmartConstReference<M2>::Type m2;
   491     typename SmartConstReference<M2>::Type m2;
   476   public:
   492   public:
   477 
   493 
   478     typedef True NeedCopy;
   494     typedef True NeedCopy;
       
   495     ///\e
   479     typedef typename M1::Key Key;
   496     typedef typename M1::Key Key;
       
   497     ///\e
   480     typedef typename M1::Value Value;
   498     typedef typename M1::Value Value;
   481 
   499 
   482     ///Constructor
   500     ///Constructor
   483 
   501 
   484     ///\e
   502     ///\e
   520     typename SmartConstReference<M1>::Type m1;
   538     typename SmartConstReference<M1>::Type m1;
   521     typename SmartConstReference<M2>::Type m2;
   539     typename SmartConstReference<M2>::Type m2;
   522   public:
   540   public:
   523 
   541 
   524     typedef True NeedCopy;
   542     typedef True NeedCopy;
       
   543     ///\e
   525     typedef typename M2::Key Key;
   544     typedef typename M2::Key Key;
       
   545     ///\e
   526     typedef typename M1::Value Value;
   546     typedef typename M1::Value Value;
   527 
   547 
   528     ///Constructor
   548     ///Constructor
   529 
   549 
   530     ///\e
   550     ///\e
   573     typename SmartConstReference<M2>::Type m2;
   593     typename SmartConstReference<M2>::Type m2;
   574     F f;
   594     F f;
   575   public:
   595   public:
   576 
   596 
   577     typedef True NeedCopy;
   597     typedef True NeedCopy;
       
   598     ///\e
   578     typedef typename M1::Key Key;
   599     typedef typename M1::Key Key;
       
   600     ///\e
   579     typedef V Value;
   601     typedef V Value;
   580 
   602 
   581     ///Constructor
   603     ///Constructor
   582 
   604 
   583     ///\e
   605     ///\e
   622   {
   644   {
   623     typename SmartConstReference<M>::Type m;
   645     typename SmartConstReference<M>::Type m;
   624   public:
   646   public:
   625 
   647 
   626     typedef True NeedCopy;
   648     typedef True NeedCopy;
       
   649     ///\e
   627     typedef typename M::Key Key;
   650     typedef typename M::Key Key;
       
   651     ///\e
   628     typedef typename M::Value Value;
   652     typedef typename M::Value Value;
   629 
   653 
   630     ///Constructor
   654     ///Constructor
   631 
   655 
   632     ///\e
   656     ///\e
   674   {
   698   {
   675     typename SmartConstReference<M>::Type m;
   699     typename SmartConstReference<M>::Type m;
   676   public:
   700   public:
   677 
   701 
   678     typedef True NeedCopy;
   702     typedef True NeedCopy;
       
   703     ///\e
   679     typedef typename M::Key Key;
   704     typedef typename M::Key Key;
       
   705     ///\e
   680     typedef typename M::Value Value;
   706     typedef typename M::Value Value;
   681 
   707 
   682     ///Constructor
   708     ///Constructor
   683 
   709 
   684     ///\e
   710     ///\e
   715   {
   741   {
   716     const F &f;
   742     const F &f;
   717   public:
   743   public:
   718 
   744 
   719     typedef True NeedCopy;
   745     typedef True NeedCopy;
       
   746     ///\e
   720     typedef K Key;
   747     typedef K Key;
       
   748     ///\e
   721     typedef V Value;
   749     typedef V Value;
   722 
   750 
   723     ///Constructor
   751     ///Constructor
   724 
   752 
   725     ///\e
   753     ///\e
   754   {
   782   {
   755     typename SmartConstReference<M>::Type m;
   783     typename SmartConstReference<M>::Type m;
   756   public:
   784   public:
   757 
   785 
   758     typedef True NeedCopy;
   786     typedef True NeedCopy;
       
   787     ///\e
   759     typedef typename M::Key argument_type;
   788     typedef typename M::Key argument_type;
       
   789     ///\e
   760     typedef typename M::Value result_type;
   790     typedef typename M::Value result_type;
       
   791     ///\e
   761     typedef typename M::Key Key;
   792     typedef typename M::Key Key;
       
   793     ///\e
   762     typedef typename M::Value Value;
   794     typedef typename M::Value Value;
   763 
   795 
   764     ///Constructor
   796     ///Constructor
   765 
   797 
   766     ///\e
   798     ///\e
   804     typename SmartConstReference<M1>::Type m1;
   836     typename SmartConstReference<M1>::Type m1;
   805     typename SmartConstReference<M2>::Type m2;
   837     typename SmartConstReference<M2>::Type m2;
   806   public:
   838   public:
   807 
   839 
   808     typedef True NeedCopy;
   840     typedef True NeedCopy;
       
   841     ///\e
   809     typedef typename M1::Key Key;
   842     typedef typename M1::Key Key;
       
   843     ///\e
   810     typedef typename M1::Value Value;
   844     typedef typename M1::Value Value;
   811 
   845 
   812     ///Constructor
   846     ///Constructor
   813 
   847 
   814     ///\e
   848     ///\e
   829   inline ForkMap<M1,M2> forkMap(const M1 &m1,const M2 &m2) 
   863   inline ForkMap<M1,M2> forkMap(const M1 &m1,const M2 &m2) 
   830   {
   864   {
   831     return ForkMap<M1,M2>(m1,m2);
   865     return ForkMap<M1,M2>(m1,m2);
   832   }
   866   }
   833 
   867 
       
   868 
       
   869   
       
   870   /* ************* BOOL MAPS ******************* */
       
   871   
       
   872   ///Logical 'not' of a map
       
   873   
       
   874   ///This bool \ref concept::ReadMap "read only map" returns the 
       
   875   ///logical negation of
       
   876   ///value returned by the
       
   877   ///given map. Its \c Key and will be inherited from \c M,
       
   878   ///its Value is <tt>bool</tt>.
       
   879 
       
   880   template<class M> 
       
   881   class NotMap
       
   882   {
       
   883     typename SmartConstReference<M>::Type m;
       
   884   public:
       
   885 
       
   886     typedef True NeedCopy;
       
   887     ///\e
       
   888     typedef typename M::Key Key;
       
   889     ///\e
       
   890     typedef bool Value;
       
   891 
       
   892     ///Constructor
       
   893 
       
   894     ///\e
       
   895     ///
       
   896     NotMap(const M &_m) : m(_m) {};
       
   897     Value operator[](Key k) const {return !m[k];}
       
   898   };
       
   899   
       
   900   ///Returns a \ref NotMap class
       
   901   
       
   902   ///This function just returns a \ref NotMap class.
       
   903   ///\relates NotMap
       
   904   template<class M> 
       
   905   inline NotMap<M> notMap(const M &m) 
       
   906   {
       
   907     return NotMap<M>(m);
       
   908   }
       
   909 
       
   910 
       
   911 
       
   912 
       
   913 
       
   914 
       
   915 
       
   916 
       
   917 
       
   918 
       
   919 
   834   /// @}
   920   /// @}
   835   
       
   836 }
   921 }
   837 
   922 
   838 
       
   839 #endif // LEMON_MAPS_H
   923 #endif // LEMON_MAPS_H