Files
Simple-Protocol-Lib/include/sp/protocol/command/CommandVisitor.h
2025-02-04 19:11:03 +01:00

40 lines
1.0 KiB
C++

#pragma once
/**
* \file CommandVisitor.h
* \brief File containing the sp::protocol::CommandVisitor class
*/
#include <sp/protocol/command/Commands.h>
namespace sp {
namespace protocol {
#define DeclareCommand(CommandName, ...) \
/** This function is called when the packet processed by CommandVisitor::Check is a CommandName */ \
virtual void Visit(const commands::CommandName&) {}
/**
* \class CommandVisitor
* \brief This class uses double-dispatch in order to find the real type of a packet
*/
class CommandVisitor : private NonCopyable {
protected:
CommandVisitor() {}
virtual ~CommandVisitor() {}
public:
/**
* \brief Calls the right CommandVisitor::Visit method corresponding to the real type of the packet
* \param packet the Command to visit
*/
void Check(const Command& packet);
DeclareAllCommand()
};
#undef DeclareCommand
} // namespace protocol
} // namespace sp