From 631820b9cfa30eb98c64f5a61d1adf7caf4e4b28 Mon Sep 17 00:00:00 2001 From: Artem Zhmurov Date: Fri, 23 Apr 2021 10:13:49 +0000 Subject: [PATCH] Apply clang-11 fixes for fileio --- src/gromacs/commandline/pargs.cpp | 8 +- src/gromacs/fileio/checkpoint.h | 4 +- src/gromacs/fileio/confio.cpp | 2 +- src/gromacs/fileio/enxio.cpp | 1 + src/gromacs/fileio/enxio.h | 1 + src/gromacs/fileio/gmxfio.cpp | 2 + src/gromacs/fileio/gmxfio_xdr.cpp | 168 +++++++++--------- src/gromacs/fileio/readinp.cpp | 2 +- src/gromacs/fileio/tests/.clang-tidy | 91 ++++++++++ src/gromacs/fileio/tests/filemd5.cpp | 4 +- src/gromacs/fileio/tests/xvgio.cpp | 4 +- src/gromacs/fileio/timecontrol.cpp | 25 +-- src/gromacs/fileio/timecontrol.h | 18 +- src/gromacs/fileio/tpxio.cpp | 8 +- src/gromacs/fileio/trxio.cpp | 43 ++--- src/gromacs/fileio/warninp.cpp | 6 +- src/gromacs/fileio/warninp.h | 10 +- src/gromacs/fileio/writeps.cpp | 27 +-- src/gromacs/fileio/writeps.h | 34 ++-- src/gromacs/fileio/xvgr.cpp | 7 +- src/gromacs/gmxana/gmx_wheel.cpp | 10 +- .../trajectoryanalysis/runnercommon.cpp | 6 +- 22 files changed, 296 insertions(+), 185 deletions(-) create mode 100644 src/gromacs/fileio/tests/.clang-tidy diff --git a/src/gromacs/commandline/pargs.cpp b/src/gromacs/commandline/pargs.cpp index 079e9bb70f..c027dba96a 100644 --- a/src/gromacs/commandline/pargs.cpp +++ b/src/gromacs/commandline/pargs.cpp @@ -4,7 +4,7 @@ * 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. @@ -566,15 +566,15 @@ gmx_bool parse_common_args(int* argc, /* 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(); diff --git a/src/gromacs/fileio/checkpoint.h b/src/gromacs/fileio/checkpoint.h index f2c35b8c53..c6a996ac16 100644 --- a/src/gromacs/fileio/checkpoint.h +++ b/src/gromacs/fileio/checkpoint.h @@ -36,8 +36,8 @@ * 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 diff --git a/src/gromacs/fileio/confio.cpp b/src/gromacs/fileio/confio.cpp index 6af30e2a01..5e68256a82 100644 --- a/src/gromacs/fileio/confio.cpp +++ b/src/gromacs/fileio/confio.cpp @@ -268,7 +268,7 @@ void ChainIdFiller::fill(t_atoms* atoms, const int startAtomIndex, const int end { // 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 */ diff --git a/src/gromacs/fileio/enxio.cpp b/src/gromacs/fileio/enxio.cpp index ce94d52fed..1903e26346 100644 --- a/src/gromacs/fileio/enxio.cpp +++ b/src/gromacs/fileio/enxio.cpp @@ -67,6 +67,7 @@ /* 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)", diff --git a/src/gromacs/fileio/enxio.h b/src/gromacs/fileio/enxio.h index 77ae446cd7..741d12a8ee 100644 --- a/src/gromacs/fileio/enxio.h +++ b/src/gromacs/fileio/enxio.h @@ -95,6 +95,7 @@ enum }; /* names for the above enum */ +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) extern const char* enx_block_id_name[]; diff --git a/src/gromacs/fileio/gmxfio.cpp b/src/gromacs/fileio/gmxfio.cpp index 013b8472e5..fad104947f 100644 --- a/src/gromacs/fileio/gmxfio.cpp +++ b/src/gromacs/fileio/gmxfio.cpp @@ -70,6 +70,7 @@ /* 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; @@ -82,6 +83,7 @@ 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; diff --git a/src/gromacs/fileio/gmxfio_xdr.cpp b/src/gromacs/fileio/gmxfio_xdr.cpp index 45c9bbe4ef..f2376562f3 100644 --- a/src/gromacs/fileio/gmxfio_xdr.cpp +++ b/src/gromacs/fileio/gmxfio_xdr.cpp @@ -4,7 +4,7 @@ * 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. @@ -47,6 +47,7 @@ #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" @@ -54,30 +55,35 @@ #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 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) { @@ -106,41 +112,41 @@ XDR* gmx_fio_getxdr(t_fileio* fio) } /* 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(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; @@ -159,7 +165,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, gmx_fio_check_nitem(eio, nitem, srcfile, line); switch (eio) { - case eioREAL: + case IOType::REAL: if (fio->bDouble) { if (item && !fio->bRead) @@ -185,7 +191,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, } } break; - case eioFLOAT: + case IOType::FLOAT: if (item && !fio->bRead) { f = *(static_cast(item)); @@ -196,7 +202,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, *(static_cast(item)) = f; } break; - case eioDOUBLE: + case IOType::DOUBLE: if (item && !fio->bRead) { d = *(static_cast(item)); @@ -207,7 +213,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, *(static_cast(item)) = d; } break; - case eioINT: + case IOType::INT: if (item && !fio->bRead) { idum = *static_cast(item); @@ -218,7 +224,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, *static_cast(item) = idum; } break; - case eioINT32: + case IOType::INT32: if (item && !fio->bRead) { s32dum = *static_cast(item); @@ -229,7 +235,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, *static_cast(item) = s32dum; } break; - case eioINT64: + case IOType::INT64: if (item && !fio->bRead) { s64dum = *static_cast(item); @@ -240,7 +246,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, *static_cast(item) = s64dum; } break; - case eioUCHAR: + case IOType::UCHAR: if (item && !fio->bRead) { ucdum = *static_cast(item); @@ -251,7 +257,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, *static_cast(item) = ucdum; } break; - case eioCHAR: + case IOType::CHAR: if (item && !fio->bRead) { cdum = *static_cast(item); @@ -262,7 +268,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, *static_cast(item) = cdum; } break; - case eioNCHAR: + case IOType::NCHAR: cptr = static_cast(item); GMX_RELEASE_ASSERT(nitem < static_cast(std::numeric_limits::max()), "The XDR interface cannot handle array lengths > 2^31"); @@ -272,7 +278,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, static_cast(sizeof(char)), reinterpret_cast(xdr_char)); break; - case eioNUCHAR: + case IOType::NUCHAR: ucptr = static_cast(item); GMX_RELEASE_ASSERT(nitem < static_cast(std::numeric_limits::max()), "The XDR interface cannot handle array lengths > 2^31"); @@ -282,7 +288,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, static_cast(sizeof(unsigned char)), reinterpret_cast(xdr_u_char)); break; - case eioUSHORT: + case IOType::USHORT: if (item && !fio->bRead) { us = *static_cast(item); @@ -293,7 +299,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, *static_cast(item) = us; } break; - case eioRVEC: + case IOType::RVEC: if (fio->bDouble) { if (item && !fio->bRead) @@ -339,7 +345,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, } } break; - case eioNRVEC: + case IOType::NRVEC: ptr = nullptr; res = 1; for (std::size_t j = 0; j < nitem && res; j++) @@ -348,10 +354,10 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, { ptr = (static_cast(item))[j]; } - res = static_cast(do_xdr(fio, ptr, 1, eioRVEC, desc, srcfile, line)); + res = static_cast(do_xdr(fio, ptr, 1, IOType::RVEC, desc, srcfile, line)); } break; - case eioIVEC: + case IOType::IVEC: iptr = static_cast(item); res = 1; for (m = 0; (m < DIM) && res; m++) @@ -367,7 +373,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, } } break; - case eioSTRING: + case IOType::STRING: { char* cptr; int slen; @@ -420,7 +426,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc, } break; } - case eioOPAQUE: + case IOType::OPAQUE: { if (item == nullptr && nitem > 0) { @@ -469,7 +475,7 @@ gmx_bool gmx_fio_writee_string(t_fileio* fio, const char* item, const char* desc gmx_bool ret; void* it = const_cast(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; } @@ -478,7 +484,7 @@ gmx_bool gmx_fio_doe_real(t_fileio* fio, real* item, const char* desc, const cha { 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; } @@ -487,7 +493,7 @@ gmx_bool gmx_fio_doe_float(t_fileio* fio, float* item, const char* desc, const c { 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; } @@ -496,7 +502,7 @@ gmx_bool gmx_fio_doe_double(t_fileio* fio, double* item, const char* desc, const { 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; } @@ -510,13 +516,13 @@ gmx_bool gmx_fio_doe_gmx_bool(t_fileio* fio, gmx_bool* item, const char* desc, c 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(*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; @@ -526,7 +532,7 @@ gmx_bool gmx_fio_doe_int(t_fileio* fio, int* item, const char* desc, const char* { 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; } @@ -535,7 +541,7 @@ gmx_bool gmx_fio_doe_int32(t_fileio* fio, int32_t* item, const char* desc, const { 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; } @@ -544,7 +550,7 @@ gmx_bool gmx_fio_doe_int64(t_fileio* fio, int64_t* item, const char* desc, const { 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; } @@ -553,7 +559,7 @@ gmx_bool gmx_fio_doe_uchar(t_fileio* fio, unsigned char* item, const char* desc, { 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; } @@ -562,7 +568,7 @@ gmx_bool gmx_fio_doe_char(t_fileio* fio, char* item, const char* desc, const cha { 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; } @@ -571,7 +577,7 @@ gmx_bool gmx_fio_doe_ushort(t_fileio* fio, unsigned short* item, const char* des { 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; } @@ -580,7 +586,7 @@ gmx_bool gmx_fio_doe_rvec(t_fileio* fio, rvec* item, const char* desc, const cha { 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; } @@ -589,7 +595,7 @@ gmx_bool gmx_fio_doe_ivec(t_fileio* fio, ivec* item, const char* desc, const cha { 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; } @@ -598,7 +604,7 @@ gmx_bool gmx_fio_doe_string(t_fileio* fio, char* item, const char* desc, const c { 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; } @@ -607,7 +613,7 @@ gmx_bool gmx_fio_doe_opaque(t_fileio* fio, char* data, std::size_t size, const c { 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; } @@ -621,7 +627,7 @@ gmx_bool gmx_fio_ndoe_real(t_fileio* fio, real* item, int n, const char* desc, c 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; @@ -635,7 +641,7 @@ gmx_bool gmx_fio_ndoe_float(t_fileio* fio, float* item, int n, const char* desc, 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; @@ -649,7 +655,7 @@ gmx_bool gmx_fio_ndoe_double(t_fileio* fio, double* item, int n, const char* des 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; @@ -667,13 +673,13 @@ gmx_bool gmx_fio_ndoe_gmx_bool(t_fileio* fio, gmx_bool* item, int n, const char* 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(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); @@ -687,7 +693,7 @@ gmx_bool gmx_fio_ndoe_int(t_fileio* fio, int* item, int n, const char* desc, con 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; @@ -701,7 +707,7 @@ gmx_bool gmx_fio_ndoe_int64(t_fileio* fio, int64_t* item, int n, const char* des 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; @@ -712,7 +718,7 @@ gmx_bool gmx_fio_ndoe_uchar(t_fileio* fio, unsigned char* item, int n, const cha { 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; } @@ -721,7 +727,7 @@ gmx_bool gmx_fio_ndoe_char(t_fileio* fio, char* item, int n, const char* desc, c { 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; } @@ -734,7 +740,7 @@ gmx_bool gmx_fio_ndoe_ushort(t_fileio* fio, unsigned short* item, int n, const c 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; @@ -745,7 +751,7 @@ gmx_bool gmx_fio_ndoe_rvec(t_fileio* fio, rvec* item, int n, const char* desc, c { 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; } @@ -758,7 +764,7 @@ gmx_bool gmx_fio_ndoe_ivec(t_fileio* fio, ivec* item, int n, const char* desc, c 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; @@ -772,7 +778,7 @@ gmx_bool gmx_fio_ndoe_string(t_fileio* fio, char* item[], int n, const char* des 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; diff --git a/src/gromacs/fileio/readinp.cpp b/src/gromacs/fileio/readinp.cpp index d9d30ba8b3..09076b74a3 100644 --- a/src/gromacs/fileio/readinp.cpp +++ b/src/gromacs/fileio/readinp.cpp @@ -161,7 +161,7 @@ gmx::KeyValueTreeObject flatKeyValueTreeFromInpFile(gmx::ArrayRef(local.name_, !local.value_.empty() ? local.value_ : ""); } diff --git a/src/gromacs/fileio/tests/.clang-tidy b/src/gromacs/fileio/tests/.clang-tidy new file mode 100644 index 0000000000..0adf51e3ee --- /dev/null +++ b/src/gromacs/fileio/tests/.clang-tidy @@ -0,0 +1,91 @@ +# 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 diff --git a/src/gromacs/fileio/tests/filemd5.cpp b/src/gromacs/fileio/tests/filemd5.cpp index 8c6042eee2..841fe4c5c4 100644 --- a/src/gromacs/fileio/tests/filemd5.cpp +++ b/src/gromacs/fileio/tests/filemd5.cpp @@ -1,7 +1,7 @@ /* * 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. @@ -67,7 +67,7 @@ namespace class FileMD5Test : public ::testing::Test { public: - void prepareFile(int lengthInBytes) + void prepareFile(int lengthInBytes) const { // Fill some memory with some arbitrary bits. std::vector data(lengthInBytes); diff --git a/src/gromacs/fileio/tests/xvgio.cpp b/src/gromacs/fileio/tests/xvgio.cpp index 20d82b537c..f40afab03d 100644 --- a/src/gromacs/fileio/tests/xvgio.cpp +++ b/src/gromacs/fileio/tests/xvgio.cpp @@ -1,7 +1,7 @@ /* * 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. @@ -67,7 +67,7 @@ public: void useStringAsXvgFile(const std::string& xvgString) { referenceContents_ = xvgString; } - void writeXvgFile() + void writeXvgFile() const { gmx::TextWriter::writeFileFromString(referenceFilename(), referenceContents()); } diff --git a/src/gromacs/fileio/timecontrol.cpp b/src/gromacs/fileio/timecontrol.cpp index fb3c2d050f..4ee04f8942 100644 --- a/src/gromacs/fileio/timecontrol.cpp +++ b/src/gromacs/fileio/timecontrol.cpp @@ -36,6 +36,7 @@ */ #include "gmxpre.h" +#include "gromacs/utility/enumerationhelpers.h" #include "timecontrol.h" #include @@ -48,41 +49,43 @@ 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(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 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 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 lock(g_timeControlMutex); - range_check(tcontrol, 0, TNR); timecontrol[tcontrol].t = value; timecontrol[tcontrol].bSet = TRUE; } diff --git a/src/gromacs/fileio/timecontrol.h b/src/gromacs/fileio/timecontrol.h index 52f7b37cee..651cfbf1b9 100644 --- a/src/gromacs/fileio/timecontrol.h +++ b/src/gromacs/fileio/timecontrol.h @@ -1,7 +1,7 @@ /* * 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. @@ -41,18 +41,18 @@ /* 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 diff --git a/src/gromacs/fileio/tpxio.cpp b/src/gromacs/fileio/tpxio.cpp index d3dde6a338..6109039cd5 100644 --- a/src/gromacs/fileio/tpxio.cpp +++ b/src/gromacs/fileio/tpxio.cpp @@ -95,7 +95,7 @@ * 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 @@ -2719,7 +2719,7 @@ static void do_tpxheader(gmx::FileIOXdrSerializer* serializer, serializer->doString(&buf); gmx_fio_setprecision(fio, tpx->isDouble); serializer->doInt(&precision); - fileTag = gmx::formatString("%s", tpx_tag); + fileTag = tpx_tag; } /* Check versions! */ @@ -2751,7 +2751,7 @@ static void do_tpxheader(gmx::FileIOXdrSerializer* serializer, 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. @@ -2765,7 +2765,7 @@ static void do_tpxheader(gmx::FileIOXdrSerializer* serializer, tpx->fileVersion, fileTag.c_str(), tpx_version, - tpx_tag); + tpx_tag.c_str()); } } } diff --git a/src/gromacs/fileio/trxio.cpp b/src/gromacs/fileio/trxio.cpp index 697fbb0727..e731f42771 100644 --- a/src/gromacs/fileio/trxio.cpp +++ b/src/gromacs/fileio/trxio.cpp @@ -4,7 +4,7 @@ * 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. @@ -83,7 +83,7 @@ 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 */ @@ -124,9 +124,10 @@ int check_times2(real t, real t0, gmx_bool bDouble) #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; } @@ -135,7 +136,7 @@ int check_times2(real t, real t0, gmx_bool bDouble) r = 0; } } - else if (bTimeSet(TEND) && (t >= rTimeValue(TEND))) + else if (bTimeSet(TimeControl::End) && (t >= rTimeValue(TimeControl::End))) { r = 1; } @@ -145,9 +146,9 @@ int check_times2(real t, real t0, gmx_bool bDouble) "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; @@ -160,7 +161,7 @@ int check_times(real t) static void initcount(t_trxstatus* status) { - status->__frame = -1; + status->currentFrame = -1; } static void status_init(t_trxstatus* status) @@ -168,7 +169,7 @@ 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; @@ -178,24 +179,24 @@ static void status_init(t_trxstatus* status) 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); } @@ -210,11 +211,11 @@ static void printincomp(t_trxstatus* status, t_trxframe* fr) { 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); } @@ -843,14 +844,14 @@ bool read_next_frame(const gmx_output_env_t* oenv, t_trxstatus* status, t_trxfra 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); } diff --git a/src/gromacs/fileio/warninp.cpp b/src/gromacs/fileio/warninp.cpp index cee3526950..43d481eac2 100644 --- a/src/gromacs/fileio/warninp.cpp +++ b/src/gromacs/fileio/warninp.cpp @@ -4,7 +4,7 @@ * 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. @@ -249,7 +249,7 @@ void free_warning(warninp_t wi) 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]; @@ -257,7 +257,7 @@ void _too_few(warninp_t wi, const char* fn, int line) 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]; diff --git a/src/gromacs/fileio/warninp.h b/src/gromacs/fileio/warninp.h index 7d21c03d52..15b71f0b03 100644 --- a/src/gromacs/fileio/warninp.h +++ b/src/gromacs/fileio/warninp.h @@ -4,7 +4,7 @@ * 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. @@ -131,12 +131,12 @@ void done_warning(warninp_t wi, int f_errno, const char* file, int line); 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 diff --git a/src/gromacs/fileio/writeps.cpp b/src/gromacs/fileio/writeps.cpp index 2caf643e49..85de599702 100644 --- a/src/gromacs/fileio/writeps.cpp +++ b/src/gromacs/fileio/writeps.cpp @@ -4,7 +4,7 @@ * 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. @@ -40,16 +40,21 @@ #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 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) { @@ -251,15 +256,15 @@ void ps_circle(t_psdata* ps, real x1, real y1, real rad) 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(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); } diff --git a/src/gromacs/fileio/writeps.h b/src/gromacs/fileio/writeps.h index d6449e9adc..d0518b6196 100644 --- a/src/gromacs/fileio/writeps.h +++ b/src/gromacs/fileio/writeps.h @@ -3,7 +3,7 @@ * * 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. @@ -63,21 +63,21 @@ typedef enum 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 }; @@ -91,7 +91,7 @@ struct t_psdata }; -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); @@ -122,7 +122,7 @@ void ps_fillarcslice(t_psdata* ps, real xc, real yc, real rad1, real rad2, real 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); diff --git a/src/gromacs/fileio/xvgr.cpp b/src/gromacs/fileio/xvgr.cpp index b1504c4008..2cafa953cb 100644 --- a/src/gromacs/fileio/xvgr.cpp +++ b/src/gromacs/fileio/xvgr.cpp @@ -4,7 +4,7 @@ * 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. @@ -39,6 +39,7 @@ #include "xvgr.h" +#include #include #include #include @@ -418,8 +419,8 @@ void xvgr_line_props(FILE* out, int NrSet, int LineStyle, int LineColor, const g } } -static const char* LocTypeStr[] = { "view", "world" }; -static const char* BoxFillStr[] = { "none", "color", "pattern" }; +static constexpr std::array LocTypeStr = { "view", "world" }; +static constexpr std::array BoxFillStr = { "none", "color", "pattern" }; void xvgr_box(FILE* out, int LocType, diff --git a/src/gromacs/gmxana/gmx_wheel.cpp b/src/gromacs/gmxana/gmx_wheel.cpp index dbb5514dd0..cc566007aa 100644 --- a/src/gromacs/gmxana/gmx_wheel.cpp +++ b/src/gromacs/gmxana/gmx_wheel.cpp @@ -4,7 +4,7 @@ * 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. @@ -121,13 +121,13 @@ static void wheel(const char* fn, int nres, char* resnm[], int r0, real rot0, ch 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);) { @@ -179,14 +179,14 @@ static void wheel2(const char* fn, int nres, char* resnm[], real rot0, char* tit 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);) diff --git a/src/gromacs/trajectoryanalysis/runnercommon.cpp b/src/gromacs/trajectoryanalysis/runnercommon.cpp index 55419eb7f9..04201be572 100644 --- a/src/gromacs/trajectoryanalysis/runnercommon.cpp +++ b/src/gromacs/trajectoryanalysis/runnercommon.cpp @@ -406,15 +406,15 @@ void TrajectoryAnalysisRunnerCommon::optionsFinished() 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_); } } -- 2.22.0