]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/protocol.cpp
Use default member initializers where possible
[libs/net.git] / source / net / protocol.cpp
index db663821c370cef914676eb1da698cdb473f5c50..bcad032b4cb4fcc86a9de9702312806bf640b3b3 100644 (file)
@@ -1,6 +1,5 @@
 #include <cstring>
 #include <string>
-#include <msp/core/hash.h>
 #include <msp/core/maputils.h>
 #include <msp/strings/format.h>
 #include <msp/strings/lexicalcast.h>
@@ -21,8 +20,8 @@ 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()
@@ -76,10 +75,13 @@ 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());
-       return hash<64>(description);
+       uint64_t result = hash<64>(packet_id_defs.size());
+       for(auto &kvp: packet_id_defs)
+       {
+               hash_update<64>(result, kvp.first);
+               hash_update<64>(result, kvp.second->get_hash());
+       }
+       return result;
 }
 
 
@@ -164,11 +166,6 @@ Protocol::PacketDefBase::PacketDefBase(unsigned i):
 { }
 
 
-Protocol::PacketHeader::PacketHeader():
-       type(0),
-       length(0)
-{ }
-
 Protocol::PacketHeader::PacketHeader(uint16_t t, uint16_t l):
        type(t),
        length(l)