I have written a messaging system which relies a lot on compile-time mechanics. To receive messages, you inherit from a class template like so:
class WorldRenderer : public fea::MessageReceiver<SpriteCreateMessage>,
public fea::MessageReceiver<SpritePositionMessage>,
public fea::MessageReceiver<SpriteMoveMessage>
{
public:
void handleMessage(const SpriteCreateMessage& mess) override;
void handleMessage(const SpritePositionMessage& mess) override;
void handleMessage(const SpriteMoveMessage& mess) override;
};
I was thinking it there was a way to shorthand this notation in a neat way using macros. How I imagine said macro to be used:
class WorldRenderer
FEA_IS_RECEIVER(SpriteCreateMessage, SpritePositionMessage, SpriteMoveMessage)
{
public:
void handleMessage(const SpriteCreateMessage& mess) override;
void handleMessage(const SpritePositionMessage& mess) override;
void handleMessage(const SpriteMoveMessage& mess) override;
};
Is there a way to create such a FEA_IS_RECEIVER macro?
I have looked into variadic macros but it doesn't seem possible to evaluate them unless you write specific macro overloads for every specific amount of parameters. This approach would work but would limit the amount of messages you can subscribe to.
Is there at all a neat way to achieve what I am trying to do?