X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Finclude%2Fvirtual-methods.hh;h=b3b9cf008ec084c74d3a00e2b6d9767e2ea76ab4;hb=0e5d83a9ceb4a143f83d22406d7eb816314ff9f7;hp=e4dcd8ade673bb938744430881b5d7020fef2a84;hpb=bdf4ab13203502e7ec7cf9cf5896527643a07c1f;p=lilypond.git diff --git a/flower/include/virtual-methods.hh b/flower/include/virtual-methods.hh index e4dcd8ade6..b3b9cf008e 100644 --- a/flower/include/virtual-methods.hh +++ b/flower/include/virtual-methods.hh @@ -3,39 +3,42 @@ source file of the Flower Library - (c) 1997--2005 Han-Wen Nienhuys + (c) 1997--2009 Han-Wen Nienhuys */ #ifndef VIRTUAL_METHODS_HH #define VIRTUAL_METHODS_HH #include +using namespace std; #define classname(class_ptr) demangle_classname (typeid (* (class_ptr))) -const char * -demangle_classname (std::type_info const &); - -/* Virtual copy constructor. Make up for C++'s lack of a standard - factory or clone () function. Uses a typeof hack. Usage: - - class Foo : Baseclass - { - VIRTUAL_COPY_CONSTRUCTOR (Baseclass, Foo); - }; */ - -#define VIRTUAL_COPY_CONSTRUCTOR(Base, name) \ - /* Hack to fix constness: gcc >= 2.95 is correct in defining \ - typeof (*this) in a const member function to be const. */ \ - virtual Base *clone_const_helper () \ - { \ - return new name (*this); \ - } \ - virtual Base *clone () const \ - { \ - /* return new name (*this); */ \ - Base *urg = (Base *) this; \ - return urg->clone_const_helper (); \ +char const * +demangle_classname (type_info const &); + +/* + +Virtual copy constructor. Make up for C++'s lack of a standard +factory or clone () function. Usage: + +class Foo : Baseclass +{ +VIRTUAL_COPY_CONSTRUCTOR (Baseclass, Foo); +}; + +*/ + +#define DECLARE_CLASSNAME(name) \ + virtual const char *class_name () const { \ + return #name; \ +} + +#define VIRTUAL_COPY_CONSTRUCTOR(Base, name) \ + DECLARE_CLASSNAME(name);\ + virtual Base *clone () const \ + { \ + return new name (*this); \ } #endif /* VIRTUAL_METHODS_HH */