Boost logo

Boost :

From: Carlo Wood (carlo_at_[hidden])
Date: 2002-09-03 20:37:56


Hi again,

I've tried to implement the interface that we came up with,
but... unfortunately I've come to the conclusion that it
makes no sense.

The fact that sensible output in case of a failure is expected
and needed means we cannot write directly to an output iterator:
it is very well possible that halfway the decoding we find that
the mangled string that is being passed cannot be demangled.

It is also not possible to use exceptions, since those call
malloc() as well in certain cases (for example g++ configured
with --enable-slsj-exceptions).

I have to conclude that the only way to go is to write to
a temporary buffer (of the type
std::basic_string<char, std::char_traits<char>, Allocator>)
and think that is makes no sense not also return this string
in that form (instead of using iterators).

Also, the input iterator cannot be used because the code
makes use of pointers into it at arbitrary places. Using
an input iterator would only be possible if we'd first copy
the whole input to a temporal string - and that makes no sense.

That, combined with the fact that the origin of the mangled names
are char const* to begin with, I see only one general interface
that makes sense:

namespace boost {

  template<typename Allocator>
    struct demangler {
      static std::basic_string<char, std::char_traits<char>, Allocator>
        type(char const* in);
      static std::basic_string<char, std::char_traits<char>, Allocator>
        symbol(char const* in);
    };

}

Here I dropped the appending, so the output variable is
just the return value. The struct is used in order to
allow a typedef (handy because there is no Allocator in the
function input parameters).

The normal usage of the demangler will then be:

typedef boost::demangler<std::allocator<char> > demangle;

std::cout << demangle::type(typeid(OBJECT).name()) << '\n';

I don't want to add the typedef in the boost header because
that will instantiate the demangler for std::allocator<char>.
Therefore I'll provide (documented) wrappers for the lesser
gifted with a #ifndef BOOST_DEMANGLER_NOWRAPPERS .. #endif
around it. As a result, people who use the <demangler.h>
headerfile without defining BOOST_DEMANGLER_NOWRAPPERS will
get a nice, simple interface like:

  std::string result = boost::demangle(typeid(OBJECT));

or whatever people on this list think is needed in order
not to confuse developers who need to debug C++ code but
never heard of allocators...

-- 
Carlo Wood <carlo_at_[hidden]>

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk