#include <msp/strings/format.h>
#include <msp/strings/lexicalcast.h>
#include "protocol.h"
-#include "protocol_impl.h"
using namespace std;
delete i->second;
}
+unsigned Protocol::get_next_packet_class_id()
+{
+ static unsigned next_id = 1;
+ return next_id++;
+}
+
void Protocol::add_packet(PacketDefBase *pdef)
{
PacketDefBase *&ptr = packet_class_defs[pdef->get_class_id()];
}
-unsigned Protocol::PacketDefBase::next_class_id = 1;
-
Protocol::PacketDefBase::PacketDefBase(unsigned i):
id(i)
{ }
protected:
unsigned id;
- static unsigned next_class_id;
-
PacketDefBase(unsigned);
public:
virtual ~PacketDefBase() { }
private:
CompoundTypeDef<P> *compound;
- static unsigned class_id;
-
public:
PacketTypeDef(unsigned);
~PacketTypeDef();
- static unsigned get_static_class_id() { return class_id; }
- virtual unsigned get_class_id() const { return class_id; }
+ virtual unsigned get_class_id() const { return get_packet_class_id<P>(); }
template<typename S>
void set_serializer(const S &);
~Protocol();
private:
+ static unsigned get_next_packet_class_id();
+
+ template<typename P>
+ static unsigned get_packet_class_id();
+
void add_packet(PacketDefBase *);
protected:
};
+template<typename P>
+unsigned Protocol::get_packet_class_id()
+{
+ static unsigned id = get_next_packet_class_id();
+ return id;
+}
+
template<typename P>
Protocol::PacketDefBuilder<P, Protocol::NullSerializer<P> > Protocol::add(unsigned id)
{
template<typename P>
const Protocol::PacketTypeDef<P> &Protocol::get_packet_by_class() const
{
- const PacketDefBase &pdef = get_packet_by_class_id(PacketTypeDef<P>::get_static_class_id());
+ const PacketDefBase &pdef = get_packet_by_class_id(get_packet_class_id<P>());
return static_cast<const PacketTypeDef<P> &>(pdef);
}
Protocol::PacketTypeDef<P>::PacketTypeDef(unsigned i):
PacketDefBase(i),
compound(new CompoundDef<P, NullSerializer<P> >(NullSerializer<P>()))
-{
- if(!class_id)
- class_id = next_class_id++;
-}
+{ }
template<typename P>
Protocol::PacketTypeDef<P>::~PacketTypeDef()
#ifndef MSP_NET_PROTOCOL_IMPL_H_
#define MSP_NET_PROTOCOL_IMPL_H_
-#include "protocol.h"
-
-namespace Msp {
-namespace Net {
-
-template<typename P>
-unsigned Protocol::PacketTypeDef<P>::class_id = 0;
-
-} // namespace Net
-} // namespace Msp
+#warning "This header is deprected and should not be used"
#endif