Want more features on Pastebin? Sign Up, it's FREE!
Guest

yuriks

By: a guest on Dec 2nd, 2008  |  syntax: C++  |  size: 0.70 KB  |  views: 351  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // PacketFactory.h
  2.  
  3. class PacketFactory
  4. {
  5. public:
  6.         // I guess this goes here, could go elsewhere though.
  7.         enum PacketIds
  8.         {
  9.                 PACKET_ACKNOWLEDGE = 0x00,
  10.  
  11.                 MAX_PACKET
  12.         };
  13. private:
  14.         // Ensures packet ids fit in one byte.
  15.         BOOST_STATIC_ASSERT(MAX_PACKET <= 0x100);
  16. public:
  17.         struct UnknownPacketException : std::runtime_error
  18.         {
  19.                 UnknownPacketException() : runtime_error("Unknown packet id.") {}
  20.         };
  21.  
  22.         PacketFactory();
  23.  
  24.         Packet *createFromId(PacketIds id);
  25. private:
  26.         PacketFactory(const PacketFactory&);
  27.         PacketFactory& operator=(const PacketFactory&);
  28.  
  29.         typedef std::map<PacketIds, boost::function<Packet*()> > IdMapType;
  30.         IdMapType idMap;
  31. };
  32.  
  33. extern PacketFactory globalPacketFactory;
clone this paste RAW Paste Data