X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnet%2Fprotocol.h;h=cd68d5148735024eaa77f9ef1ebe06a16064de72;hb=ee01d294f9078fbf17dc6a0a645ad3a342c49b1a;hp=fa90e6d250d87531fdc01069a90fe0cab6a90352;hpb=b91b37fd6534a8e546fd6f5d6ddd91d66cd0519f;p=libs%2Fnet.git diff --git a/source/net/protocol.h b/source/net/protocol.h index fa90e6d..cd68d51 100644 --- a/source/net/protocol.h +++ b/source/net/protocol.h @@ -163,8 +163,6 @@ private: protected: unsigned id; - static unsigned next_class_id; - PacketDefBase(unsigned); public: virtual ~PacketDefBase() { } @@ -180,14 +178,11 @@ private: private: CompoundTypeDef

*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

(); } template void set_serializer(const S &); @@ -237,6 +232,11 @@ public: ~Protocol(); private: + static unsigned get_next_packet_class_id(); + + template + static unsigned get_packet_class_id(); + void add_packet(PacketDefBase *); protected: @@ -267,6 +267,13 @@ private: }; +template +unsigned Protocol::get_packet_class_id() +{ + static unsigned id = get_next_packet_class_id(); + return id; +} + template Protocol::PacketDefBuilder > Protocol::add(unsigned id) { @@ -284,7 +291,7 @@ Protocol::PacketDefBuilder > Protocol::add() template const Protocol::PacketTypeDef

&Protocol::get_packet_by_class() const { - const PacketDefBase &pdef = get_packet_by_class_id(PacketTypeDef

::get_static_class_id()); + const PacketDefBase &pdef = get_packet_by_class_id(get_packet_class_id

()); return static_cast &>(pdef); } @@ -460,10 +467,7 @@ template Protocol::PacketTypeDef

::PacketTypeDef(unsigned i): PacketDefBase(i), compound(new CompoundDef >(NullSerializer

())) -{ - if(!class_id) - class_id = next_class_id++; -} +{ } template Protocol::PacketTypeDef

::~PacketTypeDef()