From f8db2b1736da53c2b3dca7d887b86ab72e43d149 Mon Sep 17 00:00:00 2001
From: Johannes Wienke <jwienke@techfak.uni-bielefeld.de>
Date: Tue, 18 Dec 2012 14:43:26 +0100
Subject: [PATCH] Fix compilation on windows, again.

* New export logic for Converter<string>.
* Add a test case to compile a new converter inside the unit tests to emulate compiling a converter in an arbitrary client program.
  This should find out another possible compilation problem induced through the converter template class, which needs to be exported on windows.
---
 src/rsb/converter/Converter.h               |  2 ++
 src/rsb/converter/ProtocolBufferConverter.h |  4 ---
 src/rsb/rsbexports.h.in                     |  2 +-
 test/CMakeLists.txt                         |  3 ++
 test/rsb/converter/TestConverter.cpp        | 44 +++++++++++++++++++++++++
 test/rsb/converter/TestConverter.h          | 50 +++++++++++++++++++++++++++++
 test/rsb/converter/TestConverterTest.cpp    | 40 +++++++++++++++++++++++
 7 files changed, 140 insertions(+), 5 deletions(-)
 create mode 100644 test/rsb/converter/TestConverter.cpp
 create mode 100644 test/rsb/converter/TestConverter.h
 create mode 100644 test/rsb/converter/TestConverterTest.cpp

diff --git a/src/rsb/converter/Converter.h b/src/rsb/converter/Converter.h
index 5362555..fffb22c 100644
--- a/src/rsb/converter/Converter.h
+++ b/src/rsb/converter/Converter.h
@@ -146,5 +146,7 @@ private:
     }
 };
 
+RSB_EXPIMP template class RSB_EXPORT Converter<std::string>;
+
 }
 }
diff --git a/src/rsb/converter/ProtocolBufferConverter.h b/src/rsb/converter/ProtocolBufferConverter.h
index 0404cf1..ce14e87 100644
--- a/src/rsb/converter/ProtocolBufferConverter.h
+++ b/src/rsb/converter/ProtocolBufferConverter.h
@@ -35,10 +35,6 @@
 #include "Converter.h"
 #include "rsb/rsbexports.h"
 
-#if defined(RSB_IMPORT_TEMPLATES)
-template class __declspec(dllimport) rsb::converter::Converter<std::string>;
-#endif
-
 namespace rsb {
 namespace converter {
 
diff --git a/src/rsb/rsbexports.h.in b/src/rsb/rsbexports.h.in
index e69e69f..f46cc92 100644
--- a/src/rsb/rsbexports.h.in
+++ b/src/rsb/rsbexports.h.in
@@ -37,10 +37,10 @@
     #else
         #define RSB_EXPORT __declspec(dllimport)
         #define RSB_EXPIMP extern
-        #define RSB_IMPORT_TEMPLATES
     #endif
 #else
     #define RSB_EXPORT
+    #define RSB_EXPIMP
 #endif
 
 #endif /* RSBEXPORTS_H_ */
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index c6d8599..11dec75 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -65,6 +65,9 @@ SET(CORE_TEST_SOURCES rsbtest_core.cpp
                       rsb/converter/PredicateConverterListTest.cpp
                       rsb/converter/ProtocolBufferConverterLinkingTest.cpp
                       rsb/converter/ProtocolBufferConverterTest.cpp
+                      rsb/converter/TestConverter.cpp
+                      rsb/converter/TestConverter.h
+                      rsb/converter/TestConverterTest.cpp
                       rsb/eventprocessing/ParallelEventReceivingStrategyTest.cpp
                       rsb/util/MD5Test.cpp
                       rsb/transport/FactoryTest.cpp)
diff --git a/test/rsb/converter/TestConverter.cpp b/test/rsb/converter/TestConverter.cpp
new file mode 100644
index 0000000..aa89fca
--- /dev/null
+++ b/test/rsb/converter/TestConverter.cpp
@@ -0,0 +1,44 @@
+/* ============================================================
+ *
+ * This file is a part of the rsb-cpp project.
+ *
+ * Copyright (C) 2012 by Johannes Wienke <jwienke at techfak dot uni-bielefeld dot de>
+ *
+ * This file may be licensed under the terms of the
+ * GNU Lesser General Public License Version 3 (the ``LGPL''),
+ * or (at your option) any later version.
+ *
+ * Software distributed under the License is distributed
+ * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+ * express or implied. See the LGPL for the specific language
+ * governing rights and limitations.
+ *
+ * You should have received a copy of the LGPL along with this
+ * program. If not, go to http://www.gnu.org/licenses/lgpl.html
+ * or write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The development of this software was supported by:
+ *   CoR-Lab, Research Institute for Cognition and Robotics
+ *     Bielefeld University
+ *
+ * ============================================================ */
+
+#include "TestConverter.h"
+
+TestConverter::TestConverter() :
+        rsb::converter::Converter<std::string>("foo", "bar", true) {
+}
+
+TestConverter::~TestConverter() {
+}
+
+std::string TestConverter::serialize(const rsb::AnnotatedData& /*data*/,
+        std::string& /*wire*/) {
+    return "";
+}
+
+rsb::AnnotatedData TestConverter::deserialize(const std::string& /*wireSchema*/,
+        const std::string& /*wire*/) {
+    return std::make_pair("", boost::shared_ptr<void>());
+}
diff --git a/test/rsb/converter/TestConverter.h b/test/rsb/converter/TestConverter.h
new file mode 100644
index 0000000..bb913d8
--- /dev/null
+++ b/test/rsb/converter/TestConverter.h
@@ -0,0 +1,50 @@
+/* ============================================================
+ *
+ * This file is a part of the rsb-cpp project.
+ *
+ * Copyright (C) 2012 by Johannes Wienke <jwienke at techfak dot uni-bielefeld dot de>
+ *
+ * This file may be licensed under the terms of the
+ * GNU Lesser General Public License Version 3 (the ``LGPL''),
+ * or (at your option) any later version.
+ *
+ * Software distributed under the License is distributed
+ * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+ * express or implied. See the LGPL for the specific language
+ * governing rights and limitations.
+ *
+ * You should have received a copy of the LGPL along with this
+ * program. If not, go to http://www.gnu.org/licenses/lgpl.html
+ * or write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The development of this software was supported by:
+ *   CoR-Lab, Research Institute for Cognition and Robotics
+ *     Bielefeld University
+ *
+ * ============================================================ */
+
+#pragma once
+
+#include "rsb/converter/Converter.h"
+
+/**
+ * This converter is compiled into the unit tests to test windows compilation
+ * issues with the templatized Converter base class.
+ *
+ * @ref https://code.cor-lab.org/issues/1285
+ * @author jwienke
+ */
+class TestConverter: public rsb::converter::Converter<std::string> {
+public:
+    TestConverter();
+    virtual ~TestConverter();
+
+    virtual std::string serialize(const rsb::AnnotatedData& data,
+            std::string& wire);
+
+    virtual rsb::AnnotatedData deserialize(const std::string& wireSchema,
+            const std::string& wire);
+
+};
+
diff --git a/test/rsb/converter/TestConverterTest.cpp b/test/rsb/converter/TestConverterTest.cpp
new file mode 100644
index 0000000..b5d2ce9
--- /dev/null
+++ b/test/rsb/converter/TestConverterTest.cpp
@@ -0,0 +1,40 @@
+/* ============================================================
+ *
+ * This file is part of the RSB project
+ *
+ * Copyright (C) 2012 Johannes Wienke <jwienke@techfak.uni-bielefeld.de>
+ *
+ * This file may be licensed under the terms of the
+ * GNU Lesser General Public License Version 3 (the ``LGPL''),
+ * or (at your option) any later version.
+ *
+ * Software distributed under the License is distributed
+ * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+ * express or implied. See the LGPL for the specific language
+ * governing rights and limitations.
+ *
+ * You should have received a copy of the LGPL along with this
+ * program. If not, go to http://www.gnu.org/licenses/lgpl.html
+ * or write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The development of this software was supported by:
+ *   CoR-Lab, Research Institute for Cognition and Robotics
+ *     Bielefeld University
+ *
+ * ============================================================ */
+
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include "TestConverter.h"
+
+using namespace std;
+using namespace rsb;
+using namespace rsb::converter;
+using namespace testing;
+
+TEST(TestConverterTest, testCompilation)
+{
+    TestConverter();
+}
-- 
1.8.0.2

