Advertisement
Guest User

yuriks

a guest
Dec 2nd, 2008
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. // PacketFactory.cpp
  2.  
  3. template<class T> Packet *makePacket()
  4. {
  5.     return static_cast<Packet *>(new T());
  6. }
  7.  
  8. PacketFactory::PacketFactory()
  9. {
  10.     // Register packet types here
  11.     idMap[PacketFactory::PACKET_ACKNOWLEDGE] = makePacket<PacketAcknowledge>;
  12. }
  13.  
  14. Packet *PacketFactory::createFromId(PacketIds id)
  15. {
  16.     IdMapType::const_iterator mapping = idMap.find(id);
  17.  
  18.     if (mapping == idMap.end())
  19.         throw UnknownPacketException();
  20.  
  21.     return mapping->second();
  22. }
  23.  
  24. PacketFactory globalPacketFactory;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement