#include <cstdlib>
#include <iostream>
#include <typeinfo>
#include <cxxabi.h>
class AutoRegister
{
class InitializerPrivate
{
};
public:
explicit AutoRegister(const InitializerPrivate&)
{
}
template <class Child>
class Initializer : public InitializerPrivate
{
class StaticInit
{
public:
StaticInit()
{
int status;
char *childName = abi::__cxa_demangle(typeid(Child).name(), 0, 0, &status);
std::cout << "Registering child: " << childName << std::endl;
// XXX: qRegisterMetaType<EventFoo>("EventFoo");
std::free(childName);
}
void nop() const
{
}
};
static const StaticInit _init;
public:
explicit Initializer()
{
_init.nop();
}
};
};
class BaseEvent : protected virtual AutoRegister
{
public:
explicit BaseEvent() : AutoRegister(Initializer<BaseEvent>())
{
}
};
class EventFoo : public BaseEvent
{
public:
explicit EventFoo() : AutoRegister(Initializer<EventFoo>())
{
}
};
class EventBar : public BaseEvent
{
public:
explicit EventBar() : AutoRegister(Initializer<EventBar>())
{
}
};
template<class T>
const typename AutoRegister::Initializer<T>::StaticInit AutoRegister::Initializer<T>::_init = typename AutoRegister::Initializer<T>::StaticInit();
int main(void)
{
return 0;
}
I2luY2x1ZGUgPGNzdGRsaWI+CgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDx0eXBlaW5mbz4KCiNpbmNsdWRlIDxjeHhhYmkuaD4KCmNsYXNzIEF1dG9SZWdpc3Rlcgp7CiAgICBjbGFzcyBJbml0aWFsaXplclByaXZhdGUKICAgIHsKICAgIH07CgpwdWJsaWM6CiAgICBleHBsaWNpdCBBdXRvUmVnaXN0ZXIoY29uc3QgSW5pdGlhbGl6ZXJQcml2YXRlJikKICAgIHsKICAgIH0KCiAgICB0ZW1wbGF0ZSA8Y2xhc3MgQ2hpbGQ+CiAgICBjbGFzcyBJbml0aWFsaXplciA6IHB1YmxpYyBJbml0aWFsaXplclByaXZhdGUKICAgIHsKICAgICAgICBjbGFzcyBTdGF0aWNJbml0CiAgICAgICAgewogICAgICAgIHB1YmxpYzoKICAgICAgICAgICAgU3RhdGljSW5pdCgpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGludCBzdGF0dXM7CiAgICAgICAgICAgICAgICBjaGFyICpjaGlsZE5hbWUgPSBhYmk6Ol9fY3hhX2RlbWFuZ2xlKHR5cGVpZChDaGlsZCkubmFtZSgpLCAwLCAwLCAmc3RhdHVzKTsKICAgICAgICAgICAgICAgIHN0ZDo6Y291dCA8PCAiUmVnaXN0ZXJpbmcgY2hpbGQ6ICIgPDwgY2hpbGROYW1lIDw8IHN0ZDo6ZW5kbDsKICAgICAgICAgICAgICAgIC8vIFhYWDogcVJlZ2lzdGVyTWV0YVR5cGU8RXZlbnRGb28+KCJFdmVudEZvbyIpOwogICAgICAgICAgICAgICAgc3RkOjpmcmVlKGNoaWxkTmFtZSk7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIHZvaWQgbm9wKCkgY29uc3QKICAgICAgICAgICAgewoKICAgICAgICAgICAgfQogICAgICAgIH07CgogICAgICAgIHN0YXRpYyBjb25zdCBTdGF0aWNJbml0IF9pbml0OwoKICAgIHB1YmxpYzoKICAgICAgICBleHBsaWNpdCBJbml0aWFsaXplcigpCiAgICAgICAgewogICAgICAgICAgICBfaW5pdC5ub3AoKTsKICAgICAgICB9CiAgICB9Owp9OwoKY2xhc3MgQmFzZUV2ZW50IDogcHJvdGVjdGVkIHZpcnR1YWwgQXV0b1JlZ2lzdGVyCnsKcHVibGljOgogICAgZXhwbGljaXQgQmFzZUV2ZW50KCkgOiBBdXRvUmVnaXN0ZXIoSW5pdGlhbGl6ZXI8QmFzZUV2ZW50PigpKQogICAgewogICAgfQp9OwoKY2xhc3MgRXZlbnRGb28gOiBwdWJsaWMgQmFzZUV2ZW50CnsKcHVibGljOgogICAgZXhwbGljaXQgRXZlbnRGb28oKSA6IEF1dG9SZWdpc3RlcihJbml0aWFsaXplcjxFdmVudEZvbz4oKSkKICAgIHsKICAgIH0KfTsKCmNsYXNzIEV2ZW50QmFyIDogcHVibGljIEJhc2VFdmVudAp7CnB1YmxpYzo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