it_bus/string_map.h

00001 #ifndef _IT_BUS_STRING_MAP_H_
00002 #define _IT_BUS_STRING_MAP_H_
00003 
00004 // @Copyright 2004 IONA Technologies, Plc. All Rights Reserved.
00005 //
00006 
00007 #include <it_bus/types.h>
00008 #include <it_bus/string_hash.h>
00009 #include <it_dsa/hash_map.h>
00010 
00011 namespace IT_Bus
00012 {
00013     template<class Data>
00014     class StringMap
00015     {
00016       public:
00017         typedef String                           key_type;
00018         typedef Data                             data_type;
00019         typedef Data&                            reference_type;
00020         typedef const Data&                      const_reference_type;
00021         typedef IT_Pair<const String, data_type> value_type;
00022         typedef size_t                           size_type;
00023         typedef ptrdiff_t                        difference_type;
00024         typedef StringHash                       hasher;
00025         typedef StringEq                         key_equal;
00026 
00027         typedef IT_TYPENAME
00028         IT_HashMap<String, Data, StringHash, StringEq>::iterator iterator;
00029 
00030         typedef IT_TYPENAME
00031         IT_HashMap<String, Data, StringHash, StringEq>::const_iterator
00032         const_iterator;
00033 
00034         StringMap(
00035             IT_ExceptionHandler& eh = IT_EXCEPTION_HANDLER
00036         );
00037 
00038         IT_EXPLICIT StringMap(
00039             size_type            count,
00040             IT_ExceptionHandler& eh = IT_EXCEPTION_HANDLER
00041         );
00042 
00043         StringMap(
00044             size_type            count,
00045             hasher               hash_fn,
00046             IT_ExceptionHandler& eh = IT_EXCEPTION_HANDLER
00047         );
00048         StringMap(
00049             size_type            count,
00050             hasher               hash_fn,
00051             key_equal            key_eq,
00052             IT_ExceptionHandler& eh = IT_EXCEPTION_HANDLER
00053         );
00054 
00055         // Note: This method is inlined here due to a bug in the AIX linker.
00056         //
00057         StringMap(
00058             const StringMap<Data>& map_
00059         ) : m_map(map_.m_map)
00060         {
00061             // complete
00062         }
00063 
00064         ~StringMap();
00065 
00066         StringMap<Data>&
00067         operator=(
00068             const StringMap<Data>& map_
00069         );
00070 
00071         iterator
00072         begin();
00073 
00074         const_iterator
00075         begin() const;
00076 
00077         iterator
00078         end();
00079 
00080         const_iterator
00081         end() const;
00082 
00083         hasher
00084         hash_funct() const;
00085 
00086         key_equal
00087         key_eq() const;
00088 
00089         void
00090         swap(
00091             StringMap<Data>& map_
00092         );
00093 
00094         IT_Pair<iterator, IT_Bool>
00095         insert(
00096             const value_type&    val,
00097             IT_ExceptionHandler& eh = IT_EXCEPTION_HANDLER
00098         );
00099 
00100         void
00101         insert(
00102             const value_type*    first,
00103             const value_type*    last,
00104             IT_ExceptionHandler& eh = IT_EXCEPTION_HANDLER
00105         );
00106 
00107         size_type
00108         erase(
00109             const key_type& key
00110         );
00111 
00112         void
00113         erase(
00114             const iterator& pos
00115         );
00116 
00117         void
00118         erase(
00119             const iterator& first,
00120             const iterator& last
00121         );
00122 
00123         iterator
00124         find(
00125             const key_type& key
00126         );
00127         const_iterator
00128         find(
00129             const key_type& key
00130         ) const;
00131 
00132         size_type
00133         size() const;
00134 
00135         data_type&
00136         operator[](
00137             const IT_ConstPairWithException<key_type>& key
00138         );
00139 
00140         size_type
00141         bucket_count() const;
00142 
00143         void
00144         resize(
00145             size_type            count,
00146             IT_ExceptionHandler& eh = IT_EXCEPTION_HANDLER
00147         );
00148 
00149       private:
00150         IT_HashMap<String, Data, StringHash, StringEq> m_map;
00151     };
00152 }
00153 
00154 
00155 // Inline functions.
00156 //
00157 template<class Data>
00158 inline IT_TYPENAME IT_Bus::StringMap<Data>::iterator
00159 IT_Bus::StringMap<Data>::begin()
00160 {
00161     return m_map.begin();
00162 }
00163 
00164 template<class Data>
00165 inline IT_TYPENAME IT_Bus::StringMap<Data>::const_iterator
00166 IT_Bus::StringMap<Data>::begin() const
00167 {
00168     return m_map.begin();
00169 }
00170 
00171 template<class Data>
00172 inline IT_TYPENAME IT_Bus::StringMap<Data>::iterator
00173 IT_Bus::StringMap<Data>::end()
00174 {
00175     return m_map.end();
00176 }
00177 
00178 template<class Data>
00179 inline IT_TYPENAME IT_Bus::StringMap<Data>::const_iterator
00180 IT_Bus::StringMap<Data>::end() const
00181 {
00182     return m_map.end();
00183 }
00184 
00185 template<class Data>
00186 inline IT_TYPENAME IT_Bus::StringMap<Data>::hasher
00187 IT_Bus::StringMap<Data>::hash_funct() const
00188 {
00189     return m_map.hash_funct();
00190 }
00191 
00192 template<class Data>
00193 inline IT_TYPENAME IT_Bus::StringMap<Data>::key_equal
00194 IT_Bus::StringMap<Data>::key_eq() const
00195 {
00196     return m_map.key_eq();
00197 }
00198 
00199 template<class Data>
00200 inline void
00201 IT_Bus::StringMap<Data>::swap(
00202     IT_Bus::StringMap<Data>& map_
00203 )
00204 {
00205     m_map.swap(map_.m_map);
00206 }
00207 
00208 template<class Data>
00209 inline IT_Pair<IT_TYPENAME IT_Bus::StringMap<Data>::iterator, IT_Bool>
00210 IT_Bus::StringMap<Data>::insert(
00211     const IT_TYPENAME IT_Bus::StringMap<Data>::value_type& val,
00212     IT_ExceptionHandler&                              eh
00213 )
00214 {
00215     return m_map.insert(val, eh);
00216 }
00217 
00218 template<class Data>
00219 inline void
00220 IT_Bus::StringMap<Data>::insert(
00221     const IT_TYPENAME IT_Bus::StringMap<Data>::value_type* first,
00222     const IT_TYPENAME IT_Bus::StringMap<Data>::value_type* last,
00223     IT_ExceptionHandler&                              eh
00224 )
00225 {
00226     m_map.insert(first, last, eh);
00227 }
00228 
00229 template<class Data>
00230 inline IT_TYPENAME IT_Bus::StringMap<Data>::size_type
00231 IT_Bus::StringMap<Data>::erase(
00232     const IT_TYPENAME IT_Bus::StringMap<Data>::key_type& key
00233 )
00234 {
00235     return m_map.erase(key);
00236 }
00237 
00238 template<class Data>
00239 inline void
00240 IT_Bus::StringMap<Data>::erase(
00241     const IT_TYPENAME IT_Bus::StringMap<Data>::iterator& pos
00242 )
00243 {
00244     m_map.erase(pos);
00245 }
00246 
00247 template<class Data>
00248 inline void
00249 IT_Bus::StringMap<Data>::erase(
00250     const IT_TYPENAME IT_Bus::StringMap<Data>::iterator& first,
00251     const IT_TYPENAME IT_Bus::StringMap<Data>::iterator& last
00252 )
00253 {
00254     m_map.erase(first, last);
00255 }
00256 
00257 template<class Data>
00258 inline IT_TYPENAME IT_Bus::StringMap<Data>::iterator
00259 IT_Bus::StringMap<Data>::find(
00260     const IT_TYPENAME IT_Bus::StringMap<Data>::key_type& key
00261 )
00262 {
00263     return m_map.find(key);
00264 }
00265 
00266 template<class Data>
00267 inline IT_TYPENAME IT_Bus::StringMap<Data>::const_iterator
00268 IT_Bus::StringMap<Data>::find(
00269     const IT_TYPENAME IT_Bus::StringMap<Data>::key_type& key
00270 ) const
00271 {
00272     return m_map.find(key);
00273 }
00274 
00275 template<class Data>
00276 inline IT_TYPENAME IT_Bus::StringMap<Data>::size_type
00277 IT_Bus::StringMap<Data>::size() const
00278 {
00279     return m_map.size();
00280 }
00281 
00282 template<class Data>
00283 inline IT_TYPENAME IT_Bus::StringMap<Data>::data_type&
00284 IT_Bus::StringMap<Data>::operator[](
00285     const IT_ConstPairWithException<key_type>& key
00286 )
00287 {
00288     return m_map[key];
00289 }
00290 
00291 template<class Data>
00292 inline IT_TYPENAME IT_Bus::StringMap<Data>::size_type
00293 IT_Bus::StringMap<Data>::bucket_count() const
00294 {
00295     return m_map.bucket_count();
00296 }
00297 
00298 template<class Data>
00299 inline void
00300 IT_Bus::StringMap<Data>::resize(
00301     IT_TYPENAME IT_Bus::StringMap<Data>::size_type count,
00302     IT_ExceptionHandler&                      eh
00303 )
00304 {
00305     m_map.resize(count, eh);
00306 }
00307 
00308 #if IT_SUPPORTS_COMPILE_TIME_INSTANTIATION
00309 #include <it_bus/string_map.cxx>
00310 #endif 
00311 
00312 #endif  

Generated on Tue Mar 20 15:27:44 2007 for Artix by  doxygen 1.5.1-p1