ulib/3party/eventbus/include/enable_polymorphic_dispatch.h
tqcq 925efe8abe
All checks were successful
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m15s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 1m12s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m8s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m10s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m23s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 1m31s
linux-x64-gcc / linux-gcc (push) Successful in 1m57s
feat/add_eventbus (#9)
Co-authored-by: tqcq <99722391+tqcq@users.noreply.github.com>
Reviewed-on: #9
2024-01-19 04:51:24 +00:00

42 lines
1.0 KiB
C++

#pragma once
#include "detail/typelist.h"
namespace mpm {
namespace detail {
/// root class for polymorphic event hierarchies
class event {
protected:
//don't dispatch as this type - it's an internal
//implementation detail
using dispatch_as = null_t;
virtual ~event() {}
};
/// forward decl from eventbus.h
template<typename E>
struct dispatch_typelist;
}// namespace detail
//! Publicly inherit from this class to obtain polymorphic
//! event delivery.
template<typename T, typename Base = detail::event>
class enable_polymorphic_dispatch : public Base {
protected:
// \internal
// Couldn't use a typelist based on std::tuple here because
// std::tuple_cat won't work with an incomplete type, and the
// derived event types are incomplete when decltype(tuple_cat)
// would be used
#ifdef DOCS
using dispatch_as = implementation - defined;
#else
template<typename E>
friend class detail::dispatch_typelist;
using dispatch_as = detail::typelist<T, typename Base::dispatch_as>;
#endif
};
}// namespace mpm