open-dis-cpp
PacketFactory.h
1 #ifndef _dcl_dis_packet_factory_h_
5 #define _dcl_dis_packet_factory_h_
6 
7 #include <map> // for member
8 #include <dis6/opendis6_export.h> // for library symbols
9 
10 namespace DIS
11 {
12  class Pdu;
13 
15  template<class BaseT, class DerivedT>
17  {
18  return new DerivedT();
19  }
20 
22  class OPENDIS6_EXPORT PacketFactory
23  {
24  public:
25 
29  Pdu* CreatePacket(unsigned char id);
30 
33  void DestroyPacket(Pdu* pdu);
34 
38  template<class T>
39  bool RegisterPacket(unsigned char id)
40  {
41  FunctionMap::value_type candidate(id,&CreateImplementation<Pdu,T>);
42  std::pair<FunctionMap::iterator,bool> result = _fMap.insert( candidate );
43  return result.second;
44  }
45 
49  bool UnRegisterPacket(char id)
50  {
51  return( _fMap.erase( id )>0 );
52  }
53 
57  bool IsRegistered(unsigned char id) const;
58 
59  private:
61  typedef Pdu* (*CREATE_FUNC)();
62 
64  typedef std::map<unsigned char,CREATE_FUNC> FunctionMap;
65 
67  FunctionMap _fMap;
68  };
69 }
70 
71 #endif // _dcl_dis_packet_factory_h_
Symbolic names as defined in 5.1.4.
Definition: AcknowledgePdu.h:8
responsible for mapping an ID value to a Pdu type.
Definition: PacketFactory.h:22
Definition: Pdu.h:15
bool UnRegisterPacket(char id)
Remove support for creating the Pdu.
Definition: PacketFactory.h:49
bool RegisterPacket(unsigned char id)
Add support for creating the Pdu.
Definition: PacketFactory.h:39
BaseT * CreateImplementation()
a utility to make functions
Definition: PacketFactory.h:16