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

misc/hash.hh

Go to the documentation of this file.
00001 // Copyright (C) 2003  Laboratoire d'Informatique de Paris 6 (LIP6),
00002 // département Systèmes Répartis Coopératifs (SRC), Université Pierre
00003 // et Marie Curie.
00004 //
00005 // This file is part of Spot, a model checking library.
00006 //
00007 // Spot is free software; you can redistribute it and/or modify it
00008 // under the terms of the GNU General Public License as published by
00009 // the Free Software Foundation; either version 2 of the License, or
00010 // (at your option) any later version.
00011 //
00012 // Spot is distributed in the hope that it will be useful, but WITHOUT
00013 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00014 // or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
00015 // License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Spot; see the file COPYING.  If not, write to the Free
00019 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00020 // 02111-1307, USA.
00021 
00022 #ifndef SPOT_MISC_HASH_HH
00023 #  define SPOT_MISC_HASH_HH
00024 
00025 #  include <string>
00026 #  include <functional>
00027 
00028 // See the G++ FAQ for details about the following.
00029 #  ifdef __GNUC__
00030 #  if __GNUC__ < 3
00031 #    include <hash_map.h>
00032 #    include <hash_set.h>
00033     namespace Sgi
00034     { // inherit globals
00035       using ::hash_map;
00036       using ::hash_set;
00037       using ::hash;
00038     };
00039 #  else
00040 #    include <ext/hash_map>
00041 #    include <ext/hash_set>
00042 #    if __GNUC_MINOR__ == 0
00043       namespace Sgi = std;               // GCC 3.0
00044 #    else
00045       namespace Sgi = ::__gnu_cxx;       // GCC 3.1 and later
00046 #    endif
00047 #  endif
00048 #  else      // ...  there are other compilers, right?
00049 #   include <hash_map>
00050 #   include <hash_set>
00051     namespace Sgi = std;
00052 #  endif
00053 
00054 namespace spot
00055 {
00056 
00058   template <class T>
00059   struct ptr_hash :
00060     public std::unary_function<const T*, size_t>
00061   {
00062     size_t operator()(const T* p) const
00063     {
00064       return reinterpret_cast<const char*>(p) - static_cast<const char*>(0);
00065     }
00066   };
00067 
00069   struct string_hash :
00070     public Sgi::hash<const char*>,
00071     public std::unary_function<const std::string&, size_t>
00072   {
00073     size_t operator()(const std::string& s) const
00074     {
00075       // We are living dangerously.  Be sure to call operator()
00076       // from the super-class, not this one.
00077       return Sgi::hash<const char*>::operator()(s.c_str());
00078     }
00079   };
00080 }
00081 
00082 #endif // SPOT_MISC_HASH_HH

Generated on Tue Jan 13 18:18:21 2004 for spot by doxygen 1.3.5