BIE |
/home/weinberg/src/BIE/include/hash_map_gnu_cxx.h00001 00002 00003 #ifndef hash_map_gnu_cxx_h 00004 #define hash_map_gnu_cxx_h 00005 #include <ext/hash_map> 00006 #include <string> 00007 00008 /* Thu Jan 31 21:58:35 EST 2008 - bchoi 00009 * 00010 * Serialization code for hash_map 00011 * #including <boost/serialization/hash_map.hpp> does not work at the moment 00012 * There is some discussion online 00013 * http://archives.free.net.ph/message/20071217.105431.2d332fc1.en.html 00014 * 00015 * But their solution requires changes to the headers which breaks portability 00016 * Instead, we're including the relevant code here. 00017 * The following code is copied directly from <boost/serialization/hash_map.hpp> 00018 */ 00019 #include <boost/version.hpp> 00020 #include <boost/serialization/hash_map.hpp> 00021 #include <boost/serialization/string.hpp> 00022 #include <boost/serialization/type_info_implementation.hpp> 00023 #include <boost/serialization/extended_type_info_typeid.hpp> 00024 00025 #include <boost/serialization/utility.hpp> 00026 #include <boost/serialization/collections_save_imp.hpp> 00027 #include <boost/serialization/collections_load_imp.hpp> 00028 #include <boost/serialization/split_free.hpp> 00029 00030 namespace boost { 00031 namespace serialization { 00032 00033 template<class Archive, class Key, class Data, class HashFn, 00034 class Compare, class Allocator > 00035 inline void save( 00036 Archive & ar, 00037 const __gnu_cxx::hash_map<Key, Data, HashFn, Compare, Allocator> &t, 00038 const unsigned int file_version 00039 ){ 00040 boost::serialization::stl::save_collection< 00041 Archive, 00042 __gnu_cxx::hash_map<Key, Data, HashFn, Compare, Allocator> 00043 >(ar, t); 00044 } 00045 00046 template<class Archive, class Key, class Data, class HashFn, 00047 class Compare, class Allocator > 00048 inline void load( 00049 Archive & ar, 00050 __gnu_cxx::hash_map<Key, Data, HashFn, Compare, Allocator> &t, 00051 const unsigned int file_version 00052 ){ 00053 boost::serialization::stl::load_collection< 00054 Archive, 00055 __gnu_cxx::hash_map<Key, Data, HashFn, Compare, Allocator>, 00056 #if ((BOOST_VERSION / 100) % 1000) < 36 00057 boost::serialization::stl::archive_input_unique< 00058 #else 00059 boost::serialization::stl::archive_input_map< 00060 #endif 00061 Archive, 00062 __gnu_cxx::hash_map<Key, Data, HashFn, Compare, Allocator> 00063 >, 00064 boost::serialization::stl::no_reserve_imp< 00065 __gnu_cxx::hash_map<Key, Data, HashFn, Compare, Allocator> 00066 > 00067 >(ar, t); 00068 } 00069 00072 template<class Archive, class Key, class Data, class HashFn, 00073 class Compare, class Allocator > 00074 inline void serialize( 00075 Archive & ar, 00076 __gnu_cxx::hash_map<Key, Data, HashFn, Compare, Allocator> &t, 00077 const unsigned int file_version 00078 ){ 00079 boost::serialization::split_free(ar, t, file_version); 00080 } 00081 00082 // hash_multimap 00083 template<class Archive, class Key, class Data, class HashFn, 00084 class Compare, class Allocator > 00085 inline void save( 00086 Archive & ar, 00087 const __gnu_cxx::hash_multimap<Key, Data, HashFn, Compare, Allocator> &t, 00088 const unsigned int file_version 00089 ){ 00090 boost::serialization::stl::save_collection< 00091 Archive, 00092 __gnu_cxx::hash_multimap<Key, Data, HashFn, Compare, Allocator> 00093 >(ar, t); 00094 } 00095 00096 template<class Archive, class Key, class Data, class HashFn, 00097 class Compare, class Allocator > 00098 inline void load( 00099 Archive & ar, 00100 __gnu_cxx::hash_multimap<Key, Data, HashFn, Compare, Allocator> &t, 00101 const unsigned int file_version 00102 ){ 00103 boost::serialization::stl::load_collection< 00104 Archive, 00105 __gnu_cxx::hash_multimap<Key, Data, HashFn, Compare, Allocator>, 00106 #if ((BOOST_VERSION / 100) % 1000) < 36 00107 boost::serialization::stl::archive_input_multi< 00108 #else 00109 boost::serialization::stl::archive_input_multimap< 00110 #endif 00111 Archive, 00112 __gnu_cxx::hash_multimap<Key, Data, HashFn, Compare, Allocator> 00113 >, 00114 boost::serialization::stl::no_reserve_imp< 00115 __gnu_cxx::hash_multimap<Key, Data, HashFn, Compare, Allocator> 00116 > 00117 >(ar, t); 00118 } 00119 00122 template<class Archive, class Key, class Data, class HashFn, 00123 class Compare, class Allocator > 00124 inline void serialize(Archive & ar, 00125 __gnu_cxx::hash_multimap<Key, Data, HashFn, 00126 Compare, Allocator> &t, 00127 const unsigned int file_version 00128 ){ 00129 boost::serialization::split_free(ar, t, file_version); 00130 } 00131 00133 template<class Key, class Data, class HashFn, class Compare, class Allocator > 00134 struct type_info_implementation< 00135 __gnu_cxx::hash_map<Key, Data, HashFn, Compare, Allocator> > { 00137 typedef extended_type_info_typeid< 00138 __gnu_cxx::hash_map<Key, Data, HashFn, Compare, Allocator> > type; 00139 }; 00140 00142 template<class Key, class Data, class HashFn, class Compare, class Allocator > 00143 struct type_info_implementation< 00144 const __gnu_cxx::hash_map<Key, Data, HashFn, Compare, Allocator> > { 00146 typedef extended_type_info_typeid< 00147 __gnu_cxx::hash_map<Key, Data, HashFn, Compare, Allocator> > type; 00148 }; 00149 00151 template<class Key, class Data > 00152 struct type_info_implementation< std::pair<Key, Data> > { 00154 typedef extended_type_info_typeid< std::pair<Key, Data> > type; 00155 }; 00156 00158 template<class Key, class Data > 00159 struct type_info_implementation< const std::pair<Key, Data> > { 00161 typedef extended_type_info_typeid< std::pair<Key, Data> > type; 00162 }; 00163 } // namespace serialization 00164 } // namespace boost 00165 // End of serialization code 00166 00167 #define HASHMAP_NAMESPACE_BEGIN namespace __gnu_cxx { 00168 #define HASHMAP_NAMESPACE_END } 00169 00180 HASHMAP_NAMESPACE_BEGIN 00182 template<> 00183 struct hash<std::string> { 00185 size_t operator()(const std::string& x) const { 00186 return hash<const char*>()( x.c_str() ); 00187 } 00188 }; 00189 00191 template<> 00192 struct hash<const std::string> { 00194 size_t operator()(const std::string& x) const { 00195 return hash<const char*>()( x.c_str() ); 00196 } 00197 }; 00198 00218 HASHMAP_NAMESPACE_END 00219 00220 using __gnu_cxx::hash; 00221 00222 namespace bie { 00224 template<class _Key, class _Tp, 00225 class _Hash = hash<_Key>, 00226 class _Pred = std::equal_to<_Key>, 00227 class _Alloc = std::allocator<std::pair<const _Key, _Tp> > > 00228 struct hashers 00229 { 00231 typedef __gnu_cxx::hash_map<_Key, _Tp, _Hash, _Pred, _Alloc> 00232 MapType; 00234 typedef __gnu_cxx::hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc> 00235 MultiMapType; 00236 }; 00237 } 00238 00239 #endif// hash_map_pre_gcc_4_3_h Send suggestions, questions, and feedback to WEINBERG at ASTRO dot UMASS dot EDU. Documentation generated at Fri Mar 26 00:35:10 2010 by
|