]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Move some generic stuff to subr.hh
authorRoland McGrath <roland@redhat.com>
Wed, 25 Mar 2009 02:09:20 +0000 (19:09 -0700)
committerRoland McGrath <roland@redhat.com>
Wed, 25 Mar 2009 02:09:20 +0000 (19:09 -0700)
libdw/c++/dwarf
libdw/c++/subr.hh

index 862b9a14666516e8dd0370ae142a782e578ff418..8d0737292b6594673172983af44fa0420f14448a 100644 (file)
@@ -55,9 +55,6 @@
 #include "subr.hh"
 #include <stdexcept>
 
-#include <cstring>
-#include <iostream>
-#include <sstream>
 #include <list>
 #include <map>
 #include <set>
@@ -231,35 +228,13 @@ namespace elfutils
   // One DWARF object file.
   class dwarf
   {
-  private:
-    template<const char *lookup_known (int)>
-    static inline std::string known_name (int code)
-    {
-      const char *known = lookup_known (code);
-      if (known != NULL)
-       return std::string (known);
-      std::ostringstream os;
-      os.setf(std::ios::hex, std::ios::basefield);
-      os << code;
-      return os.str ();
-    }
-
-    template<typename string>
-    struct name_equal : public std::binary_function<const char *, string, bool>
-    {
-      bool operator () (const char *me, const string &you)
-      {
-       return you == me;
-      }
-    };
-
   public:
     static const char *known_attribute (int);
     static const char *known_tag (int);
 
     static inline std::string tag_name (int code)
     {
-      return known_name<known_tag> (code);
+      return subr::known_name<known_tag> (code);
     }
 
     template<typename attribute>
@@ -271,7 +246,7 @@ namespace elfutils
 
     static inline std::string attribute_name (const unsigned int code)
     {
-      return known_name<known_attribute> (code);
+      return subr::known_name<known_attribute> (code);
     }
 
   private:
@@ -1011,7 +986,8 @@ namespace elfutils
            if (other_size != 0 && other_size != size ())
              return false;
          }
-       return name_equal<typeof (other.name ())> () (name (), other.name ());
+       return subr::name_equal<typeof (other.name ())> () (name (),
+                                                           other.name ());
       }
       template<typename other_file>
       inline bool operator!= (const other_file &other) const
@@ -1134,11 +1110,11 @@ namespace elfutils
              return source_column () == other.source_column ();
 
            case VS_identifier:
-             return name_equal<typeof (other.identifier ())> ()
+             return subr::name_equal<typeof (other.identifier ())> ()
                (identifier (), other.identifier ());
 
            case VS_string:
-             return name_equal<typeof (other.string ())> ()
+             return subr::name_equal<typeof (other.string ())> ()
                (string (), other.string ());
 
            case VS_address:
@@ -1448,7 +1424,7 @@ namespace elfutils
        typename table::const_iterator j = other.begin ();
        return subr::container_equal
          (++i, end (), ++j, other.end (),
-          name_equal<typename table::value_type> ());
+          subr::name_equal<typename table::value_type> ());
       }
 
     public:
@@ -2180,17 +2156,6 @@ namespace elfutils
       }
   };
 
-  // Explicit specialization used inside dwarf::directory_table::operator==.
-  template<>
-  struct dwarf::name_equal<const char *>
-    : public std::binary_function<const char *, const char *, bool>
-  {
-    bool operator () (const char *me, const char *you)
-    {
-      return !strcmp (me, you);
-    }
-  };
-
   inline class dwarf::debug_info_entry::raw_children
   dwarf::debug_info_entry::raw_children () const
   {
index d9392c35395fca006f30c3ee5a650326d243b742..ef632e57a433307cf35a8fb67869a419b0bc5d5b 100644 (file)
@@ -7,11 +7,46 @@
 
 #include <iterator>
 #include <functional>
+#include <cstring>
+#include <iostream>
+#include <sstream>
 
 namespace elfutils
 {
   namespace subr
   {
+    template<typename string>
+    struct name_equal : public std::binary_function<const char *, string, bool>
+    {
+      inline bool operator () (const char *me, const string &you)
+      {
+       return you == me;
+      }
+    };
+
+    // Explicit specialization.
+    template<>
+    struct name_equal<const char *>
+      : public std::binary_function<const char *, const char *, bool>
+    {
+      bool operator () (const char *me, const char *you)
+      {
+       return !strcmp (me, you);
+      }
+    };
+
+    template<const char *lookup_known (int)>
+    static inline std::string known_name (int code)
+    {
+      const char *known = lookup_known (code);
+      if (known != NULL)
+       return std::string (known);
+      std::ostringstream os;
+      os.setf(std::ios::hex, std::ios::basefield);
+      os << code;
+      return os.str ();
+    }
+
     template<typename t1, typename t2>
     struct equal_to : public std::binary_function<t1, t2, bool>
     {