]> git.tdb.fi Git - libs/net.git/commitdiff
Use maputils
authorMikko Rasa <tdb@tdb.fi>
Thu, 4 Aug 2011 22:44:12 +0000 (01:44 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 4 Aug 2011 22:44:12 +0000 (01:44 +0300)
source/protocol.cpp

index 147077cc1253c3c60e7c9ab049951b0e3223445b..3e7d479b52407f4bca47f3057fdeef7ed507fd96 100644 (file)
@@ -1,5 +1,6 @@
 #include <cstring>
 #include <string>
+#include <msp/core/maputils.h>
 #include <msp/strings/lexicalcast.h>
 #include "protocol.h"
 
@@ -123,18 +124,12 @@ void Protocol::add_packet(PacketDefBase &pdef)
 
 const Protocol::PacketDefBase &Protocol::get_packet_by_class(unsigned id) const
 {
-       PacketMap::const_iterator i = packet_class_defs.find(id);
-       if(i==packet_class_defs.end())
-               throw KeyError("Unknown packet class", lexical_cast(id));
-       return *i->second;
+       return *get_item(packet_class_defs, id);
 }
 
 const Protocol::PacketDefBase &Protocol::get_packet_by_id(unsigned id) const
 {
-       PacketMap::const_iterator i = packet_id_defs.find(id);
-       if(i==packet_id_defs.end())
-               throw KeyError("Unknown packet ID", lexical_cast(id));
-       return *i->second;
+       return *get_item(packet_id_defs, id);
 }
 
 unsigned Protocol::disassemble(ReceiverBase &rcv, const char *data, unsigned size) const