]> sourceware.org Git - systemtap.git/commitdiff
Provide backward-compatible unordered_map/set
authorJosh Stone <jistone@redhat.com>
Wed, 2 Sep 2009 23:43:58 +0000 (16:43 -0700)
committerJosh Stone <jistone@redhat.com>
Thu, 3 Sep 2009 00:13:14 +0000 (17:13 -0700)
We were defining our own stap_map with a ::type to let us use typedefs
to use the new unordered_map if available, or hash_map otherwise.  Since
unordered_map is the future direction, I'm changing our code to use that
directly.  The backward-compatible version is a #define to hash_map,
which has a compatible interface.

While I'm at it, let's also define unordered_multimap, unordered_set,
and unordered_multiset.

* unordered.h: New.
* dwflpp.h (stap_map): Removed.
  (cache typedefs): Use the unordered name now.

dwflpp.h
unordered.h [new file with mode: 0644]

index 047ad6021ae9204f4e6d06f7a6688b3d6d99fc2c..9ed185589876e2523edc840e4932da3624549334 100644 (file)
--- a/dwflpp.h
+++ b/dwflpp.h
@@ -15,6 +15,7 @@
 #include "dwarf_wrappers.h"
 #include "elaborate.h"
 #include "session.h"
+#include "unordered.h"
 
 #include <cstring>
 #include <iostream>
@@ -43,33 +44,17 @@ struct dwarf_query;
 enum line_t { ABSOLUTE, RELATIVE, RANGE, WILDCARD };
 enum info_status { info_unknown, info_present, info_absent };
 
-#ifdef HAVE_TR1_UNORDERED_MAP
-#include <tr1/unordered_map>
-template<class K, class V> struct stap_map {
-  typedef std::tr1::unordered_map<K, V> type;
-};
-#else
-#include <ext/hash_map>
-template<class K, class V> struct stap_map {
-  typedef __gnu_cxx::hash_map<K, V, stap_map> type;
-  size_t operator() (std::string const& s) const
-  { __gnu_cxx::hash<const char*> h; return h(s.c_str()); }
-  size_t operator() (void* const& p) const
-  { __gnu_cxx::hash<long> h; return h(reinterpret_cast<long>(p)); }
-};
-#endif
-
 // module -> cu die[]
-typedef stap_map<Dwarf*, std::vector<Dwarf_Die>*>::type module_cu_cache_t;
+typedef unordered_map<Dwarf*, std::vector<Dwarf_Die>*> module_cu_cache_t;
 
 // function -> die
-typedef stap_map<std::string, Dwarf_Die>::type cu_function_cache_t;
+typedef unordered_map<std::string, Dwarf_Die> cu_function_cache_t;
 
 // cu die -> (function -> die)
-typedef stap_map<void*, cu_function_cache_t*>::type mod_cu_function_cache_t;
+typedef unordered_map<void*, cu_function_cache_t*> mod_cu_function_cache_t;
 
 // inline function die -> instance die[]
-typedef stap_map<void*, std::vector<Dwarf_Die>*>::type cu_inl_function_cache_t;
+typedef unordered_map<void*, std::vector<Dwarf_Die>*> cu_inl_function_cache_t;
 
 typedef std::vector<func_info> func_info_map_t;
 typedef std::vector<inline_instance_info> inline_instance_map_t;
diff --git a/unordered.h b/unordered.h
new file mode 100644 (file)
index 0000000..6204dbf
--- /dev/null
@@ -0,0 +1,56 @@
+// backward-compatible unordered containers
+// Copyright (C) 2009 Red Hat Inc.
+//
+// This file is part of systemtap, and is free software.  You can
+// redistribute it and/or modify it under the terms of the GNU General
+// Public License (GPL); either version 2, or (at your option) any
+// later version.
+
+#ifndef UNORDERED_H
+#define UNORDERED_H
+
+#include "config.h"
+
+#if 0 // uncomment to force the old mode
+#undef HAVE_TR1_UNORDERED_MAP
+#define _BACKWARD_BACKWARD_WARNING_H 1 // defeat deprecation warning
+#endif
+
+#ifdef HAVE_TR1_UNORDERED_MAP
+
+#include <tr1/unordered_map>
+using std::tr1::unordered_map;
+using std::tr1::unordered_multimap;
+
+#include <tr1/unordered_set>
+using std::tr1::unordered_set;
+using std::tr1::unordered_multiset;
+
+#else
+
+#include <ext/hash_map>
+#define unordered_map __gnu_cxx::hash_map
+#define unordered_multimap __gnu_cxx::hash_multimap
+
+#include <ext/hash_set>
+#define unordered_set __gnu_cxx::hash_set
+#define unordered_multiset __gnu_cxx::hash_multiset
+
+// Hack in common hash functions for strings and raw pointers
+namespace __gnu_cxx
+{
+  template<class T> struct hash<T*> {
+    size_t operator() (T* p) const
+    { hash<long> h; return h(reinterpret_cast<long>(p)); }
+  };
+  template<> struct hash<std::string> {
+    size_t operator() (std::string const& s) const
+    { hash<const char*> h; return h(s.c_str()); }
+  };
+}
+
+#endif
+
+#endif // UNORDERED_H
+
+/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
This page took 0.029439 seconds and 5 git commands to generate.