40 lines
1019 B
C++
40 lines
1019 B
C++
#pragma once
|
|
|
|
/**
|
|
* \file PacketVisitor.h
|
|
* \brief File containing the sp::protocol::PacketVisitor class
|
|
*/
|
|
|
|
#include <sp/protocol/packet/Packets.h>
|
|
|
|
namespace sp {
|
|
namespace protocol {
|
|
|
|
#define DeclarePacket(PacketName, ...) \
|
|
/** This function is called when the packet processed by PacketVisitor::Check is a PacketName */ \
|
|
virtual void Visit(const packets::PacketName&) {}
|
|
|
|
/**
|
|
* \class PacketVisitor
|
|
* \brief This class uses double-dispatch in order to find the real type of a packet
|
|
*/
|
|
class PacketVisitor : private NonCopyable {
|
|
protected:
|
|
PacketVisitor() {}
|
|
virtual ~PacketVisitor() {}
|
|
|
|
public:
|
|
/**
|
|
* \brief Calls the right PacketVisitor::Visit method corresponding to the real type of the packet
|
|
* \param packet the Packet to visit
|
|
*/
|
|
void Check(const Packet& packet);
|
|
|
|
DeclareAllPacket()
|
|
};
|
|
|
|
#undef DeclarePacket
|
|
|
|
} // namespace protocol
|
|
} // namespace sp
|