Convert gmx_ffparams_t to C++
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / convparm.cpp
index a5f3f05ccc035a20259e08388cf4d9ebb0f19a93..91fd43c7ee732774b3c8d7985ad5e47b1b797e5b 100644 (file)
@@ -460,7 +460,7 @@ static int enter_params(gmx_ffparams_t *ffparams, t_functype ftype,
 
     if (!bAppend)
     {
-        for (type = start; (type < ffparams->ntypes); type++)
+        for (type = start; (type < ffparams->numTypes()); type++)
         {
             if (ffparams->functype[type] == ftype)
             {
@@ -473,12 +473,14 @@ static int enter_params(gmx_ffparams_t *ffparams, t_functype ftype,
     }
     else
     {
-        type = ffparams->ntypes;
+        type = ffparams->numTypes();
     }
-    memcpy(&ffparams->iparams[type], &newparam, static_cast<size_t>(sizeof(newparam)));
 
-    ffparams->ntypes++;
-    ffparams->functype[type] = ftype;
+    ffparams->iparams.push_back(newparam);
+    ffparams->functype.push_back(ftype);
+
+    GMX_ASSERT(ffparams->iparams.size() == ffparams->functype.size(),
+               "sizes should match");
 
     return type;
 }
@@ -495,22 +497,15 @@ static void append_interaction(InteractionList *ilist,
 
 static void enter_function(t_params *p, t_functype ftype, int comb, real reppow,
                            gmx_ffparams_t *ffparams, InteractionList *il,
-                           int *maxtypes,
                            bool bNB, bool bAppend)
 {
     int     k, type, nr, nral, start;
 
-    start = ffparams->ntypes;
+    start = ffparams->numTypes();
     nr    = p->nr;
 
     for (k = 0; k < nr; k++)
     {
-        if (*maxtypes <= ffparams->ntypes)
-        {
-            *maxtypes += 1000;
-            srenew(ffparams->functype, *maxtypes);
-            srenew(ffparams->iparams, *maxtypes);
-        }
         type = enter_params(ffparams, ftype, p->param[k].c, comb, reppow, start, bAppend);
         /* Type==-1 is used as a signal that this interaction is all-zero and should not be added. */
         if (!bNB && type >= 0)
@@ -527,25 +522,22 @@ void convert_params(int atnr, t_params nbtypes[],
                     int comb, double reppow, real fudgeQQ,
                     gmx_mtop_t *mtop)
 {
-    int             i, maxtypes;
+    int             i;
     unsigned long   flags;
     gmx_ffparams_t *ffp;
     gmx_moltype_t  *molt;
     t_params       *plist;
 
-    maxtypes = 0;
-
     ffp           = &mtop->ffparams;
-    ffp->ntypes   = 0;
     ffp->atnr     = atnr;
-    ffp->functype = nullptr;
-    ffp->iparams  = nullptr;
+    ffp->functype.clear();
+    ffp->iparams.clear();
     ffp->reppow   = reppow;
 
     enter_function(&(nbtypes[F_LJ]),  static_cast<t_functype>(F_LJ),    comb, reppow, ffp, nullptr,
-                   &maxtypes, TRUE, TRUE);
+                   TRUE, TRUE);
     enter_function(&(nbtypes[F_BHAM]), static_cast<t_functype>(F_BHAM),  comb, reppow, ffp, nullptr,
-                   &maxtypes, TRUE, TRUE);
+                   TRUE, TRUE);
 
     for (size_t mt = 0; mt < mtop->moltype.size(); mt++)
     {
@@ -563,7 +555,7 @@ void convert_params(int atnr, t_params nbtypes[],
             {
                 enter_function(&(plist[i]), static_cast<t_functype>(i), comb, reppow,
                                ffp, &molt->ilist[i],
-                               &maxtypes, FALSE, (i == F_POSRES  || i == F_FBPOSRES));
+                               FALSE, (i == F_POSRES  || i == F_FBPOSRES));
             }
         }
     }
@@ -604,7 +596,7 @@ void convert_params(int atnr, t_params nbtypes[],
                 {
                     enter_function(&(plist[i]), static_cast<t_functype>(i), comb, reppow,
                                    ffp, &(*mtop->intermolecular_ilist)[i],
-                                   &maxtypes, FALSE, FALSE);
+                                   FALSE, FALSE);
 
                     mtop->bIntermolecularInteractions = TRUE;
                 }