I fiddled dwarf_output on roland/dwarf-collector some more on Monday,
but forgot to post about it. I did the value_dispatch stuff to get the
constructors passed the collector pointer. I did one attr_value flavor
(strings) in the collector to maybe indicate how others would go.
But then it occurred to me that perhaps the collector's sets should contain
the value_foobar objects that value_dispatch points to, rather than have a
"new value_foobar" for each that actually just holds a pointer/reference
into a collector value_set. I started hacking for that on top of
roland/dwarf-collector (0206412) but did not get it to the point of compiling.
Non-compiling unfinished patch below.
The concept is that dwarf_output::value_wrapper::make can
be defined with a separate overload for each flavor, and
those will return a pointer into a collector value_set.
Thanks,
Roland
diff --git a/libdw/c++/dwarf_output b/libdw/c++/dwarf_output
index 6c5fe51..f1a0128 100644
--- a/libdw/c++/dwarf_output
+++ b/libdw/c++/dwarf_output
@@ -271,6 +271,8 @@ namespace elfutils
class dwarf_output
{
+ friend class dwarf_output_collector;
+
public:
typedef dwarf_data::source_file source_file;
typedef dwarf_data::directory_table directory_table;
@@ -288,10 +290,6 @@ namespace elfutils
protected:
template<typename input>
- static inline const std::string &
- collect_string (dwarf_output_collector *, const input &);
-
- template<typename input>
static inline const range_list &
collect (dwarf_output_collector *, const typename input::range_list &);
@@ -334,28 +332,18 @@ namespace elfutils
struct value_wrapper
: public dwarf_data::value<dwarf_output, dwarf_output_collector *>
{
- struct value_string : public value_dispatch
+ // XXX Generic case, goes away when all types complete(?)
+ template<typename flavor, typename input>
+ static inline value_dispatch *
+ make (flavor *&result, const input &x, dwarf_output_collector *c)
{
- const std::string &_m_str;
-
- template<typename string>
- inline value_string (const string &s, dwarf_output_collector *c)
- : _m_str (collect_string (c, s))
- {}
+ return result = new flavor (x, c);
+ }
- inline operator const std::string & () const
- {
- return _m_str;
- }
-
- std::string to_string () const
- {
- std::string result ("\"");
- result += _m_str;
- result += "\"";
- return result;
- }
- };
+ template<typename input>
+ static inline value_dispatch *make (value_string *result,
+ const input &x,
+ dwarf_output_collector *);
};
public:
@@ -580,16 +568,18 @@ namespace elfutils
friend class dwarf_output;
private:
- subr::value_set<std::string> _m_strings;
+ subr::value_set<dwarf_output::value_wrapper::value_string> _m_strings;
subr::value_set<dwarf_output::range_list> _m_ranges;
};
template<typename input>
- inline const std::string &
- dwarf_output::collect_string (dwarf_output_collector *c, const input &s)
+ inline dwarf_output::value_wrapper::value_dispatch *
+ dwarf_output::value_wrapper::make
+ (dwarf_output::value_wrapper::value_string *result,
+ const input &x, dwarf_output_collector *c)
{
- return c->_m_strings.add (s);
+ return c->_m_strings.add (x);
}
template<typename input>
Show replies by date