/* Enumerated for data types in files */
enum {
- eioREAL, eioFLOAT, eioDOUBLE, eioINT, eioINT64,
+ eioREAL, eioFLOAT, eioDOUBLE, eioINT, eioINT32, eioINT64,
eioUCHAR, eioNUCHAR, eioUSHORT,
eioRVEC, eioNRVEC, eioIVEC, eioSTRING, eioNR
};
static const char *eioNames[eioNR] =
{
- "REAL", "FLOAT", "DOUBLE", "INT", "INT64",
+ "REAL", "FLOAT", "DOUBLE", "INT", "INT32", "INT64",
"UCHAR", "NUCHAR", "USHORT",
"RVEC", "NRVEC", "IVEC", "STRING"
};
float fvec[DIM];
double dvec[DIM];
int j, m, *iptr, idum;
- int64_t sdum;
+ int32_t s32dum;
+ int64_t s64dum;
real *ptr;
unsigned short us;
double d = 0;
*static_cast<int *>(item) = idum;
}
break;
+ case eioINT32:
+ if (item && !fio->bRead)
+ {
+ s32dum = *static_cast<int32_t *>(item);
+ }
+ res = xdr_int32(fio->xdr, &s32dum);
+ if (item)
+ {
+ *static_cast<int32_t *>(item) = s32dum;
+ }
+ break;
case eioINT64:
if (item && !fio->bRead)
{
- sdum = *static_cast<int64_t *>(item);
+ s64dum = *static_cast<int64_t *>(item);
}
- res = xdr_int64(fio->xdr, &sdum);
+ res = xdr_int64(fio->xdr, &s64dum);
if (item)
{
- *static_cast<int64_t *>(item) = sdum;
+ *static_cast<int64_t *>(item) = s64dum;
}
break;
case eioUCHAR:
return ret;
}
+gmx_bool gmx_fio_doe_int32(t_fileio *fio, int32_t *item,
+ const char *desc, const char *srcfile, int line)
+{
+ gmx_bool ret;
+ gmx_fio_lock(fio);
+ ret = do_xdr(fio, item, 1, eioINT32, desc, srcfile, line);
+ gmx_fio_unlock(fio);
+ return ret;
+}
+
gmx_bool gmx_fio_doe_int64(t_fileio *fio, int64_t *item,
const char *desc, const char *srcfile, int line)
{
gmx_fio_do_int(fio_, *value);
}
+void FileIOXdrSerializer::doInt32(int32_t *value)
+{
+ gmx_fio_do_int32(fio_, *value);
+}
+
void FileIOXdrSerializer::doInt64(int64_t *value)
{
gmx_fio_do_int64(fio_, *value);
const char *desc, const char *srcfile, int line);
gmx_bool gmx_fio_doe_int(struct t_fileio *fio, int *item,
const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_doe_int32(struct t_fileio *fio, int32_t *item,
+ const char *desc, const char *srcfile, int line);
gmx_bool gmx_fio_doe_int64(struct t_fileio *fio, int64_t *item,
const char *desc, const char *srcfile, int line);
gmx_bool gmx_fio_doe_uchar(struct t_fileio *fio, unsigned char *item,
const char *desc, const char *srcfile, int line);
gmx_bool gmx_fio_ndoe_int(struct t_fileio *fio, int *item, int n,
const char *desc, const char *srcfile, int line);
+gmx_bool gmx_fio_ndoe_int32(struct t_fileio *fio, int32_t *item, int n,
+ const char *desc, const char *srcfile,
+ int line);
gmx_bool gmx_fio_ndoe_int64(struct t_fileio *fio, int64_t *item, int n,
const char *desc, const char *srcfile,
int line);
#define gmx_fio_do_double(fio, item) gmx_fio_doe_double(fio, &(item), (#item), __FILE__, __LINE__)
#define gmx_fio_do_gmx_bool(fio, item) gmx_fio_doe_gmx_bool(fio, &(item), (#item), __FILE__, __LINE__)
#define gmx_fio_do_int(fio, item) gmx_fio_doe_int(fio, &(item), (#item), __FILE__, __LINE__)
+#define gmx_fio_do_int32(fio, item) gmx_fio_doe_int32(fio, &(item), (#item), __FILE__, __LINE__)
#define gmx_fio_do_int64(fio, item) gmx_fio_doe_int64(fio, &(item), (#item), __FILE__, __LINE__)
#define gmx_fio_do_uchar(fio, item) gmx_fio_doe_uchar(fio, &(item), (#item), __FILE__, __LINE__)
#define gmx_fio_do_ushort(fio, item) gmx_fio_doe_ushort(fio, &(item), (#item), __FILE__, __LINE__)
#define gmx_fio_ndo_double(fio, item, n) gmx_fio_ndoe_double(fio, item, n, (#item), __FILE__, __LINE__)
#define gmx_fio_ndo_gmx_bool(fio, item, n) gmx_fio_ndoe_gmx_bool(fio, item, n, (#item), __FILE__, __LINE__)
#define gmx_fio_ndo_int(fio, item, n) gmx_fio_ndoe_int(fio, item, n, (#item), __FILE__, __LINE__)
+#define gmx_fio_ndo_int32(fio, item, n) gmx_fio_ndoe_int32(fio, item, n, (#item), __FILE__, __LINE__)
#define gmx_fio_ndo_int64(fio, item, n) gmx_fio_ndoe_int64(fio, item, n, (#item), __FILE__, __LINE__)
#define gmx_fio_ndo_uchar(fio, item, n) gmx_fio_ndoe_uchar(fio, item, n, (#item), __FILE__, __LINE__)
#define gmx_fio_ndo_ushort(fio, item, n) gmx_fio_ndoe_ushort(fio, item, n, (#item), __FILE__, __LINE__)
void doBool(bool *value) override;
void doUChar(unsigned char *value) override;
void doInt(int *value) override;
+ void doInt32(int32_t *value) override;
void doInt64(int64_t *value) override;
void doFloat(float *value) override;
void doDouble(double *value) override;
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2018,2019, 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.
#endif
}
-int xdr_int64(XDR *xdrs, int64_t *i)
+int xdr_int32(XDR *xdrs, int32_t *i)
{
- /* This routine stores values compatible with xdr_int64_t */
+ // Note that this implementation assumes that an int is at least
+ // 32 bits, which is not strictly required by the language, but
+ // good enough in practice on 32- or 64-bit systems. GROMACS
+ // requires 64-bit systems.
+ static_assert(sizeof(int) >= 4, "XDR handling assumes that an int32_t can be stored in an int");
+ int temporary = static_cast<int>(*i);
+ int ret = xdr_int(xdrs, &temporary);
+ *i = static_cast<int32_t>(temporary);
+
+ return ret;
+}
+int xdr_int64(XDR *xdrs, int64_t *i)
+{
+ // Note that this implementation assumes that an int is at least
+ // 32 bits, which is not strictly required by the language, but
+ // good enough in practice on 32- or 64-bit systems. GROMACS
+ // requires 64-bit systems.
+ static_assert(2*sizeof(int) >= 8, "XDR handling assumes that an int64_t can be stored in two ints");
int imaj, imin;
int ret;
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2018,2019, 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.
int xdr3drcoord(XDR *xdrs, real *fp, int *size, real *precision);
+//! Read or write a int32_t value.
+int xdr_int32(XDR *xdrs, int32_t *i);
+
+//! Read or write a int64_t value.
int xdr_int64(XDR *xdrs, int64_t *i);
-/* Read or write a int64_t value.
- * When warn!=NULL a warning will be written to stderr
- * when a value does not fit,
- * the first line is:
- * "WARNING during %s:", where warn is printed in %s.
- */
int xdr_xtc_seek_time(real time, FILE *fp, XDR *xdrs, int natoms, gmx_bool bSeekForwardOnly);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019, 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.
impl_->doValue(*value);
}
+void InMemorySerializer::doInt32(int32_t *value)
+{
+ impl_->doValue(*value);
+}
+
void InMemorySerializer::doInt64(int64_t *value)
{
impl_->doValue(*value);
impl_->doValue(value);
}
+void InMemoryDeserializer::doInt32(int32_t *value)
+{
+ impl_->doValue(value);
+}
+
void InMemoryDeserializer::doInt64(int64_t *value)
{
impl_->doValue(value);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019, 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.
void doBool(bool *value) override;
void doUChar(unsigned char *value) override;
void doInt(int *value) override;
+ void doInt32(int32_t *value) override;
void doInt64(int64_t *value) override;
void doFloat(float *value) override;
void doDouble(double *value) override;
void doBool(bool *value) override;
void doUChar(unsigned char *value) override;
void doInt(int *value) override;
+ void doInt32(int32_t *value) override;
void doInt64(int64_t *value) override;
void doFloat(float *value) override;
void doDouble(double *value) override;
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019, 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.
virtual void doBool(bool *value) = 0;
virtual void doUChar(unsigned char *value) = 0;
virtual void doInt(int *value) = 0;
+ virtual void doInt32(int32_t *value) = 0;
virtual void doInt64(int64_t *value) = 0;
virtual void doFloat(float *value) = 0;
virtual void doDouble(double *value) = 0;
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019, 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.
{
checker_.checkInteger(*value, nullptr);
}
+ void doInt32(int32_t *value) override
+ {
+ checker_.checkInt32(*value, nullptr);
+ }
void doInt64(int64_t *value) override
{
checker_.checkInt64(*value, nullptr);
TEST_F(KeyValueTreeSerializerTest, SimpleObject)
{
builder_.rootObject().addValue<int>("foo", 1);
+ builder_.rootObject().addValue<int32_t>("foo32", 1);
+ builder_.rootObject().addValue<int64_t>("foo64", 1);
builder_.rootObject().addValue<std::string>("bar", "a");
builder_.rootObject().addValue<float>("f", 1.5);
builder_.rootObject().addValue<double>("d", 2.5);
<ReferenceData>
<Object Name="Input">
<Int Name="foo">1</Int>
+ <Int Name="foo32">1</Int>
+ <Int64 Name="foo64">1</Int64>
<String Name="bar">a</String>
<Real Name="f">1.5</Real>
<Real Name="d">2.5</Real>
</Object>
<SerializedData Name="Stream">
- <Int>4</Int>
+ <Int>6</Int>
<String>foo</String>
<UChar>105</UChar>
<Int>1</Int>
+ <String>foo32</String>
+ <UChar>105</UChar>
+ <Int>1</Int>
+ <String>foo64</String>
+ <UChar>108</UChar>
+ <Int64>1</Int64>
<String>bar</String>
<UChar>115</UChar>
<String>a</String>
static const char * const cUCharNodeName;
//! String constant for naming XML elements for integer values.
static const char * const cIntegerNodeName;
- //! String constant for naming XML elements for int64 values.
+ //! String constant for naming XML elements for int32 values.
+ static const char * const cInt32NodeName;
+ //! String constant for naming XML elements for unsigned int32 values.
+ static const char * const cUInt32NodeName;
+ //! String constant for naming XML elements for int32 values.
static const char * const cInt64NodeName;
//! String constant for naming XML elements for unsigned int64 values.
static const char * const cUInt64NodeName;
const char *const TestReferenceChecker::Impl::cStringNodeName = "String";
const char *const TestReferenceChecker::Impl::cUCharNodeName = "UChar";
const char *const TestReferenceChecker::Impl::cIntegerNodeName = "Int";
+const char *const TestReferenceChecker::Impl::cInt32NodeName = "Int32";
+const char *const TestReferenceChecker::Impl::cUInt32NodeName = "UInt32";
const char *const TestReferenceChecker::Impl::cInt64NodeName = "Int64";
const char *const TestReferenceChecker::Impl::cUInt64NodeName = "UInt64";
const char *const TestReferenceChecker::Impl::cRealNodeName = "Real";
ExactStringChecker(formatString("%d", value))));
}
+void TestReferenceChecker::checkInt32(int32_t value, const char *id)
+{
+ EXPECT_PLAIN(impl_->processItem(Impl::cInt32NodeName, id,
+ ExactStringChecker(formatString("%" PRId32, value))));
+}
+
+void TestReferenceChecker::checkUInt32(uint32_t value, const char *id)
+{
+ EXPECT_PLAIN(impl_->processItem(Impl::cUInt32NodeName, id,
+ ExactStringChecker(formatString("%" PRIu32, value))));
+}
+
void TestReferenceChecker::checkInt64(int64_t value, const char *id)
{
EXPECT_PLAIN(impl_->processItem(Impl::cInt64NodeName, id,
{
checkInteger(any.cast<int>(), id);
}
+ else if (any.isType<int32_t>())
+ {
+ checkInt32(any.cast<int32_t>(), id);
+ }
+ else if (any.isType<uint32_t>())
+ {
+ checkInt32(any.cast<uint32_t>(), id);
+ }
else if (any.isType<int64_t>())
{
checkInt64(any.cast<int64_t>(), id);
}
+ else if (any.isType<uint64_t>())
+ {
+ checkInt64(any.cast<uint64_t>(), id);
+ }
else if (any.isType<float>())
{
checkFloat(any.cast<float>(), id);
}
+int32_t TestReferenceChecker::readInt32(const char *id)
+{
+ if (impl_->shouldIgnore())
+ {
+ GMX_THROW(TestException("Trying to read from non-existent reference data value"));
+ }
+ int32_t value = 0;
+ EXPECT_PLAIN(impl_->processItem(Impl::cInt32NodeName, id,
+ ValueExtractor<int32_t>(&value)));
+ return value;
+}
+
+
int64_t TestReferenceChecker::readInt64(const char *id)
{
if (impl_->shouldIgnore())
void checkUChar(unsigned char value, const char *id);
//! Check a single integer value.
void checkInteger(int value, const char *id);
+ //! Check a single int32 value.
+ void checkInt32(int32_t value, const char *id);
+ //! Check a single uint32 value.
+ void checkUInt32(uint32_t value, const char *id);
//! Check a single int64 value.
void checkInt64(int64_t value, const char *id);
//! Check a single uint64 value.
unsigned char readUChar(const char *id);
//! Reads an integer value.
int readInteger(const char *id);
+ //! Reads a 32-bit integer value.
+ int32_t readInt32(const char *id);
//! Reads a 64-bit integer value.
int64_t readInt64(const char *id);
//! Reads a float value.
{
checkString(value, id);
}
- //! Check a single integer value.
+ //! Check a single signed integer value
void checkValue(int value, const char *id)
{
checkInteger(value, id);
}
- //! Check a single integer value.
+ //! Check a single signed integer value of width 64 bits.
void checkValue(int64_t value, const char *id)
{
checkInt64(value, id);
}
- //! Check a single integer value.
+ //! Check a single unsigned integer value of width 64 bits.
void checkValue(uint64_t value, const char *id)
{
checkUInt64(value, id);
TestReferenceChecker checker(data.rootChecker());
checker.checkBoolean(true, "bool");
checker.checkInteger(1, "int");
+ checker.checkInt32(1ULL<<12, "int32");
+ checker.checkUInt32(1ULL<<12, "uint32");
checker.checkInt64(1ULL<<42, "int64");
checker.checkUInt64(1ULL<<42, "uint64");
checker.checkDouble(0.5, "real");
TestReferenceChecker checker(data.rootChecker());
checker.checkBoolean(true, "bool");
checker.checkInteger(1, "int");
+ checker.checkInt32(1ULL<<12, "int32");
+ checker.checkUInt32(1ULL<<12, "uint32");
checker.checkInt64(1ULL<<42, "int64");
checker.checkUInt64(1ULL<<42, "uint64");
checker.checkDouble(0.5, "real");