X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fnet%2Fprotocol.cpp;h=9cba6382d307dcae861d3f4298c76ee4f86ac09b;hb=62ea6954a91568c900ad8155999bea264dfa72f3;hp=17e4310f5196c2f5c599cc103c8d8d5c6cf36430;hpb=2fbfce0c327c852d33c6713af646abf07b241108;p=libs%2Fnet.git diff --git a/source/net/protocol.cpp b/source/net/protocol.cpp index 17e4310..9cba638 100644 --- a/source/net/protocol.cpp +++ b/source/net/protocol.cpp @@ -5,7 +5,6 @@ #include #include #include "protocol.h" -#include "protocol_impl.h" using namespace std; @@ -22,8 +21,14 @@ Protocol::Protocol(unsigned npi): Protocol::~Protocol() { - for(map::iterator i=packet_class_defs.begin(); i!=packet_class_defs.end(); ++i) - delete i->second; + for(auto &kvp: packet_class_defs) + delete kvp.second; +} + +unsigned Protocol::get_next_packet_class_id() +{ + static unsigned next_id = 1; + return next_id++; } void Protocol::add_packet(PacketDefBase *pdef) @@ -72,8 +77,8 @@ size_t Protocol::get_packet_size(const char *buf, size_t size) const uint64_t Protocol::get_hash() const { string description; - for(PacketMap::const_iterator i=packet_id_defs.begin(); i!=packet_id_defs.end(); ++i) - description += format("%d:%s\n", i->first, i->second->describe()); + for(auto &kvp: packet_id_defs) + description += format("%d:%s\n", kvp.first, kvp.second->describe()); return hash<64>(description); } @@ -154,8 +159,6 @@ const char *Protocol::StringSerializer::deserialize(string &str, const char *buf } -unsigned Protocol::PacketDefBase::next_class_id = 1; - Protocol::PacketDefBase::PacketDefBase(unsigned i): id(i) { }