From: Roland McGrath Date: Wed, 25 Mar 2009 02:09:20 +0000 (-0700) Subject: Move some generic stuff to subr.hh X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=eb5efaff729e02f8043147f07e85af5ee13e613e;p=thirdparty%2Felfutils.git Move some generic stuff to subr.hh --- diff --git a/libdw/c++/dwarf b/libdw/c++/dwarf index 862b9a146..8d0737292 100644 --- a/libdw/c++/dwarf +++ b/libdw/c++/dwarf @@ -55,9 +55,6 @@ #include "subr.hh" #include -#include -#include -#include #include #include #include @@ -231,35 +228,13 @@ namespace elfutils // One DWARF object file. class dwarf { - private: - template - 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 - struct name_equal : public std::binary_function - { - 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 (code); + return subr::known_name (code); } template @@ -271,7 +246,7 @@ namespace elfutils static inline std::string attribute_name (const unsigned int code) { - return known_name (code); + return subr::known_name (code); } private: @@ -1011,7 +986,8 @@ namespace elfutils if (other_size != 0 && other_size != size ()) return false; } - return name_equal () (name (), other.name ()); + return subr::name_equal () (name (), + other.name ()); } template 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 () + return subr::name_equal () (identifier (), other.identifier ()); case VS_string: - return name_equal () + return subr::name_equal () (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 ()); + subr::name_equal ()); } public: @@ -2180,17 +2156,6 @@ namespace elfutils } }; - // Explicit specialization used inside dwarf::directory_table::operator==. - template<> - struct dwarf::name_equal - : public std::binary_function - { - 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 { diff --git a/libdw/c++/subr.hh b/libdw/c++/subr.hh index d9392c353..ef632e57a 100644 --- a/libdw/c++/subr.hh +++ b/libdw/c++/subr.hh @@ -7,11 +7,46 @@ #include #include +#include +#include +#include namespace elfutils { namespace subr { + template + struct name_equal : public std::binary_function + { + inline bool operator () (const char *me, const string &you) + { + return you == me; + } + }; + + // Explicit specialization. + template<> + struct name_equal + : public std::binary_function + { + bool operator () (const char *me, const char *you) + { + return !strcmp (me, you); + } + }; + + template + 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 struct equal_to : public std::binary_function {