]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/protocol.cpp
Prefer range-based for loops where possible
[libs/net.git] / source / net / protocol.cpp
index 17e4310f5196c2f5c599cc103c8d8d5c6cf36430..9cba6382d307dcae861d3f4298c76ee4f86ac09b 100644 (file)
@@ -5,7 +5,6 @@
 #include <msp/strings/format.h>
 #include <msp/strings/lexicalcast.h>
 #include "protocol.h"
-#include "protocol_impl.h"
 
 using namespace std;
 
@@ -22,8 +21,14 @@ Protocol::Protocol(unsigned npi):
 
 Protocol::~Protocol()
 {
-       for(map<unsigned, PacketDefBase *>::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)
 { }