Move the definition of PacketTypeDef<T>::class_id to a separate header master
authorMikko Rasa <tdb@tdb.fi>
Tue, 1 Nov 2016 22:00:55 +0000 (00:00 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 1 Nov 2016 22:00:55 +0000 (00:00 +0200)
Defining it in protocol.h may cause multiple definitions to appear across
the program and there are cases where they don't get collapsed to one.
DLLs on Windows are one such case.  The _impl header is to be included in
files that add packet definitions to a protocol and nowhere else.

source/net/communicator.cpp
source/net/protocol.cpp
source/net/protocol.h
source/net/protocol_impl.h [new file with mode: 0644]

index 3d6353a2158fb2d62fbe6df164085a1b2ea7a417..22a79631d9a214741fdbf71721d8e6322986ea4e 100644 (file)
@@ -1,5 +1,6 @@
 #include <cstring>
 #include "communicator.h"
+#include "protocol_impl.h"
 #include "streamsocket.h"
 
 using namespace std;
index b24cef1f5e3f03ef067711271480c2eb1ab378cb..52678af2d9009cf9279d88ce3e1856d0fee1be9b 100644 (file)
@@ -5,6 +5,7 @@
 #include <msp/strings/format.h>
 #include <msp/strings/lexicalcast.h>
 #include "protocol.h"
+#include "protocol_impl.h"
 
 using namespace std;
 
index 7ff63cb1e7dd12cc2a8fb3e9ba1e092062bcc754..05ea60e2f13232305a0ca18c9b50850db25e013c 100644 (file)
@@ -455,9 +455,6 @@ const char *Protocol::Serializer<P, Head, S>::deserialize(P &pkt, const char *bu
 }
 
 
-template<typename P>
-unsigned Protocol::PacketTypeDef<P>::class_id = 0;
-
 template<typename P>
 Protocol::PacketTypeDef<P>::PacketTypeDef(unsigned i):
        PacketDefBase(i),
diff --git a/source/net/protocol_impl.h b/source/net/protocol_impl.h
new file mode 100644 (file)
index 0000000..9ddf818
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef MSP_NET_PROTOCOL_IMPL_H_
+#define MSP_NET_PROTOCOL_IMPL_H_
+
+#include "protocol.h"
+
+namespace Msp {
+namespace Net {
+
+template<typename P>
+unsigned Protocol::PacketTypeDef<P>::class_id = 0;
+
+} // namespace Net
+} // namespace Msp
+
+#endif