* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2011,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 "gromacs/utility/smalloc.h"
#include "gromacs/utility/stringcompare.h"
-/* these MUST correspond to the enum in hackblock.h */
-const char* btsNames[ebtsNR] = { "bonds", "angles", "dihedrals", "impropers", "exclusions", "cmap" };
-const int btsNiatoms[ebtsNR] = { 2, 3, 4, 4, 2, 5 };
+const char* enumValueToString(BondedTypes enumValue)
+{
+ /* these MUST correspond to the enum in hackblock.h */
+ constexpr gmx::EnumerationArray<BondedTypes, const char*> bondedTypeNames = {
+ "bonds", "angles", "dihedrals", "impropers", "exclusions", "cmap"
+ };
+ return bondedTypeNames[enumValue];
+}
+
+int enumValueToNumIAtoms(BondedTypes enumValue)
+{
+ constexpr gmx::EnumerationArray<BondedTypes, int> bondedTypeIAtoms = { 2, 3, 4, 4, 2, 5 };
+ return bondedTypeIAtoms[enumValue];
+}
MoleculePatchType MoleculePatch::type() const
{
{
globalPatches->name.clear();
globalPatches->hack.clear();
- for (int i = 0; i < ebtsNR; i++)
+ for (auto bondedsList : globalPatches->rb)
{
- globalPatches->rb[i].b.clear();
+ bondedsList.b.clear();
}
}
bool bPlus)
{
bool bBondsRemoved = false;
- for (int i = 0; i < ebtsNR; i++)
+ for (auto i : gmx::EnumerationWrapper<BondedTypes>{})
{
- if (!s[i].b.empty())
+ int value = static_cast<int>(i);
+ if (!s[value].b.empty())
{
/* Record how many bonds we have in the destination when we start.
*
* it is a hackblock entry meant to override the main rtp, and then
* we don't add the main rtp one.
*/
- int nbHackblockStart = d[i].b.size();
+ int nbHackblockStart = d[value].b.size();
- for (const auto& b : s[i].b)
+ for (const auto& b : s[value].b)
{
/* Check if this bonded string already exists before adding.
* We are merging from the main RTP to the hackblocks, so this
* will mean the hackblocks overwrite the man RTP, as intended.
*/
- int index = rbonded_find_atoms_in_list(b, d[i].b, btsNiatoms[i]);
+ int index = rbonded_find_atoms_in_list(b, d[value].b, enumValueToNumIAtoms(i));
/* - If we did not find this interaction at all, the index will be -1,
* and then we should definitely add it to the merged hackblock and rtp.
*
{
if (!(bMin && contains_char(b, '-')) && !(bPlus && contains_char(b, '+')))
{
- d[i].b.push_back(b);
+ d[value].b.push_back(b);
}
- else if (i == ebtsBONDS)
+ else if (i == BondedTypes::Bonds)
{
bBondsRemoved = true;
}
{
d->cgnr.push_back(c);
}
- for (int i = 0; i < ebtsNR; i++)
+ for (auto i : gmx::EnumerationWrapper<BondedTypes>{})
{
d->rb[i].type = s.rb[i].type;
d->rb[i].b.clear();
*d = s;
d->name = s.name;
d->hack.clear();
- for (int i = 0; i < ebtsNR; i++)
+ for (auto bondedList : d->rb)
{
- d->rb[i].b.clear();
+ bondedList.b.clear();
}
mergeAtomAndBondModifications(s, d);
}