User Manual, Developers Guide and API Documentation

pointerhashmap.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #ifndef _POINTERHASHMAP_HPP
00029 #define _POINTERHASHMAP_HPP
00030 #include <WNS/SmartPtr.hpp>
00031 #include <functional>
00032 #include <boost/version.hpp>
00033 
00034 // From Boost 1.38 on the unordered_map container is present
00035 // at the same time hash_map becomes deprecated in GNU C++
00036 #if BOOST_VERSION < 103800
00037     #define WNS_USE_OLD_HASH_MAP
00038     #include <ext/hash_map>
00039 #else
00040     #include <boost/unordered_map.hpp>
00041 #endif
00042 
00043 namespace rise {
00045 
00046     template<class Key>
00047     class PointerHashMapFunctor :
00048 #ifdef WNS_USE_OLD_HASH_MAP
00049         public __gnu_cxx::hash<Key const>
00050 #else
00051         public boost::hash<Key const>
00052 #endif
00053     {
00054     public:
00055         ptrdiff_t operator()(Key const k) const {
00056             return ((ptrdiff_t)(k));
00057         };
00058     };
00059 
00061 
00062     template<class Key>
00063     class PointerHashMapFunctor<wns::SmartPtr<Key> > :
00064 #ifdef WNS_USE_OLD_HASH_MAP
00065         public __gnu_cxx::hash<Key* const>
00066 #else
00067         public boost::hash<Key* const>
00068 #endif
00069     {
00070     public:
00071         ptrdiff_t operator()(wns::SmartPtr<Key> const k) const {
00072             return ((ptrdiff_t)(k.get()));
00073         };
00074     };
00075 
00077 
00078     template<class Key, class Value>
00079     class PointerHashMap :
00080 #ifdef WNS_USE_OLD_HASH_MAP
00081         public __gnu_cxx::hash_map<Key const,
00082 #else
00083         public boost::unordered_map<Key const,
00084 #endif
00085                                    Value,
00086                                    PointerHashMapFunctor<Key>,
00087                                    std::equal_to<Key> > {
00088     public:
00089         PointerHashMap() :
00090 #ifdef WNS_USE_OLD_HASH_MAP
00091             __gnu_cxx::hash_map<Key const,
00092 #else
00093             boost::unordered_map<Key const,
00094 #endif
00095                                 Value,
00096                                 PointerHashMapFunctor<Key>,
00097                                 std::equal_to<Key> >() {};
00098 
00099         virtual ~PointerHashMap() {};
00100 
00101         virtual bool contains(Key k) const {
00102             return find(k)!=this->end();
00103         };
00104 };
00105 
00106 }
00107 #endif
00108 
00109 

Generated on Sun May 27 03:31:56 2012 for openWNS by  doxygen 1.5.5