Extend serialization to gmx_int64_t
authorMark Abraham <mark.j.abraham@gmail.com>
Sun, 1 Jan 2017 19:12:55 +0000 (19:12 +0000)
committerMark Abraham <mark.j.abraham@gmail.com>
Wed, 8 Feb 2017 22:24:36 +0000 (23:24 +0100)
Change-Id: Ib48b89d3f6e75e47ab6462c4505227e3f14913a5

src/gromacs/fileio/gmxfio-xdr.cpp
src/gromacs/fileio/gmxfio-xdr.h
src/gromacs/utility/inmemoryserializer.cpp
src/gromacs/utility/inmemoryserializer.h
src/gromacs/utility/iserializer.h
src/gromacs/utility/keyvaluetreeserializer.cpp
src/gromacs/utility/tests/keyvaluetreeserializer.cpp
src/testutils/refdata.cpp
src/testutils/refdata.h

index 16eb311b5806310fae96bfe466fa80b620c443fe..bdac061185a6d4fb5dc61cc05aba297fecc1e3f5 100644 (file)
@@ -691,6 +691,11 @@ void FileIOXdrSerializer::doInt(int *value)
     gmx_fio_do_int(fio_, *value);
 }
 
+void FileIOXdrSerializer::doInt64(gmx_int64_t *value)
+{
+    gmx_fio_do_int64(fio_, *value);
+}
+
 void FileIOXdrSerializer::doFloat(float *value)
 {
     gmx_fio_do_float(fio_, *value);
index 16169a8b71377a5809725c5ba7fc5cc164248f13..45118cb2afde236155ed9a59e44a066746a4ff83 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -147,6 +147,7 @@ class FileIOXdrSerializer : public ISerializer
 
         virtual void doUChar(unsigned char *value);
         virtual void doInt(int *value);
+        virtual void doInt64(gmx_int64_t *value);
         virtual void doFloat(float *value);
         virtual void doDouble(double *value);
         virtual void doString(std::string *value);
index fb7d4b71286283ebb5fdd3a3996dbd8d56c93c5c..a741b6760773068b43d2287ab939378e0c4043f8 100644 (file)
@@ -107,6 +107,11 @@ void InMemorySerializer::doInt(int *value)
     impl_->doValue(*value);
 }
 
+void InMemorySerializer::doInt64(gmx_int64_t *value)
+{
+    impl_->doValue(*value);
+}
+
 void InMemorySerializer::doFloat(float *value)
 {
     impl_->doValue(*value);
@@ -172,6 +177,11 @@ void InMemoryDeserializer::doInt(int *value)
     impl_->doValue(value);
 }
 
+void InMemoryDeserializer::doInt64(gmx_int64_t *value)
+{
+    impl_->doValue(value);
+}
+
 void InMemoryDeserializer::doFloat(float *value)
 {
     impl_->doValue(value);
index 55d315c6d3607939131be348dde99116fb2e3cf4..2466602399a8cb3ceaa3bcb464e35867e0b7aeff 100644 (file)
@@ -63,6 +63,7 @@ class InMemorySerializer : public ISerializer
         virtual bool reading() const { return false; }
         virtual void doUChar(unsigned char *value);
         virtual void doInt(int *value);
+        virtual void doInt64(gmx_int64_t *value);
         virtual void doFloat(float *value);
         virtual void doDouble(double *value);
         virtual void doString(std::string *value);
@@ -83,6 +84,7 @@ class InMemoryDeserializer : public ISerializer
         virtual bool reading() const { return true; }
         virtual void doUChar(unsigned char *value);
         virtual void doInt(int *value);
+        virtual void doInt64(gmx_int64_t *value);
         virtual void doFloat(float *value);
         virtual void doDouble(double *value);
         virtual void doString(std::string *value);
index 64fdf963845525aee0009b755b41ac44859d7c6f..aa52b85828409b88f0719a905c02da2cde97dd4d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -45,6 +45,8 @@
 
 #include <string>
 
+#include "gromacs/utility/basedefinitions.h"
+
 namespace gmx
 {
 
@@ -67,6 +69,7 @@ class ISerializer
         ///@{
         virtual void doUChar(unsigned char *value) = 0;
         virtual void doInt(int *value)             = 0;
+        virtual void doInt64(gmx_int64_t *value)   = 0;
         virtual void doFloat(float *value)         = 0;
         virtual void doDouble(double *value)       = 0;
         virtual void doString(std::string *value)  = 0;
index df8bda370dc00d372fac845bcb3bb99f92bf310d..99e40470676bc34c8327efc79ab699fd3c7e76fa 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -167,6 +167,21 @@ struct SerializationTraits<int>
     }
 };
 
+template <>
+struct SerializationTraits<gmx_int64_t>
+{
+    static void serialize(gmx_int64_t value, ISerializer *serializer)
+    {
+        serializer->doInt64(&value);
+    }
+    static void deserialize(KeyValueTreeValueBuilder *builder, ISerializer *serializer)
+    {
+        gmx_int64_t value;
+        serializer->doInt64(&value);
+        builder->setValue<gmx_int64_t>(value);
+    }
+};
+
 template <>
 struct SerializationTraits<float>
 {
@@ -222,6 +237,7 @@ void ValueSerializer::initSerializers()
         SERIALIZER('A', KeyValueTreeArray),
         SERIALIZER('s', std::string),
         SERIALIZER('i', int),
+        SERIALIZER('l', gmx_int64_t),
         SERIALIZER('f', float),
         SERIALIZER('d', double),
     };
index 00156143a9b29f0a11376d5304fb184c558b229b..f94866c8a6766a42086265227a2df0e284ac7c5b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -65,6 +65,10 @@ class RefDataWriteSerializer : public gmx::ISerializer
         {
             checker_.checkInteger(*value, nullptr);
         }
+        virtual void doInt64(gmx_int64_t *value)
+        {
+            checker_.checkInt64(*value, nullptr);
+        }
         virtual void doFloat(float *value)
         {
             checker_.checkFloat(*value, nullptr);
@@ -101,6 +105,10 @@ class RefDataReadSerializer : public gmx::ISerializer
         {
             *value = checker_.readInteger(nullptr);
         }
+        virtual void doInt64(gmx_int64_t *value)
+        {
+            *value = checker_.readInt64(nullptr);
+        }
         virtual void doFloat(float *value)
         {
             *value = checker_.readFloat(nullptr);
index d42f97f98dca796b589c7e9d492d0d03271feaef..474feff22fa371a26666ae47807bbfd9d7111bb8 100644 (file)
@@ -1065,6 +1065,19 @@ int TestReferenceChecker::readInteger(const char *id)
 }
 
 
+gmx_int64_t TestReferenceChecker::readInt64(const char *id)
+{
+    if (impl_->shouldIgnore())
+    {
+        GMX_THROW(TestException("Trying to read from non-existent reference data value"));
+    }
+    gmx_int64_t value = 0;
+    EXPECT_PLAIN(impl_->processItem(Impl::cInt64NodeName, id,
+                                    ValueExtractor<gmx_int64_t>(&value)));
+    return value;
+}
+
+
 float TestReferenceChecker::readFloat(const char *id)
 {
     if (impl_->shouldIgnore())
index e1cd287fe753dec81c9d6db29a5db4482c846f12..acf44b5ea5976a69676c437106ba8fd58ad5df2a 100644 (file)
@@ -394,6 +394,8 @@ class TestReferenceChecker
         unsigned char readUChar(const char *id);
         //! Reads an integer value.
         int readInteger(const char *id);
+        //! Reads a 64-bit integer value.
+        gmx_int64_t readInt64(const char *id);
         //! Reads a float value.
         float readFloat(const char *id);
         //! Reads a double value.