Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

map.hh

00001 /*
00002 *  Name:      map.hh
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Extension class for STL map
00005 *  Date:      $Date: 2003/04/14 00:18:35 $
00006 *  Revision:  $Revision: 1.1 $
00007 *
00008 *  Copyright (C) 1994-2001  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #ifndef _MPCL_UTIL_COLLECTION_MAP__
00027 #define _MPCL_UTIL_COLLECTION_MAP__
00028 
00029 #include <map>
00030 #include "../../exceptions.hh"
00031 
00032 
00034 namespace mpcl
00035 {
00036 
00038   namespace util
00039   {
00040 
00042     namespace collection
00043     {
00044 
00050       template < typename TKey                                   ,
00051                  typename TItem                                  ,
00052                  typename TCompare       = std::less<TKey>       ,
00053                  typename TItemAllocator = std::allocator<TItem> >
00054       class TMap : public std::map<TKey, TItem, TCompare, TItemAllocator>
00055       {
00056 
00057         public:
00058 
00059           typedef
00060             typename std::map<TKey, TItem, TCompare, TItemAllocator>::const_iterator
00061             const_iterator;
00062 
00063           typedef
00064             typename std::map<TKey, TItem, TCompare, TItemAllocator>::const_pointer
00065             const_pointer;
00066 
00067           typedef
00068             typename std::map<TKey, TItem, TCompare, TItemAllocator>::const_reference
00069             const_reference;
00070 
00071           typedef
00072             typename std::map<TKey, TItem, TCompare, TItemAllocator>::const_reverse_iterator
00073             const_reverse_iterator;
00074 
00075           typedef
00076             typename std::map<TKey, TItem, TCompare, TItemAllocator>::difference_type
00077             difference_type;
00078 
00079           typedef
00080             typename std::map<TKey, TItem, TCompare, TItemAllocator>::iterator
00081             iterator;
00082 
00083           typedef
00084             typename std::map<TKey, TItem, TCompare, TItemAllocator>::key_compare
00085             key_compare;
00086 
00087           typedef
00088             typename std::map<TKey, TItem, TCompare, TItemAllocator>::key_type
00089             key_type;
00090 
00091           typedef
00092             typename std::map<TKey, TItem, TCompare, TItemAllocator>::mapped_type
00093             mapped_type;
00094 
00095           typedef
00096             typename std::map<TKey, TItem, TCompare, TItemAllocator>::pointer
00097             pointer;
00098 
00099           typedef
00100             typename std::map<TKey, TItem, TCompare, TItemAllocator>::reference
00101             reference;
00102 
00103           typedef
00104             typename std::map<TKey, TItem, TCompare, TItemAllocator>::reverse_iterator
00105             reverse_iterator;
00106 
00107           typedef
00108             typename std::map<TKey, TItem, TCompare, TItemAllocator>::size_type
00109             size_type;
00110 
00111           typedef
00112             typename std::map<TKey, TItem, TCompare, TItemAllocator>::value_type
00113             value_type;
00114 
00115 
00116         public:
00117 
00118           //
00119           //  C O N S T R U C T O R S
00120           //
00121 
00123           TMap (void)                                         :
00124             std::map<TKey, TItem, TCompare, TItemAllocator>() {}
00125 
00127           explicit TMap (const TCompare& rktCOMPARE)                     :
00128             std::map<TKey, TItem, TCompare, TItemAllocator> (rktCOMPARE) {}
00129 
00131           template <typename InputIterator>
00132           TMap (InputIterator tBEGIN, InputIterator tEND)                  :
00133             std::map<TKey, TItem, TCompare, TItemAllocator> (tBEGIN, tEND) {}
00134 
00136           template <typename InputIterator>
00137           TMap ( InputIterator   tBEGIN     ,
00138                  InputIterator   tEND       ,
00139                  const TCompare& rktCOMPARE )                                          :
00140             std::map<TKey, TItem, TCompare, TItemAllocator> (tBEGIN, tEND, rktCOMPARE) {}
00141 
00143           TMap (const std::map<TKey, TItem, TCompare, TItemAllocator>& rktSOURCE_MAP) :
00144             std::map<TKey, TItem, TCompare, TItemAllocator> (rktSOURCE_MAP)           {}
00145 
00151           TMap& operator = (const TMap& rktSOURCE_MAP)
00152           {
00153             std::map<TKey, TItem, TCompare, TItemAllocator>::operator = (rktSOURCE_MAP);
00154             return *this;
00155           }
00156 
00163           TMap& bind (const TKey& rktKEY, const TItem& rktITEM)
00164           {
00165             insert (std::make_pair (rktKEY, rktITEM));
00166             return *this;
00167           }
00168 
00169 
00170         public:
00171 
00172           //
00173           //  S E L E C T O R S
00174           //
00175 
00181           bool isBound (const key_type& rktKEY) const
00182           {
00183             return ( find (rktKEY) != end() );
00184           }
00185 
00191           TItem& operator [] (const key_type& rktKEY)
00192           {
00193             iterator   tIter = find (rktKEY);
00194 
00195             if ( tIter == end() )
00196             {
00197               throw TConstraintException ("item not in map", __FILE__, __LINE__);
00198             }
00199             return tIter->second;
00200           }
00201 
00207           const TItem& operator [] (const key_type& rktKEY) const
00208           {
00209             const_iterator   ktIter = find (rktKEY);
00210 
00211             if ( ktIter == end() )
00212             {
00213               throw TConstraintException ("item not in map", __FILE__, __LINE__);
00214             }
00215             return ktIter->second;
00216           }
00217 
00218       };  // class TMap
00219 
00220     }  // namespace collection
00221 
00222   }  // namespace util
00223 
00224 }  // namespace mpcl
00225 
00226 
00227 #endif  // not _MPCL_UTIL_COLLECTION_MAP__

Generated on Mon Oct 13 02:35:23 2003 for MPCL by doxygen1.2.18