* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
/* Extract Time info from arguments */
if (bBeginTimeSet)
{
- setTimeValue(TBEGIN, tbegin);
+ setTimeValue(TimeControl::Begin, tbegin);
}
if (bEndTimeSet)
{
- setTimeValue(TEND, tend);
+ setTimeValue(TimeControl::End, tend);
}
if (bDtSet)
{
- setTimeValue(TDELTA, tdelta);
+ setTimeValue(TimeControl::Delta, tdelta);
}
adapter.copyValues();
* the research papers on the package. Check out http://www.gromacs.org.
*/
-#ifndef _checkpoint_h
-#define _checkpoint_h
+#ifndef GMX_FILEIO_CHECKPOINT_H
+#define GMX_FILEIO_CHECKPOINT_H
#include <cstdio>
{
// We always assign a new chain number, but only assign a chain id
// characters for larger molecules.
- int chainIdToAssign;
+ char chainIdToAssign;
if (endAtomIndex - startAtomIndex >= s_chainMinAtoms && !outOfIds_)
{
/* Set the chain id for the output */
/* This number should be increased whenever the file format changes! */
static const int enx_version = 5;
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
const char* enx_block_id_name[] = { "Averaged orientation restraints",
"Instantaneous orientation restraints",
"Orientation restraint order tensor(s)",
};
/* names for the above enum */
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
extern const char* enx_block_id_name[];
/* the list of open files is a linked list, with a dummy element at its head;
it is initialized when the first file is opened. */
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static t_fileio* open_files = nullptr;
opening and closing of files, or during global operations like
iterating along all open files. All these cases should be rare
during the simulation. */
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static std::mutex open_file_mutex;
using Lock = std::lock_guard<std::mutex>;
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
#include "gromacs/fileio/gmxfio.h"
#include "gromacs/fileio/xdrf.h"
+#include "gromacs/utility/enumerationhelpers.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
#include "gmxfio_impl.h"
/* Enumerated for data types in files */
-enum
-{
- eioREAL,
- eioFLOAT,
- eioDOUBLE,
- eioINT,
- eioINT32,
- eioINT64,
- eioUCHAR,
- eioCHAR,
- eioNCHAR,
- eioNUCHAR,
- eioUSHORT,
- eioRVEC,
- eioNRVEC,
- eioIVEC,
- eioSTRING,
- eioOPAQUE,
- eioNR
+enum class IOType : int
+{
+ REAL,
+ FLOAT,
+ DOUBLE,
+ INT,
+ INT32,
+ INT64,
+ UCHAR,
+ CHAR,
+ NCHAR,
+ NUCHAR,
+ USHORT,
+ RVEC,
+ NRVEC,
+ IVEC,
+ STRING,
+ OPAQUE,
+ Count
};
-static const char* eioNames[eioNR] = { "REAL", "FLOAT", "DOUBLE", "INT", "INT32", "INT64",
- "UCHAR", "CHAR", "NCHAR", "NUCHAR", "USHORT", "RVEC",
- "NRVEC", "IVEC", "STRING", "OPAQUE" };
+static const char* enumValueToString(IOType enumValue)
+{
+ constexpr gmx::EnumerationArray<IOType, const char*> ioTypeNames = {
+ "REAL", "FLOAT", "DOUBLE", "INT", "INT32", "INT64", "UCHAR", "CHAR",
+ "NCHAR", "NUCHAR", "USHORT", "RVEC", "NRVEC", "IVEC", "STRING", "OPAQUE"
+ };
+ return ioTypeNames[enumValue];
+}
void gmx_fio_setprecision(t_fileio* fio, gmx_bool bDouble)
{
}
/* check the number of items given against the type */
-static void gmx_fio_check_nitem(int eio, std::size_t nitem, const char* file, int line)
+static void gmx_fio_check_nitem(IOType eio, std::size_t nitem, const char* file, int line)
{
if ((nitem != 1)
- && !((eio == eioNRVEC) || (eio == eioNUCHAR) || (eio == eioNCHAR) || (eio == eioOPAQUE)))
+ && !((eio == IOType::NRVEC) || (eio == IOType::NUCHAR) || (eio == IOType::NCHAR)
+ || (eio == IOType::OPAQUE)))
{
gmx_fatal(FARGS,
"nitem may differ from 1 only for %s, %s, %s or %s, not for %s"
"(%s, %d)",
- eioNames[eioNUCHAR],
- eioNames[eioNRVEC],
- eioNames[eioNCHAR],
- eioNames[eioOPAQUE],
- eioNames[eio],
+ enumValueToString(IOType::NUCHAR),
+ enumValueToString(IOType::NRVEC),
+ enumValueToString(IOType::NCHAR),
+ enumValueToString(IOType::OPAQUE),
+ enumValueToString(eio),
file,
line);
}
}
/* output a data type error. */
-[[noreturn]] static void gmx_fio_fe(t_fileio* fio, int eio, const char* desc, const char* srcfile, int line)
+[[noreturn]] static void gmx_fio_fe(t_fileio* fio, IOType eio, const char* desc, const char* srcfile, int line)
{
gmx_fatal(FARGS,
"Trying to %s %s type %d (%s), src %s, line %d",
fio->bRead ? "read" : "write",
desc,
- eio,
- ((eio >= 0) && (eio < eioNR)) ? eioNames[eio] : "unknown",
+ static_cast<int>(eio),
+ ((eio >= IOType::REAL) && (eio < IOType::Count)) ? enumValueToString(eio) : "unknown",
srcfile,
line);
}
/* This is the part that reads xdr files. */
-
static gmx_bool
-do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, const char* srcfile, int line)
+do_xdr(t_fileio* fio, void* item, std::size_t nitem, IOType eio, const char* desc, const char* srcfile, int line)
{
unsigned char ucdum, *ucptr;
char cdum, *cptr;
gmx_fio_check_nitem(eio, nitem, srcfile, line);
switch (eio)
{
- case eioREAL:
+ case IOType::REAL:
if (fio->bDouble)
{
if (item && !fio->bRead)
}
}
break;
- case eioFLOAT:
+ case IOType::FLOAT:
if (item && !fio->bRead)
{
f = *(static_cast<float*>(item));
*(static_cast<float*>(item)) = f;
}
break;
- case eioDOUBLE:
+ case IOType::DOUBLE:
if (item && !fio->bRead)
{
d = *(static_cast<double*>(item));
*(static_cast<double*>(item)) = d;
}
break;
- case eioINT:
+ case IOType::INT:
if (item && !fio->bRead)
{
idum = *static_cast<int*>(item);
*static_cast<int*>(item) = idum;
}
break;
- case eioINT32:
+ case IOType::INT32:
if (item && !fio->bRead)
{
s32dum = *static_cast<int32_t*>(item);
*static_cast<int32_t*>(item) = s32dum;
}
break;
- case eioINT64:
+ case IOType::INT64:
if (item && !fio->bRead)
{
s64dum = *static_cast<int64_t*>(item);
*static_cast<int64_t*>(item) = s64dum;
}
break;
- case eioUCHAR:
+ case IOType::UCHAR:
if (item && !fio->bRead)
{
ucdum = *static_cast<unsigned char*>(item);
*static_cast<unsigned char*>(item) = ucdum;
}
break;
- case eioCHAR:
+ case IOType::CHAR:
if (item && !fio->bRead)
{
cdum = *static_cast<char*>(item);
*static_cast<char*>(item) = cdum;
}
break;
- case eioNCHAR:
+ case IOType::NCHAR:
cptr = static_cast<char*>(item);
GMX_RELEASE_ASSERT(nitem < static_cast<std::size_t>(std::numeric_limits<int>::max()),
"The XDR interface cannot handle array lengths > 2^31");
static_cast<unsigned int>(sizeof(char)),
reinterpret_cast<xdrproc_t>(xdr_char));
break;
- case eioNUCHAR:
+ case IOType::NUCHAR:
ucptr = static_cast<unsigned char*>(item);
GMX_RELEASE_ASSERT(nitem < static_cast<std::size_t>(std::numeric_limits<int>::max()),
"The XDR interface cannot handle array lengths > 2^31");
static_cast<unsigned int>(sizeof(unsigned char)),
reinterpret_cast<xdrproc_t>(xdr_u_char));
break;
- case eioUSHORT:
+ case IOType::USHORT:
if (item && !fio->bRead)
{
us = *static_cast<unsigned short*>(item);
*static_cast<unsigned short*>(item) = us;
}
break;
- case eioRVEC:
+ case IOType::RVEC:
if (fio->bDouble)
{
if (item && !fio->bRead)
}
}
break;
- case eioNRVEC:
+ case IOType::NRVEC:
ptr = nullptr;
res = 1;
for (std::size_t j = 0; j < nitem && res; j++)
{
ptr = (static_cast<rvec*>(item))[j];
}
- res = static_cast<bool_t>(do_xdr(fio, ptr, 1, eioRVEC, desc, srcfile, line));
+ res = static_cast<bool_t>(do_xdr(fio, ptr, 1, IOType::RVEC, desc, srcfile, line));
}
break;
- case eioIVEC:
+ case IOType::IVEC:
iptr = static_cast<int*>(item);
res = 1;
for (m = 0; (m < DIM) && res; m++)
}
}
break;
- case eioSTRING:
+ case IOType::STRING:
{
char* cptr;
int slen;
}
break;
}
- case eioOPAQUE:
+ case IOType::OPAQUE:
{
if (item == nullptr && nitem > 0)
{
gmx_bool ret;
void* it = const_cast<char*>(item); /* ugh.. */
gmx_fio_lock(fio);
- ret = do_xdr(fio, it, 1, eioSTRING, desc, srcfile, line);
+ ret = do_xdr(fio, it, 1, IOType::STRING, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
{
gmx_bool ret;
gmx_fio_lock(fio);
- ret = do_xdr(fio, item, 1, eioREAL, desc, srcfile, line);
+ ret = do_xdr(fio, item, 1, IOType::REAL, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
{
gmx_bool ret;
gmx_fio_lock(fio);
- ret = do_xdr(fio, item, 1, eioFLOAT, desc, srcfile, line);
+ ret = do_xdr(fio, item, 1, IOType::FLOAT, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
{
gmx_bool ret;
gmx_fio_lock(fio);
- ret = do_xdr(fio, item, 1, eioDOUBLE, desc, srcfile, line);
+ ret = do_xdr(fio, item, 1, IOType::DOUBLE, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
if (fio->bRead)
{
int itmp = 0;
- ret = do_xdr(fio, &itmp, 1, eioINT, desc, srcfile, line);
+ ret = do_xdr(fio, &itmp, 1, IOType::INT, desc, srcfile, line);
*item = (itmp != 0);
}
else
{
int itmp = static_cast<int>(*item);
- ret = do_xdr(fio, &itmp, 1, eioINT, desc, srcfile, line);
+ ret = do_xdr(fio, &itmp, 1, IOType::INT, desc, srcfile, line);
}
gmx_fio_unlock(fio);
return ret;
{
gmx_bool ret;
gmx_fio_lock(fio);
- ret = do_xdr(fio, item, 1, eioINT, desc, srcfile, line);
+ ret = do_xdr(fio, item, 1, IOType::INT, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
{
gmx_bool ret;
gmx_fio_lock(fio);
- ret = do_xdr(fio, item, 1, eioINT32, desc, srcfile, line);
+ ret = do_xdr(fio, item, 1, IOType::INT32, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
{
gmx_bool ret;
gmx_fio_lock(fio);
- ret = do_xdr(fio, item, 1, eioINT64, desc, srcfile, line);
+ ret = do_xdr(fio, item, 1, IOType::INT64, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
{
gmx_bool ret;
gmx_fio_lock(fio);
- ret = do_xdr(fio, item, 1, eioUCHAR, desc, srcfile, line);
+ ret = do_xdr(fio, item, 1, IOType::UCHAR, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
{
gmx_bool ret;
gmx_fio_lock(fio);
- ret = do_xdr(fio, item, 1, eioCHAR, desc, srcfile, line);
+ ret = do_xdr(fio, item, 1, IOType::CHAR, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
{
gmx_bool ret;
gmx_fio_lock(fio);
- ret = do_xdr(fio, item, 1, eioUSHORT, desc, srcfile, line);
+ ret = do_xdr(fio, item, 1, IOType::USHORT, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
{
gmx_bool ret;
gmx_fio_lock(fio);
- ret = do_xdr(fio, item, 1, eioRVEC, desc, srcfile, line);
+ ret = do_xdr(fio, item, 1, IOType::RVEC, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
{
gmx_bool ret;
gmx_fio_lock(fio);
- ret = do_xdr(fio, item, 1, eioIVEC, desc, srcfile, line);
+ ret = do_xdr(fio, item, 1, IOType::IVEC, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
{
gmx_bool ret;
gmx_fio_lock(fio);
- ret = do_xdr(fio, item, 1, eioSTRING, desc, srcfile, line);
+ ret = do_xdr(fio, item, 1, IOType::STRING, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
{
gmx_bool ret;
gmx_fio_lock(fio);
- ret = do_xdr(fio, data, size, eioOPAQUE, desc, srcfile, line);
+ ret = do_xdr(fio, data, size, IOType::OPAQUE, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
gmx_fio_lock(fio);
for (i = 0; i < n; i++)
{
- ret = ret && do_xdr(fio, &(item[i]), 1, eioREAL, desc, srcfile, line);
+ ret = ret && do_xdr(fio, &(item[i]), 1, IOType::REAL, desc, srcfile, line);
}
gmx_fio_unlock(fio);
return ret;
gmx_fio_lock(fio);
for (i = 0; i < n; i++)
{
- ret = ret && do_xdr(fio, &(item[i]), 1, eioFLOAT, desc, srcfile, line);
+ ret = ret && do_xdr(fio, &(item[i]), 1, IOType::FLOAT, desc, srcfile, line);
}
gmx_fio_unlock(fio);
return ret;
gmx_fio_lock(fio);
for (i = 0; i < n; i++)
{
- ret = ret && do_xdr(fio, &(item[i]), 1, eioDOUBLE, desc, srcfile, line);
+ ret = ret && do_xdr(fio, &(item[i]), 1, IOType::DOUBLE, desc, srcfile, line);
}
gmx_fio_unlock(fio);
return ret;
if (fio->bRead)
{
int itmp = 0;
- ret = ret && do_xdr(fio, &itmp, 1, eioINT, desc, srcfile, line);
+ ret = ret && do_xdr(fio, &itmp, 1, IOType::INT, desc, srcfile, line);
item[i] = (itmp != 0);
}
else
{
int itmp = static_cast<int>(item[i]);
- ret = ret && do_xdr(fio, &itmp, 1, eioINT, desc, srcfile, line);
+ ret = ret && do_xdr(fio, &itmp, 1, IOType::INT, desc, srcfile, line);
}
}
gmx_fio_unlock(fio);
gmx_fio_lock(fio);
for (i = 0; i < n; i++)
{
- ret = ret && do_xdr(fio, &(item[i]), 1, eioINT, desc, srcfile, line);
+ ret = ret && do_xdr(fio, &(item[i]), 1, IOType::INT, desc, srcfile, line);
}
gmx_fio_unlock(fio);
return ret;
gmx_fio_lock(fio);
for (i = 0; i < n; i++)
{
- ret = ret && do_xdr(fio, &(item[i]), 1, eioINT64, desc, srcfile, line);
+ ret = ret && do_xdr(fio, &(item[i]), 1, IOType::INT64, desc, srcfile, line);
}
gmx_fio_unlock(fio);
return ret;
{
gmx_bool ret = TRUE;
gmx_fio_lock(fio);
- ret = ret && do_xdr(fio, item, n, eioNUCHAR, desc, srcfile, line);
+ ret = ret && do_xdr(fio, item, n, IOType::NUCHAR, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
{
gmx_bool ret = TRUE;
gmx_fio_lock(fio);
- ret = ret && do_xdr(fio, item, n, eioNCHAR, desc, srcfile, line);
+ ret = ret && do_xdr(fio, item, n, IOType::NCHAR, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
gmx_fio_lock(fio);
for (i = 0; i < n; i++)
{
- ret = ret && do_xdr(fio, &(item[i]), 1, eioUSHORT, desc, srcfile, line);
+ ret = ret && do_xdr(fio, &(item[i]), 1, IOType::USHORT, desc, srcfile, line);
}
gmx_fio_unlock(fio);
return ret;
{
gmx_bool ret = TRUE;
gmx_fio_lock(fio);
- ret = ret && do_xdr(fio, item, n, eioNRVEC, desc, srcfile, line);
+ ret = ret && do_xdr(fio, item, n, IOType::NRVEC, desc, srcfile, line);
gmx_fio_unlock(fio);
return ret;
}
gmx_fio_lock(fio);
for (i = 0; i < n; i++)
{
- ret = ret && do_xdr(fio, &(item[i]), 1, eioIVEC, desc, srcfile, line);
+ ret = ret && do_xdr(fio, &(item[i]), 1, IOType::IVEC, desc, srcfile, line);
}
gmx_fio_unlock(fio);
return ret;
gmx_fio_lock(fio);
for (i = 0; i < n; i++)
{
- ret = ret && do_xdr(fio, &(item[i]), 1, eioSTRING, desc, srcfile, line);
+ ret = ret && do_xdr(fio, &(item[i]), 1, IOType::STRING, desc, srcfile, line);
}
gmx_fio_unlock(fio);
return ret;
{
gmx::KeyValueTreeBuilder builder;
auto root = builder.rootObject();
- for (auto& local : inp)
+ for (const auto& local : inp)
{
root.addValue<std::string>(local.name_, !local.value_.empty() ? local.value_ : "");
}
--- /dev/null
+# List of rationales for check suppressions (where known).
+# This have to precede the list because inline comments are not
+# supported by clang-tidy.
+#
+# -cppcoreguidelines-non-private-member-variables-in-classes,
+# -misc-non-private-member-variables-in-classes,
+# We intend a gradual transition to conform to this guideline, but it
+# is not practical to implement yet.
+#
+# -readability-isolate-declaration,
+# Declarations like "int a, b;" are readable. Some forms are not, and
+# those might reasonably be suggested against during code review.
+#
+# -cppcoreguidelines-avoid-c-arrays,
+# C arrays are still necessary in many places with legacy code
+#
+# -cppcoreguidelines-avoid-magic-numbers,
+# -readability-magic-numbers,
+# We have many legitimate use cases for magic numbers
+#
+# -cppcoreguidelines-macro-usage,
+# We do use too many macros, and we should fix many of them, but there
+# is no reasonable way to suppress the check e.g. in src/config.h and
+# configuring the build is a major legitimate use of macros.
+#
+# -cppcoreguidelines-narrowing-conversions,
+# -bugprone-narrowing-conversions
+# We have many cases where int is converted to float and we don't care
+# enough about such potential loss of precision to use explicit casts
+# in large numbers of places.
+#
+# -google-readability-avoid-underscore-in-googletest-name
+# We need to use underscores for readability for our legacy types
+# and command-line parameter names
+#
+# -misc-no-recursion
+# We have way too many functions and methods relying on recursion
+#
+# -cppcoreguidelines-avoid-non-const-global-variables
+# There are quite a lot of static variables in the test code that
+# can not be replaced.
+#
+# -modernize-avoid-bind
+# Some code needs to use std::bind and can't be modernized quickly.
+Checks: clang-diagnostic-*,-clang-analyzer-*,-clang-analyzer-security.insecureAPI.strcpy,
+ bugprone-*,misc-*,readability-*,performance-*,mpi-*,
+ -readability-inconsistent-declaration-parameter-name,
+ -readability-function-size,-readability-else-after-return,
+ modernize-use-nullptr,modernize-use-emplace,
+ modernize-make-unique,modernize-make-shared,
+ modernize-avoid-bind,
+ modernize-use-override,
+ modernize-redundant-void-arg,modernize-use-bool-literals,
+ cppcoreguidelines-*,-cppcoreguidelines-pro-*,-cppcoreguidelines-owning-memory,
+ -cppcoreguidelines-no-malloc,-cppcoreguidelines-special-member-functions,
+ -cppcoreguidelines-avoid-goto,
+ google-*,-google-build-using-namespace,-google-explicit-constructor,
+ -google-readability-function-size,-google-readability-todo,-google-runtime-int,
+ -cppcoreguidelines-non-private-member-variables-in-classes,
+ -misc-non-private-member-variables-in-classes,
+ -readability-isolate-declaration,
+ -cppcoreguidelines-avoid-c-arrays,
+ -cppcoreguidelines-avoid-magic-numbers,
+ -readability-magic-numbers,
+ -cppcoreguidelines-macro-usage,
+ -cppcoreguidelines-narrowing-conversions,
+ -bugprone-narrowing-conversions,
+ -google-readability-avoid-underscore-in-googletest-name,
+ -cppcoreguidelines-init-variables,
+ -misc-no-recursion,
+ -cppcoreguidelines-avoid-non-const-global-variables,
+ -modernize-avoid-bind
+HeaderFilterRegex: .*
+CheckOptions:
+ - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
+ value: 1
+ - key: modernize-make-unique.IncludeStyle
+ value: google
+ - key: modernize-make-shared.IncludeStyle
+ value: google
+ - key: readability-implicit-bool-conversion.AllowIntegerConditions
+ value: 1
+ - key: readability-implicit-bool-conversion.AllowPointerConditions
+ value: 1
+ - key: bugprone-dangling-handle.HandleClasses
+ value: std::basic_string_view; nonstd::sv_lite::basic_string_view
+# Permit passing shard pointers by value for sink parameters
+ - key: performance-unnecessary-copy-initialization.AllowedTypes
+ value: shared_ptr
+ - key: performance-unnecessary-value-param.AllowedTypes
+ value: shared_ptr
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2021, 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.
class FileMD5Test : public ::testing::Test
{
public:
- void prepareFile(int lengthInBytes)
+ void prepareFile(int lengthInBytes) const
{
// Fill some memory with some arbitrary bits.
std::vector<char> data(lengthInBytes);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2020, by the GROMACS development team, led by
+ * Copyright (c) 2020,2021, 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 useStringAsXvgFile(const std::string& xvgString) { referenceContents_ = xvgString; }
- void writeXvgFile()
+ void writeXvgFile() const
{
gmx::TextWriter::writeFileFromString(referenceFilename(), referenceContents());
}
*/
#include "gmxpre.h"
+#include "gromacs/utility/enumerationhelpers.h"
#include "timecontrol.h"
#include <mutex>
Please keep it that way. */
/* Globals for trajectory input */
-typedef struct
+struct t_timecontrol
{
- real t;
- gmx_bool bSet;
-} t_timecontrol;
+ t_timecontrol(real inputT, bool inputSet) : t(inputT), bSet(inputSet) {}
+ real t;
+ bool bSet;
+};
-static t_timecontrol timecontrol[TNR] = { { 0, FALSE }, { 0, FALSE }, { 0, FALSE } };
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
+static gmx::EnumerationArray<TimeControl, t_timecontrol> timecontrol = { t_timecontrol(0, false),
+ t_timecontrol(0, false),
+ t_timecontrol(0, false) };
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static std::mutex g_timeControlMutex;
-gmx_bool bTimeSet(int tcontrol)
+gmx_bool bTimeSet(TimeControl tcontrol)
{
gmx_bool ret;
const std::lock_guard<std::mutex> lock(g_timeControlMutex);
- range_check(tcontrol, 0, TNR);
ret = timecontrol[tcontrol].bSet;
return ret;
}
-real rTimeValue(int tcontrol)
+real rTimeValue(TimeControl tcontrol)
{
real ret;
const std::lock_guard<std::mutex> lock(g_timeControlMutex);
- range_check(tcontrol, 0, TNR);
ret = timecontrol[tcontrol].t;
return ret;
}
-void setTimeValue(int tcontrol, real value)
+void setTimeValue(TimeControl tcontrol, real value)
{
const std::lock_guard<std::mutex> lock(g_timeControlMutex);
- range_check(tcontrol, 0, TNR);
timecontrol[tcontrol].t = value;
timecontrol[tcontrol].bSet = TRUE;
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2013,2014,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2018,2019,2021, 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.
/* The code below is to facilitate controlled begin and end of
* trajectory reading.
*/
-enum
+enum class TimeControl : int
{
- TBEGIN,
- TEND,
- TDELTA,
- TNR
+ Begin,
+ End,
+ Delta,
+ Count
};
-gmx_bool bTimeSet(int tcontrol);
+bool bTimeSet(TimeControl tcontrol);
-real rTimeValue(int tcontrol);
+real rTimeValue(TimeControl tcontrol);
-void setTimeValue(int tcontrol, real value);
+void setTimeValue(TimeControl tcontrol, real value);
#endif
* merging with mainstream GROMACS, set this tag string back to
* TPX_TAG_RELEASE, and instead add an element to tpxv.
*/
-static const char* tpx_tag = TPX_TAG_RELEASE;
+static const std::string tpx_tag = TPX_TAG_RELEASE;
/*! \brief Enum of values that describe the contents of a tpr file
* whose format matches a version number
serializer->doString(&buf);
gmx_fio_setprecision(fio, tpx->isDouble);
serializer->doInt(&precision);
- fileTag = gmx::formatString("%s", tpx_tag);
+ fileTag = tpx_tag;
}
/* Check versions! */
if (fileTag != tpx_tag)
{
- fprintf(stderr, "Note: file tpx tag '%s', software tpx tag '%s'\n", fileTag.c_str(), tpx_tag);
+ fprintf(stderr, "Note: file tpx tag '%s', software tpx tag '%s'\n", fileTag.c_str(), tpx_tag.c_str());
/* We only support reading tpx files with the same tag as the code
* or tpx files with the release tag and with lower version number.
tpx->fileVersion,
fileTag.c_str(),
tpx_version,
- tpx_tag);
+ tpx_tag.c_str());
}
}
}
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
struct t_trxstatus
{
int flags; /* flags for read_first/next_frame */
- int __frame;
+ int currentFrame;
real t0; /* time of the first frame, needed *
* for skipping frames with -dt */
real tf; /* internal frame time */
#endif
r = -1;
- if ((!bTimeSet(TBEGIN) || (t >= rTimeValue(TBEGIN))) && (!bTimeSet(TEND) || (t <= rTimeValue(TEND))))
+ if ((!bTimeSet(TimeControl::Begin) || (t >= rTimeValue(TimeControl::Begin)))
+ && (!bTimeSet(TimeControl::End) || (t <= rTimeValue(TimeControl::End))))
{
- if (bTimeSet(TDELTA) && !bRmod_fd(t, t0, rTimeValue(TDELTA), bDouble))
+ if (bTimeSet(TimeControl::Delta) && !bRmod_fd(t, t0, rTimeValue(TimeControl::Delta), bDouble))
{
r = -1;
}
r = 0;
}
}
- else if (bTimeSet(TEND) && (t >= rTimeValue(TEND)))
+ else if (bTimeSet(TimeControl::End) && (t >= rTimeValue(TimeControl::End)))
{
r = 1;
}
"t=%g, t0=%g, b=%g, e=%g, dt=%g: r=%d\n",
t,
t0,
- rTimeValue(TBEGIN),
- rTimeValue(TEND),
- rTimeValue(TDELTA),
+ rTimeValue(TimeControl::Begin),
+ rTimeValue(TimeControl::End),
+ rTimeValue(TimeControl::Delta),
r);
}
return r;
static void initcount(t_trxstatus* status)
{
- status->__frame = -1;
+ status->currentFrame = -1;
}
static void status_init(t_trxstatus* status)
status->flags = 0;
status->xframe = nullptr;
status->fio = nullptr;
- status->__frame = -1;
+ status->currentFrame = -1;
status->t0 = 0;
status->tf = 0;
status->persistent_line = nullptr;
int nframes_read(t_trxstatus* status)
{
- return status->__frame;
+ return status->currentFrame;
}
static void printcount_(t_trxstatus* status, const gmx_output_env_t* oenv, const char* l, real t)
{
- if ((status->__frame < 2 * SKIP1 || status->__frame % SKIP1 == 0)
- && (status->__frame < 2 * SKIP2 || status->__frame % SKIP2 == 0)
- && (status->__frame < 2 * SKIP3 || status->__frame % SKIP3 == 0)
+ if ((status->currentFrame < 2 * SKIP1 || status->currentFrame % SKIP1 == 0)
+ && (status->currentFrame < 2 * SKIP2 || status->currentFrame % SKIP2 == 0)
+ && (status->currentFrame < 2 * SKIP3 || status->currentFrame % SKIP3 == 0)
&& output_env_get_trajectory_io_verbosity(oenv) != 0)
{
- fprintf(stderr, "\r%-14s %6d time %8.3f ", l, status->__frame, output_env_conv_time(oenv, t));
+ fprintf(stderr, "\r%-14s %6d time %8.3f ", l, status->currentFrame, output_env_conv_time(oenv, t));
fflush(stderr);
}
}
static void printcount(t_trxstatus* status, const gmx_output_env_t* oenv, real t, gmx_bool bSkip)
{
- status->__frame++;
+ status->currentFrame++;
printcount_(status, oenv, bSkip ? "Skipping frame" : "Reading frame", t);
}
{
if (fr->not_ok & HEADER_NOT_OK)
{
- fprintf(stderr, "WARNING: Incomplete header: nr %d time %g\n", status->__frame + 1, fr->time);
+ fprintf(stderr, "WARNING: Incomplete header: nr %d time %g\n", status->currentFrame + 1, fr->time);
}
else if (fr->not_ok)
{
- fprintf(stderr, "WARNING: Incomplete frame: nr %d time %g\n", status->__frame + 1, fr->time);
+ fprintf(stderr, "WARNING: Incomplete frame: nr %d time %g\n", status->currentFrame + 1, fr->time);
}
fflush(stderr);
}
break;
}
case efXTC:
- if (bTimeSet(TBEGIN) && (status->tf < rTimeValue(TBEGIN)))
+ if (bTimeSet(TimeControl::Begin) && (status->tf < rTimeValue(TimeControl::Begin)))
{
- if (xtc_seek_time(status->fio, rTimeValue(TBEGIN), fr->natoms, TRUE))
+ if (xtc_seek_time(status->fio, rTimeValue(TimeControl::Begin), fr->natoms, TRUE))
{
gmx_fatal(FARGS,
"Specified frame (time %f) doesn't exist or file "
"corrupt/inconsistent.",
- rTimeValue(TBEGIN));
+ rTimeValue(TimeControl::Begin));
}
initcount(status);
}
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
delete wi;
}
-void _too_few(warninp_t wi, const char* fn, int line)
+void too_few_function(warninp_t wi, const char* fn, int line)
{
char buf[STRLEN];
warning(wi, buf);
}
-void _incorrect_n_param(warninp_t wi, const char* fn, int line)
+void incorrect_n_param_function(warninp_t wi, const char* fn, int line)
{
char buf[STRLEN];
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2010,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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 free_warning(warninp_t wi);
/* Frees the data structure pointed to by wi. */
-void _too_few(warninp_t wi, const char* fn, int line);
-#define too_few(wi) _too_few(wi, __FILE__, __LINE__)
+void too_few_function(warninp_t wi, const char* fn, int line);
+#define too_few(wi) too_few_function(wi, __FILE__, __LINE__)
/* Issue a warning stating 'Too few parameters' */
-void _incorrect_n_param(warninp_t wi, const char* fn, int line);
-#define incorrect_n_param(wi) _incorrect_n_param(wi, __FILE__, __LINE__)
+void incorrect_n_param_function(warninp_t wi, const char* fn, int line);
+#define incorrect_n_param(wi) incorrect_n_param_function(wi, __FILE__, __LINE__)
/* Issue a warning stating 'Incorrect number of parameters' */
#endif
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2017,2018 by the GROMACS development team.
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, 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.
#include "writeps.h"
#include "gromacs/fileio/gmxfio.h"
+#include "gromacs/utility/enumerationhelpers.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
using namespace gmx;
-const char* fontnm[efontNR] = {
- "Times-Roman", "Times-Italic", "Times-Bold", "Times-BoldItalic",
- "Helvetica", "Helvetica-Oblique", "Helvetica-Bold", "Helvetica-BoldOblique",
- "Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique"
-};
+const char* enumValueToString(Fonts enumValue)
+{
+ gmx::EnumerationArray<Fonts, const char*> fontNames = {
+ "Times-Roman", "Times-Italic", "Times-Bold", "Times-BoldItalic",
+ "Helvetica", "Helvetica-Oblique", "Helvetica-Bold", "Helvetica-BoldOblique",
+ "Courier", "Courier-Oblique", "Courier-Bold", "Courier-BoldOblique"
+ };
+ return fontNames[enumValue];
+}
t_psdata ps_open(const char* fn, real x1, real y1, real x2, real y2)
{
ps_arc(ps, x1, y1, rad, 0, 360);
}
-void ps_font(t_psdata* ps, int font, real size)
+void ps_font(t_psdata* ps, Fonts font, real size)
{
- if ((font < 0) || (font > efontNR))
+ if (font == Fonts::Count)
{
- fprintf(stderr, "Invalid Font: %d, using %s\n", font, fontnm[0]);
- font = 0;
+ fprintf(stderr, "Invalid Font: %d, using %s\n", static_cast<int>(font), enumValueToString(Fonts::Times));
+ font = Fonts::Times;
}
- fprintf(ps->fp, "/%s findfont\n", fontnm[font]);
+ fprintf(ps->fp, "/%s findfont\n", enumValueToString(font));
fprintf(ps->fp, "%g scalefont setfont\n", size);
}
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2010,2014,2015,2019, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014,2015,2019,2021, 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.
eYBottom
} eYPos;
-enum
+enum class Fonts : int
{
- efontTIMES,
- efontTIMESITALIC,
- efontTIMESBOLD,
- efontTIMESBOLDITALIC,
- efontHELV,
- efontHELVITALIC,
- efontHELVBOLD,
- efontHELVBOLDITALIC,
- efontCOUR,
- efontCOURITALIC,
- efontCOURBOLD,
- efontCOURBOLDITALIC,
- efontNR
+ Times,
+ TimesItalic,
+ TimesBold,
+ TimesBoldItalic,
+ Helvetica,
+ HelveticaItalic,
+ HelveticaBold,
+ HelveticaBoldItalic,
+ Courier,
+ CourierItalic,
+ CourierBold,
+ CourierBoldItalic,
+ Count
};
};
-extern const char* fontnm[efontNR];
+const char* enumValueToString(Fonts enumValue);
t_psdata ps_open(const char* fn, real x1, real y1, real x2, real y2);
void ps_circle(t_psdata* ps, real x1, real y1, real rad);
-void ps_font(t_psdata* ps, int font, real size);
+void ps_font(t_psdata* ps, Fonts font, real size);
void ps_strfont(t_psdata* ps, char* font, real size);
void ps_text(t_psdata* ps, real x1, real y1, const std::string& str);
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
#include "xvgr.h"
+#include <array>
#include <cassert>
#include <cctype>
#include <cstring>
}
}
-static const char* LocTypeStr[] = { "view", "world" };
-static const char* BoxFillStr[] = { "none", "color", "pattern" };
+static constexpr std::array<const char*, 2> LocTypeStr = { "view", "world" };
+static constexpr std::array<const char*, 3> BoxFillStr = { "none", "color", "pattern" };
void xvgr_box(FILE* out,
int LocType,
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2017,2018 by the GROMACS development team.
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, 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.
xc = box;
yc = box;
- ps_font(&out, efontHELV, 1.5 * fontsize);
+ ps_font(&out, Fonts::Helvetica, 1.5 * fontsize);
ps_translate(&out, xc, yc);
if (title)
{
ps_ctext(&out, 0, -fontsize * 1.5 / 2.0, title, eXCenter);
}
- ps_font(&out, efontHELV, fontsize);
+ ps_font(&out, Fonts::Helvetica, fontsize);
ps_rotate(&out, rot0);
for (i = 0; (i < nres);)
{
xc = box;
yc = box;
- ps_font(&out, efontHELV, 1.5 * fontsize);
+ ps_font(&out, Fonts::Helvetica, 1.5 * fontsize);
ps_translate(&out, xc, yc);
ps_color(&out, 0, 0, 0);
if (title)
{
ps_ctext(&out, 0, -fontsize * 1.5 / 2.0, title, eXCenter);
}
- ps_font(&out, efontHELV, fontsize);
+ ps_font(&out, Fonts::Helvetica, fontsize);
ps_rotate(&out, rot0);
for (i = 0; (i < nres);)
if (impl_->bStartTimeSet_)
{
- setTimeValue(TBEGIN, impl_->startTime_);
+ setTimeValue(TimeControl::Begin, impl_->startTime_);
}
if (impl_->bEndTimeSet_)
{
- setTimeValue(TEND, impl_->endTime_);
+ setTimeValue(TimeControl::End, impl_->endTime_);
}
if (impl_->bDeltaTimeSet_)
{
- setTimeValue(TDELTA, impl_->deltaTime_);
+ setTimeValue(TimeControl::Delta, impl_->deltaTime_);
}
}