From 36a98ac91becbf17e0f7730615e54232fd45de04 Mon Sep 17 00:00:00 2001
From: crule <crule@aegistg.com>
Date: Fri, 26 Oct 2018 11:55:53 -0500
Subject: [PATCH] Corrections to CERTI to allow it to compile on windows Visual
 studio 2017. * mom.cc: replaced "or" with || * mom_ineractions.cc: replaced
 "not" with ! * make_unique.hh: make_unique is now in std for VS2017. As far
 as I can tell it's also there for vs2013 and above. * StringType.hh: Removed
 unused NamedTypeImpl constructor since it won't compile on VS2017. *
 socketpair_win32.c: Added defining _WINSOCKAPI_ to prevent windows from
 including winsock.h * SystemSpecificInformations.cmake: Added definitions for
 windows 10 and VS2015 and VS2017.

---
 RTIG/Mom.cc                              |  2 +-
 RTIG/Mom_interactions.cc                 |  4 ++--
 include/make_unique.hh                   |  4 ++++
 libCERTI/StrongType.hh                   | 11 ++++++-----
 libCERTI/socketpair_win32.c              |  3 +++
 scripts/SystemSpecificInformations.cmake | 22 +++++++++++++++++++++-
 6 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/RTIG/Mom.cc b/RTIG/Mom.cc
index 065e1d00..056059f8 100644
--- a/RTIG/Mom.cc
+++ b/RTIG/Mom.cc
@@ -232,7 +232,7 @@ bool Mom::isAvailableInRootObjectAndCompliant(const RootObject& root)
 {
     // Pre check with sizes
     if (root.ObjectClasses->size() < the_required_object_classes.size()
-        or root.Interactions->size() < the_required_interactions.size()) {
+        || root.Interactions->size() < the_required_interactions.size()) {
         Debug(D, pdDebug)
             << "the root object does not contain enough object classes or interactions to have a mom definition."
             << endl;
diff --git a/RTIG/Mom_interactions.cc b/RTIG/Mom_interactions.cc
index e8191676..6383e585 100644
--- a/RTIG/Mom_interactions.cc
+++ b/RTIG/Mom_interactions.cc
@@ -790,7 +790,7 @@ Responses Mom::processFederateRequestObjectInstancesUpdated(const FederateHandle
     std::map<ObjectClassHandle, int> objectInstancesCounts;
 
     for (const auto& pair : my_object_instances_updated[federate_handle]) {
-        if (not pair.second.empty()) {
+        if (! pair.second.empty()) {
             objectInstancesCounts[pair.first] = pair.second.size();
         }
     }
@@ -826,7 +826,7 @@ Responses Mom::processFederateRequestObjectInstancesReflected(const FederateHand
     std::map<ObjectClassHandle, int> objectInstancesCounts;
 
     for (const auto& pair : my_object_instances_reflected[federate_handle]) {
-        if (not pair.second.empty()) {
+        if (! pair.second.empty()) {
             objectInstancesCounts[pair.first] = pair.second.size();
         }
     }
diff --git a/include/make_unique.hh b/include/make_unique.hh
index abb7c4ef..9b8d70ca 100644
--- a/include/make_unique.hh
+++ b/include/make_unique.hh
@@ -5,6 +5,10 @@
 
 using std::make_unique;
 
+#elif _WIN32 && (_MSC_VER >= 1800)
+// Visual Studio since VS2013 defines make_unique in <memory>.
+using std::make_unique;
+
 #elif __GNUC__ < 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ < 9))
 
 #include <memory>
diff --git a/libCERTI/StrongType.hh b/libCERTI/StrongType.hh
index e3be4396..98baf8e4 100644
--- a/libCERTI/StrongType.hh
+++ b/libCERTI/StrongType.hh
@@ -187,11 +187,12 @@ public:
     explicit NamedTypeImpl(T const& value) : value_(value)
     {
     }
-    template <typename T_ = T>
-    explicit NamedTypeImpl(T&& value, typename std::enable_if<!std::is_reference<T_>{}, std::nullptr_t>::type = nullptr)
-        : value_(std::move(value))
-    {
-    }
+//    template <typename T_ = T>
+//    explicit NamedTypeImpl(T&& value,
+//                                typename std::enable_if<!std::is_reference<T_>{}, std::nullptr_t>::type = nullptr)
+//        : value_(std::move(value))
+//    {
+//    }
 
     // get
     T& get()
diff --git a/libCERTI/socketpair_win32.c b/libCERTI/socketpair_win32.c
index 94bbb190..8a68abf2 100644
--- a/libCERTI/socketpair_win32.c
+++ b/libCERTI/socketpair_win32.c
@@ -21,6 +21,9 @@
 #include <string.h>
 
 #include <io.h>
+#ifdef _WIN32
+#define _WINSOCKAPI_ // stops windows.h including winsock.h
+#endif
 #include <windows.h>
 #include <winsock2.h>
 
diff --git a/scripts/SystemSpecificInformations.cmake b/scripts/SystemSpecificInformations.cmake
index e89d961c..44817751 100644
--- a/scripts/SystemSpecificInformations.cmake
+++ b/scripts/SystemSpecificInformations.cmake
@@ -51,6 +51,13 @@ if(WIN32)
   if(CMAKE_SYSTEM_VERSION MATCHES "6.2")
     set(SPECIFIC_SYSTEM_VERSION_NAME "Win8")
   endif(CMAKE_SYSTEM_VERSION MATCHES "6.2")
+
+  # Win 10 series
+  string(FIND ${CMAKE_SYSTEM_VERSION} "." DOT_LOCATION)
+  string(SUBSTRING ${CMAKE_SYSTEM_VERSION} 0 ${DOT_LOCATION} WINDOWS_MAJOR_VERSION)
+  if(WINDOWS_MAJOR_VERSION MATCHES "10")
+    set(SPECIFIC_SYSTEM_VERSION_NAME "Win10")
+  endif(WINDOWS_MAJOR_VERSION MATCHES "10")
   
   # Cross-compiling
   if (CMAKE_CROSSCOMPILING)
@@ -85,6 +92,19 @@ if(WIN32)
     if(MSVC_VERSION EQUAL 1800)
       set(SPECIFIC_COMPILER_NAME "MSVC-12.0-2013") #Visual Studio 2013
     endif(MSVC_VERSION EQUAL 1800)
+
+    # Info from: https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B
+    math(EXPR MSVC_PRINT_VER "${MSVC_VERSION} - 500") # Apparently this is historical based.
+    string(SUBSTRING ${MSVC_PRINT_VER} 0 2 MSVC_MAJOR_VER)
+    string(SUBSTRING ${MSVC_PRINT_VER} 2 2 MSVC_MINOR_VER)
+    set(MSVC_PRINT_VER "${MSVC_MAJOR_VER}.${MSVC_MINOR_VER}")
+
+    if(MSVC_VERSION EQUAL 1900)
+      set(SPECIFIC_COMPILER_NAME "MSVC-${MSVC_PRINT_VER}-2015") #Visual Studio 2015
+    elseif(MSVC_VERSION GREATER 1900 AND MSVC_VERSION LESS 2000)
+      set(SPECIFIC_COMPILER_NAME "MSVC-${MSVC_PRINT_VER}-2017") #Visual Studio 2017
+    endif(MSVC_VERSION EQUAL 1900)
+    
   endif(MSVC)
   if(MINGW)
     set(SPECIFIC_COMPILER_NAME "MinGW")
@@ -175,4 +195,4 @@ if(UNIX)
   set(SPECIFIC_SYSTEM_VERSION_NAME
      "${SPECIFIC_SYSTEM_VERSION_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
   set(SPECIFIC_COMPILER_NAME "")
-endif(UNIX)
\ No newline at end of file
+endif(UNIX)
-- 
2.19.1.windows.1

