X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnet%2Fprotocol.h;h=cd68d5148735024eaa77f9ef1ebe06a16064de72;hb=ee01d294f9078fbf17dc6a0a645ad3a342c49b1a;hp=3457a9d7288cf47b915d1e4249cecbc6db3f9c55;hpb=2fbfce0c327c852d33c6713af646abf07b241108;p=libs%2Fnet.git diff --git a/source/net/protocol.h b/source/net/protocol.h index 3457a9d..cd68d51 100644 --- a/source/net/protocol.h +++ b/source/net/protocol.h @@ -14,7 +14,6 @@ class bad_packet: public std::runtime_error { public: bad_packet(const std::string &w): std::runtime_error(w) { } - virtual ~bad_packet() throw() { } }; @@ -22,7 +21,6 @@ class buffer_error: public std::runtime_error { public: buffer_error(const std::string &w): std::runtime_error(w) { } - virtual ~buffer_error() throw() { } }; @@ -165,8 +163,6 @@ private: protected: unsigned id; - static unsigned next_class_id; - PacketDefBase(unsigned); public: virtual ~PacketDefBase() { } @@ -182,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 &); @@ -239,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: @@ -269,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) { @@ -286,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); } @@ -462,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()