Apply clang-11 fixes for fileio
authorArtem Zhmurov <zhmurov@gmail.com>
Fri, 23 Apr 2021 10:13:49 +0000 (10:13 +0000)
committerAndrey Alekseenko <al42and@gmail.com>
Fri, 23 Apr 2021 10:13:49 +0000 (10:13 +0000)
22 files changed:
src/gromacs/commandline/pargs.cpp
src/gromacs/fileio/checkpoint.h
src/gromacs/fileio/confio.cpp
src/gromacs/fileio/enxio.cpp
src/gromacs/fileio/enxio.h
src/gromacs/fileio/gmxfio.cpp
src/gromacs/fileio/gmxfio_xdr.cpp
src/gromacs/fileio/readinp.cpp
src/gromacs/fileio/tests/.clang-tidy [new file with mode: 0644]
src/gromacs/fileio/tests/filemd5.cpp
src/gromacs/fileio/tests/xvgio.cpp
src/gromacs/fileio/timecontrol.cpp
src/gromacs/fileio/timecontrol.h
src/gromacs/fileio/tpxio.cpp
src/gromacs/fileio/trxio.cpp
src/gromacs/fileio/warninp.cpp
src/gromacs/fileio/warninp.h
src/gromacs/fileio/writeps.cpp
src/gromacs/fileio/writeps.h
src/gromacs/fileio/xvgr.cpp
src/gromacs/gmxana/gmx_wheel.cpp
src/gromacs/trajectoryanalysis/runnercommon.cpp

index 079e9bb70f92de5d5d4992eaf35c3f21818a3714..c027dba96aa5260d66fbfb620faa4dea2a001cf7 100644 (file)
@@ -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();
index f2c35b8c5365405a38da7b61e77a9f21012261b7..c6a996ac16e4a8e1c46a73020dd3f3e4d9962455 100644 (file)
@@ -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 <cstdio>
 
index 6af30e2a01c4814fa835719a87072e2db7a7aa72..5e68256a82bc727f4615a690b3f917fe40a55c4b 100644 (file)
@@ -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 */
index ce94d52fed3e05a404dd3a2718840b02a92c68d4..1903e26346fa8c03fbfa5ea74f01a2f81ffdf196 100644 (file)
@@ -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)",
index 77ae446cd7b98107040d73663a7df5a4d7288e7e..741d12a8eee01159af4412d17c977d63eaa1ed22 100644 (file)
@@ -95,6 +95,7 @@ enum
 };
 
 /* names for the above enum */
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
 extern const char* enx_block_id_name[];
 
 
index 013b8472e550a99a4069b935b58759888d316da9..fad104947fd7f42b27242955a8e3f6f85730440e 100644 (file)
@@ -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<std::mutex>;
index 45c9bbe4efe6c0aaef697b329f60267303853fdb..f2376562f3a8a0cfaae5668bed1458fc0be77f79 100644 (file)
@@ -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"
 #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)
 {
@@ -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<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;
@@ -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<float*>(item));
@@ -196,7 +202,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc,
                 *(static_cast<float*>(item)) = f;
             }
             break;
-        case eioDOUBLE:
+        case IOType::DOUBLE:
             if (item && !fio->bRead)
             {
                 d = *(static_cast<double*>(item));
@@ -207,7 +213,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc,
                 *(static_cast<double*>(item)) = d;
             }
             break;
-        case eioINT:
+        case IOType::INT:
             if (item && !fio->bRead)
             {
                 idum = *static_cast<int*>(item);
@@ -218,7 +224,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc,
                 *static_cast<int*>(item) = idum;
             }
             break;
-        case eioINT32:
+        case IOType::INT32:
             if (item && !fio->bRead)
             {
                 s32dum = *static_cast<int32_t*>(item);
@@ -229,7 +235,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc,
                 *static_cast<int32_t*>(item) = s32dum;
             }
             break;
-        case eioINT64:
+        case IOType::INT64:
             if (item && !fio->bRead)
             {
                 s64dum = *static_cast<int64_t*>(item);
@@ -240,7 +246,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc,
                 *static_cast<int64_t*>(item) = s64dum;
             }
             break;
-        case eioUCHAR:
+        case IOType::UCHAR:
             if (item && !fio->bRead)
             {
                 ucdum = *static_cast<unsigned char*>(item);
@@ -251,7 +257,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc,
                 *static_cast<unsigned char*>(item) = ucdum;
             }
             break;
-        case eioCHAR:
+        case IOType::CHAR:
             if (item && !fio->bRead)
             {
                 cdum = *static_cast<char*>(item);
@@ -262,7 +268,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc,
                 *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");
@@ -272,7 +278,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc,
                              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");
@@ -282,7 +288,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc,
                              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);
@@ -293,7 +299,7 @@ do_xdr(t_fileio* fio, void* item, std::size_t nitem, int eio, const char* desc,
                 *static_cast<unsigned short*>(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<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++)
@@ -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<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;
 }
@@ -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<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;
@@ -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<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);
@@ -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;
index d9d30ba8b394ac2bcb011f7ed9a4a01b22a6c631..09076b74a30a7c18d0730e73bb53c7a3450f3af7 100644 (file)
@@ -161,7 +161,7 @@ gmx::KeyValueTreeObject flatKeyValueTreeFromInpFile(gmx::ArrayRef<const t_inpfil
 {
     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_ : "");
     }
diff --git a/src/gromacs/fileio/tests/.clang-tidy b/src/gromacs/fileio/tests/.clang-tidy
new file mode 100644 (file)
index 0000000..0adf51e
--- /dev/null
@@ -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
index 8c6042eee249229a5e8f09d29cfc31a141208c5c..841fe4c5c4addc05fc70c971a093fa8ef3492c1e 100644 (file)
@@ -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<char> data(lengthInBytes);
index 20d82b537c5f80fd4ace34a4a7e6e0c6413d738f..f40afab03de25e938c79f8903f3cef5a84fa92e3 100644 (file)
@@ -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());
     }
index fb3c2d050fafd56931fb0a6a0a4781fa850f5c9e..4ee04f8942af30579eac3ac390c488454b27479c 100644 (file)
@@ -36,6 +36,7 @@
  */
 #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;
 }
index 52f7b37ceedb5f54753bd1783d805501469882d1..651cfbf1b979da27388953e9af50ffb1e284383b 100644 (file)
@@ -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.
 /* 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
index d3dde6a33895f66c75724fc9af77a7a239f8e33a..6109039cd599fde116a70ec26723b7b2858be90f 100644 (file)
@@ -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());
             }
         }
     }
index 697fbb0727c2df4ecf9a66530438d0086d61156e..e731f427718f85868ce62697acd0fc9567b0e078 100644 (file)
@@ -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);
                 }
index cee3526950991014152ba303697b0dec4030fc34..43d481eac258a0b07ff5b375cbe3588a1da800ec 100644 (file)
@@ -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];
 
index 7d21c03d5214725c8c4fe71d5d1f137ca01add28..15b71f0b0372a6540f92402771b1b48e53c8feb0 100644 (file)
@@ -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
index 2caf643e4945f29bda108d49d7dee0823f03ee5d..85de599702dde5d0bde5f448f8607114d590980a 100644 (file)
@@ -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.
 #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)
 {
@@ -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<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);
 }
 
index d6449e9adcda406bc46f2ffe5d1ea0c177856c05..d0518b6196833bfb65769da0eb186acaf23c34ab 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 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);
index b1504c4008a3a8ce27721e753b976915ffd17154..2cafa953cb2f93c39fa2da22c8a646dfccb20c6d 100644 (file)
@@ -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 <array>
 #include <cassert>
 #include <cctype>
 #include <cstring>
@@ -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<const char*, 2> LocTypeStr = { "view", "world" };
+static constexpr std::array<const char*, 3> BoxFillStr = { "none", "color", "pattern" };
 
 void xvgr_box(FILE*                   out,
               int                     LocType,
index dbb5514dd03df56fca5ad6b5d135e02e369dac08..cc566007aa41393d48c3afa466fd4228d6ae717e 100644 (file)
@@ -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);)
index 55419eb7f93a62a5ead2d5e378bc12f3d992d951..04201be572c85c48b3ce171c19050e5d11cc1cc3 100644 (file)
@@ -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_);
     }
 }