Blob Blame History Raw
From f29938437db227528e28998d4154aa1f43ae7e26 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= <me@besser82.io>
Date: Tue, 18 Oct 2016 12:16:58 +0200
Subject: [PATCH] Fix build with JSONcpp >= 1.7.7, specialized template
 (#16938)

---
 ParaViewCore/ServerManager/Core/vtkSMSettings.cxx | 42 +++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/ParaViewCore/ServerManager/Core/vtkSMSettings.cxx b/ParaViewCore/ServerManager/Core/vtkSMSettings.cxx
index 49a0b22..aa17fa6 100644
--- a/ParaViewCore/ServerManager/Core/vtkSMSettings.cxx
+++ b/ParaViewCore/ServerManager/Core/vtkSMSettings.cxx
@@ -1465,6 +1465,48 @@ Json::Value vtkConvertXMLElementToJSON(
   ;
 }
 
+// We need a specialized template for `vtkIdType`, if compiling
+// with `VTK_USE_64BIT_IDS=ON`, because JSONcpp >= 1.7.7 switched
+// from at-least width (long long int) to fixed width (int64_t)
+// integers.  If compiling with `VTK_USE_64BIT_IDS=OFF` this is
+// not needed, because vtkIdType represents a plain integer in
+// this case.
+//
+// See: https://gitlab.kitware.com/paraview/paraview/issues/16938
+#ifdef VTK_USE_64BIT_IDS
+template <>
+Json::Value vtkConvertXMLElementToJSON <vtkIdType>(
+  vtkSMVectorProperty* vp,
+  const std::vector<vtkSmartPointer<vtkPVXMLElement> >& elements)
+{
+  // Since we need to handle enumeration domain :/.
+  vtkSMEnumerationDomain* enumDomain = vtkSMEnumerationDomain::SafeDownCast(
+    vp->FindDomain("vtkSMEnumerationDomain"));
+  Json::Value value(Json::arrayValue);
+  for (size_t cc=0; cc < elements.size(); ++cc)
+    {
+    vtkIdType xmlValue;
+    elements[cc]->GetScalarAttribute("value", &xmlValue);
+    const char* txt = enumDomain? enumDomain->GetEntryTextForValue(xmlValue) : NULL;
+    if (txt)
+      {
+      value[static_cast<unsigned int>(cc)] = Json::Value(txt);
+      }
+    else
+      {
+      // We need to cast from `vtkIdType` to `int64_t` explicitly.
+      value[static_cast<unsigned int>(cc)] = Json::Value(static_cast<int64_t>(xmlValue));
+      }
+    }
+  if (vp->GetNumberOfElements()==1 && vp->GetRepeatCommand()==0 && value.size()==1)
+    {
+    return value[0];
+    }
+  return value
+  ;
+}
+#endif // VTK_USE_64BIT_IDS
+
 template <>
 Json::Value vtkConvertXMLElementToJSON<vtkStdString>(
   vtkSMVectorProperty* vp,
-- 
2.7.4