Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PacketFactory.cpp
- template<class T> Packet *makePacket()
- {
- return static_cast<Packet *>(new T());
- }
- PacketFactory::PacketFactory()
- {
- // Register packet types here
- idMap[PacketFactory::PACKET_ACKNOWLEDGE] = makePacket<PacketAcknowledge>;
- }
- Packet *PacketFactory::createFromId(PacketIds id)
- {
- IdMapType::const_iterator mapping = idMap.find(id);
- if (mapping == idMap.end())
- throw UnknownPacketException();
- return mapping->second();
- }
- PacketFactory globalPacketFactory;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement