X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Finclude%2Fvirtual-methods.hh;h=b3b9cf008ec084c74d3a00e2b6d9767e2ea76ab4;hb=8cab78caa0db1ba14f2e52e4c1ddbb541ea0e5cb;hp=44cf1fcaab5cafc527e4cdda93722de9c3fdb207;hpb=7a12ad94b16c45bdac527d2a75df23a369799712;p=lilypond.git diff --git a/flower/include/virtual-methods.hh b/flower/include/virtual-methods.hh index 44cf1fcaab..b3b9cf008e 100644 --- a/flower/include/virtual-methods.hh +++ b/flower/include/virtual-methods.hh @@ -3,42 +3,42 @@ source file of the Flower Library - (c) 1997--2004 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))) + +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 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); - }; */ - -Base *clone () const { return new Name (*this); } - -#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 (); \ - } +#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 */