stdExt.h

Go to the documentation of this file.
00001 
00002 /* Copyright (c) 2006-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00024 #ifndef EQBASE_STDEXT_H
00025 #define EQBASE_STDEXT_H
00026 
00027 #include <algorithm>
00028 #include <string>
00029 
00030 //----- Common extensions of the STL
00031 #ifdef __GNUC__              // GCC 3.1 and later
00032 #  include <ext/hash_map>
00033 #  include <ext/hash_set>
00034 /* Alias stde namespace to uniformly access stl extensions. */
00035 namespace stde = __gnu_cxx; 
00036 #else                        //  other compilers
00037 #  include <hash_map>
00038 #  include <hash_set>
00039 #  ifdef WIN32
00040 /* Alias stde namespace to uniformly access stl extensions. */
00041 namespace stde = stdext;
00042 #  else
00043 /* Alias stde namespace to uniformly access stl extensions. */
00044 namespace stde = std;
00045 #  endif
00046 #endif
00047 
00048 
00049 //----- Our extensions of the STL 
00050 #ifdef __GNUC__              // GCC 3.1 and later
00051 namespace __gnu_cxx
00052 #elif defined (WIN32)
00053 namespace stdext
00054 #else //  other compilers
00055 namespace std
00056 #endif
00057 {
00058 #  ifdef __GNUC__
00059 #    ifndef EQ_HAVE_STRING_HASH
00060 
00061     template<> 
00062     struct hash< std::string >
00063     {
00064         size_t operator()( const std::string& str ) const
00065         {
00066             return hash< const char* >()( str.c_str() );
00067         }
00068     };
00069 #    endif
00070 
00071 #    ifndef EQ_HAVE_VOID_PTR_HASH
00072 
00073     template<> 
00074     struct hash< void* >
00075     {
00076         template< typename P >
00077         size_t operator()( const P& key ) const
00078         {
00079             return reinterpret_cast<size_t>(key);    
00080         }
00081     };
00082     template<> 
00083     struct hash< const void* >
00084     {
00085         template< typename P >
00086         size_t operator()( const P& key ) const
00087         {
00088             return reinterpret_cast<size_t>(key);    
00089         }
00090     };
00091 #    endif
00092 
00093 #  else // WIN32
00094 #    ifndef EQ_HAVE_STRING_HASH
00095 
00097     template<>
00098     inline size_t hash_compare< std::string >::operator()
00099         ( const std::string& key ) const
00100     {
00101         return hash_value( key.c_str( ));
00102     }
00103 
00104 #    endif
00105 #  endif
00106 
00108     template< typename C >
00109     void usort( C& c )
00110     {
00111         std::sort( c.begin(), c.end( ));
00112         c.erase( std::unique( c.begin(), c.end( )), c.end( ));
00113     }
00114 }
00115 
00116 #endif // EQBASE_STDEXT_H
Generated on Mon Aug 10 18:58:41 2009 for Equalizer 0.9 by  doxygen 1.5.8