Merge "Merge release-5-0 into master"
authorDavid van der Spoel <spoel@xray.bmc.uu.se>
Sat, 7 Jun 2014 19:51:18 +0000 (21:51 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sat, 7 Jun 2014 19:51:18 +0000 (21:51 +0200)
129 files changed:
src/contrib/do_multiprot.c
src/contrib/do_shift.c
src/contrib/g_anavel.c
src/contrib/gmx_sdf.c
src/contrib/hexamer.c
src/gromacs/commandline/pargs.cpp
src/gromacs/commandline/tests/cmdlinehelpwriter.cpp
src/gromacs/commandline/tests/pargs.cpp
src/gromacs/fileio/filenm.c
src/gromacs/fileio/filenm.h
src/gromacs/fileio/pdbio.c
src/gromacs/gmxana/dlist.c
src/gromacs/gmxana/expfit.c
src/gromacs/gmxana/gmx_anaeig.c
src/gromacs/gmxana/gmx_angle.c
src/gromacs/gmxana/gmx_bundle.c
src/gromacs/gmxana/gmx_chi.c
src/gromacs/gmxana/gmx_cluster.c
src/gromacs/gmxana/gmx_clustsize.c
src/gromacs/gmxana/gmx_confrms.c
src/gromacs/gmxana/gmx_covar.c
src/gromacs/gmxana/gmx_current.c
src/gromacs/gmxana/gmx_density.c
src/gromacs/gmxana/gmx_densmap.c
src/gromacs/gmxana/gmx_densorder.cpp
src/gromacs/gmxana/gmx_dipoles.cpp
src/gromacs/gmxana/gmx_disre.c
src/gromacs/gmxana/gmx_do_dssp.c
src/gromacs/gmxana/gmx_dos.c
src/gromacs/gmxana/gmx_dyecoupl.c
src/gromacs/gmxana/gmx_dyndom.c
src/gromacs/gmxana/gmx_editconf.c
src/gromacs/gmxana/gmx_filter.c
src/gromacs/gmxana/gmx_genion.c
src/gromacs/gmxana/gmx_genpr.c
src/gromacs/gmxana/gmx_gyrate.c
src/gromacs/gmxana/gmx_h2order.c
src/gromacs/gmxana/gmx_hbond.c
src/gromacs/gmxana/gmx_helix.c
src/gromacs/gmxana/gmx_helixorient.c
src/gromacs/gmxana/gmx_hydorder.c
src/gromacs/gmxana/gmx_make_edi.c
src/gromacs/gmxana/gmx_make_ndx.c
src/gromacs/gmxana/gmx_mdmat.c
src/gromacs/gmxana/gmx_mindist.c
src/gromacs/gmxana/gmx_morph.c
src/gromacs/gmxana/gmx_msd.c
src/gromacs/gmxana/gmx_nmeig.c
src/gromacs/gmxana/gmx_nmens.c
src/gromacs/gmxana/gmx_nmtraj.c
src/gromacs/gmxana/gmx_order.c
src/gromacs/gmxana/gmx_polystat.c
src/gromacs/gmxana/gmx_potential.c
src/gromacs/gmxana/gmx_principal.c
src/gromacs/gmxana/gmx_rama.c
src/gromacs/gmxana/gmx_rdf.c
src/gromacs/gmxana/gmx_rms.c
src/gromacs/gmxana/gmx_rmsdist.c
src/gromacs/gmxana/gmx_rmsf.c
src/gromacs/gmxana/gmx_rotacf.c
src/gromacs/gmxana/gmx_rotmat.c
src/gromacs/gmxana/gmx_sans.c
src/gromacs/gmxana/gmx_sorient.c
src/gromacs/gmxana/gmx_spatial.c
src/gromacs/gmxana/gmx_spol.c
src/gromacs/gmxana/gmx_tcaf.c
src/gromacs/gmxana/gmx_traj.c
src/gromacs/gmxana/gmx_trjcat.c
src/gromacs/gmxana/gmx_trjconv.c
src/gromacs/gmxana/gmx_trjorder.c
src/gromacs/gmxana/gmx_vanhove.c
src/gromacs/gmxana/gmx_velacc.c
src/gromacs/gmxana/gmx_wheel.c
src/gromacs/gmxana/gstat.h
src/gromacs/gmxana/hxprops.c
src/gromacs/gmxana/nsfactor.h
src/gromacs/gmxana/sfactor.c
src/gromacs/gmxana/sfactor.h
src/gromacs/gmxpreprocess/gen_vsite.c
src/gromacs/gmxpreprocess/grompp.c
src/gromacs/gmxpreprocess/pdb2gmx.c
src/gromacs/gmxpreprocess/pdb2top.cpp
src/gromacs/gmxpreprocess/protonate.c
src/gromacs/gmxpreprocess/readir.c
src/gromacs/gmxpreprocess/readpull.c
src/gromacs/gmxpreprocess/vsite_parm.c
src/gromacs/gmxpreprocess/xlate.c
src/gromacs/gmxpreprocess/xlate.h
src/gromacs/options/abstractoption.h
src/gromacs/options/basicoptions.cpp
src/gromacs/options/basicoptions.h
src/gromacs/options/filenameoption.cpp
src/gromacs/options/filenameoption.h
src/gromacs/options/filenameoptionmanager.cpp
src/gromacs/options/filenameoptionmanager.h
src/gromacs/options/filenameoptionstorage.h
src/gromacs/options/optionmanagercontainer.h [new file with mode: 0644]
src/gromacs/options/options-impl.h
src/gromacs/options/options.cpp
src/gromacs/options/options.h
src/gromacs/options/tests/abstractoptionstorage.cpp
src/gromacs/options/tests/filenameoption.cpp
src/gromacs/options/tests/optionsassigner.cpp
src/gromacs/options/timeunitmanager.cpp
src/gromacs/options/timeunitmanager.h
src/gromacs/pulling/pull.c
src/gromacs/pulling/pullutil.c
src/gromacs/selection/indexutil.cpp
src/gromacs/selection/selectionfileoption.h
src/gromacs/selection/selectionfileoptionstorage.h
src/gromacs/selection/selectionoption.cpp
src/gromacs/selection/selectionoption.h
src/gromacs/selection/selectionoptionmanager.cpp
src/gromacs/selection/selectionoptionmanager.h
src/gromacs/selection/selectionoptionstorage.h
src/gromacs/selection/tests/selectionoption.cpp
src/gromacs/tools/check.c
src/gromacs/tools/convert_tpr.c
src/gromacs/topology/CMakeLists.txt
src/gromacs/topology/atomprop.cpp
src/gromacs/topology/index.cpp [moved from src/gromacs/gmxlib/index.c with 80% similarity]
src/gromacs/topology/index.h [moved from src/gromacs/legacyheaders/index.h with 79% similarity]
src/gromacs/topology/residuetypes.cpp [new file with mode: 0644]
src/gromacs/topology/residuetypes.h [new file with mode: 0644]
src/gromacs/trajectoryanalysis/cmdlinerunner.cpp
src/programs/mdrun/md.cpp
src/programs/mdrun/membed.c
src/programs/view/filter.cpp
tests/CppCheck.cmake

index f5647c5aadfb01167663461ff0bf1b88f9a74a0c..d7943a265957f0b58f6fe593240bb6f6055545ee 100644 (file)
@@ -47,7 +47,7 @@
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/fileio/xvgr.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gstat.h"
 #include "gromacs/fileio/tpxio.h"
 #include "viewit.h"
index c66a810c9d8e9b924e49d2d63311122839ea1f7a..fd20a5ada9c29ecd67821986cc96676e6d8eb13f 100644 (file)
@@ -48,7 +48,7 @@
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gstat.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/pdbio.h"
 
 void cat(FILE *out,char *fn,real t)
index 6cb062fe49d5f7a18b08cf70f5f3a38509bd0d82..96da5c85bb9f0e0437ac0afa585377eca967c6cb 100644 (file)
@@ -46,7 +46,6 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/futil.h"
 #include "copyrite.h"
-#include "index.h"
 #include "gromacs/fileio/tpxio.h"
 
 int main(int argc,char *argv[])
index 39cb0f554514a60ec600b3b12204e3394fba4761..9e003626bd754cc94a8ef0b6d6c2c7b39f18719e 100644 (file)
@@ -29,7 +29,7 @@
 #include "gromacs/utility/futil.h"
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/tpxio.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/utility/smalloc.h"
 #include "nrnb.h"
 #include "gstat.h"
index 22117c73a93836fd0d78fa4e011c004d64149124..bd477eb91b52e89ae0e954da4e6acd82facfa5ab 100644 (file)
@@ -46,7 +46,6 @@
 #include "macros.h"
 #include "copyrite.h"
 #include "gromacs/commandline/pargs.h"
-#include "index.h"
 #include "gromacs/math/vec.h"
 #include "typedefs.h"
 #include "gbutil.h"
index 6b240668b872dc400e2f4c509059399ba231c7ef..c5e2cd36647aeb9d9fe14a62946b4bc8ec50fbc8 100644 (file)
 #include <cstdlib>
 #include <cstring>
 
+#include <algorithm>
+#include <list>
+
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
 #include "thread_mpi/threads.h"
 
-#include "gromacs/legacyheaders/macros.h"
-
 #include "gromacs/commandline/cmdlinehelpcontext.h"
 #include "gromacs/commandline/cmdlinehelpwriter.h"
-#include "gromacs/commandline/shellcompletions.h"
+#include "gromacs/commandline/cmdlineparser.h"
 #include "gromacs/fileio/timecontrol.h"
 #include "gromacs/options/basicoptions.h"
 #include "gromacs/options/filenameoption.h"
+#include "gromacs/options/filenameoptionmanager.h"
 #include "gromacs/options/options.h"
+#include "gromacs/options/timeunitmanager.h"
 #include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/basenetwork.h"
+#include "gromacs/utility/common.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/fatalerror.h"
 /* The source code in this file should be thread-safe.
       Please keep it that way. */
 
-static void usage(const char *type, const char *arg)
-{
-    GMX_ASSERT(arg != NULL, "NULL command-line argument should not occur");
-    gmx_fatal(FARGS, "Expected %s argument for option %s\n", type, arg);
-}
-
-/* Scan an int for argument argv[*i] from argument at argv[*i + 1].
- * eg: -p 32.  argv[*i] is only used for error reporting.
- * If there is no value, or the conversion is not successful, the
- * routine exits with an error, otherwise it returns the value found.
- * *i is incremented once.
- */
-static int iscan(int argc, char *argv[], int *i)
-{
-    const char *const arg = argv[*i];
-    if (argc <= (*i)+1)
-    {
-        usage("an integer", arg);
-    }
-    const char *const value = argv[++(*i)];
-    char             *endptr;
-    int               var = std::strtol(value, &endptr, 10);
-    if (*value == '\0' || *endptr != '\0')
-    {
-        usage("an integer", arg);
-    }
-    return var;
-}
-
-/* Same as above, but for large integer values */
-static gmx_int64_t istepscan(int argc, char *argv[], int *i)
-{
-    const char *const arg = argv[*i];
-    if (argc <= (*i)+1)
-    {
-        usage("an integer", arg);
-    }
-    const char *const value = argv[++(*i)];
-    char             *endptr;
-    gmx_int64_t       var = str_to_int64_t(value, &endptr);
-    if (*value == '\0' || *endptr != '\0')
-    {
-        usage("an integer", arg);
-    }
-    return var;
-}
-
-/* Routine similar to the above, but working on doubles. */
-static double dscan(int argc, char *argv[], int *i)
-{
-    const char *const arg = argv[*i];
-    if (argc <= (*i)+1)
-    {
-        usage("a real", arg);
-    }
-    const char *const value = argv[++(*i)];
-    char             *endptr;
-    double            var = std::strtod(value, &endptr);
-    if (*value == '\0' || *endptr != '\0')
-    {
-        usage("a real", arg);
-    }
-    return var;
-}
-
-/* Routine similar to the above, but working on strings. The pointer
- * returned is a pointer to the argv field.
- */
-static char *sscan(int argc, char *argv[], int *i)
-{
-    if (argc > (*i)+1)
-    {
-        if ( (argv[(*i)+1][0] == '-') && (argc > (*i)+2) &&
-             (argv[(*i)+2][0] != '-') )
-        {
-            fprintf(stderr, "Possible missing string argument for option %s\n\n",
-                    argv[*i]);
-        }
-    }
-    else
-    {
-        usage("a string", argv[*i]);
-    }
-
-    return argv[++(*i)];
-}
-
-static gmx_bool is_hidden(t_pargs *pa)
-{
-    return (strstr(pa->desc, "HIDDEN") != NULL);
-}
-
 int nenum(const char *const enumc[])
 {
     int i;
@@ -180,140 +92,6 @@ int nenum(const char *const enumc[])
     return i;
 }
 
-/* Read a number of arguments from the command line.
- * For etINT, etREAL and etCHAR an extra argument is read (when present)
- * for etBOOL the gmx_boolean option is changed to the negate value
- */
-static void get_pargs(int *argc, char *argv[], int nparg, t_pargs pa[])
-{
-    int       i, j, k, match;
-    gmx_bool *bKeep;
-    char      buf[32];
-    char     *ptr;
-
-    snew(bKeep, *argc+1);
-    bKeep[0]     = TRUE;
-    bKeep[*argc] = TRUE;
-
-    for (i = 1; (i < *argc); i++)
-    {
-        bKeep[i] = TRUE;
-        for (j = 0; (j < nparg); j++)
-        {
-            if (pa[j].type == etBOOL)
-            {
-                sprintf(buf, "-no%s", pa[j].option+1);
-                if (strcmp(pa[j].option, argv[i]) == 0)
-                {
-                    *pa[j].u.b = TRUE;
-                    pa[j].bSet = TRUE;
-                    bKeep[i]   = FALSE;
-                }
-                else if (strcmp(buf, argv[i]) == 0)
-                {
-                    *pa[j].u.b = FALSE;
-                    pa[j].bSet = TRUE;
-                    bKeep[i]   = FALSE;
-                }
-            }
-            else if (strcmp(pa[j].option, argv[i]) == 0)
-            {
-                if (pa[j].bSet)
-                {
-                    fprintf(stderr, "Setting option %s more than once!\n",
-                            pa[j].option);
-                }
-                pa[j].bSet = TRUE;
-                bKeep[i]   = FALSE;
-                switch (pa[j].type)
-                {
-                    case etINT:
-                        *pa[j].u.i = iscan(*argc, argv, &i);
-                        break;
-                    case etINT64:
-                        *pa[j].u.is = istepscan(*argc, argv, &i);
-                        break;
-                    case etTIME:
-                    case etREAL:
-                        *pa[j].u.r = dscan(*argc, argv, &i);
-                        break;
-                    case etSTR:
-                        *(pa[j].u.c) = sscan(*argc, argv, &i);
-                        break;
-                    case etENUM:
-                        match = -1;
-                        ptr   = sscan(*argc, argv, &i);
-                        for (k = 1; (pa[j].u.c[k] != NULL); k++)
-                        {
-                            /* only check ptr against beginning of
-                               pa[j].u.c[k] */
-                            if (gmx_strncasecmp(ptr, pa[j].u.c[k], strlen(ptr)) == 0)
-                            {
-                                if ( ( match == -1 ) ||
-                                     ( strlen(pa[j].u.c[k]) <
-                                       strlen(pa[j].u.c[match]) ) )
-                                {
-                                    match = k;
-                                }
-                            }
-                        }
-                        if (match != -1)
-                        {
-                            pa[j].u.c[0] = pa[j].u.c[match];
-                        }
-                        else
-                        {
-                            gmx_fatal(FARGS, "Invalid argument %s for option %s",
-                                      ptr, pa[j].option);
-                        }
-                        break;
-                    case etRVEC:
-                        (*pa[j].u.rv)[0] = dscan(*argc, argv, &i);
-                        if ( (i+1 == *argc) ||
-                             ( (argv[i+1][0] == '-') &&
-                               !isdigit(argv[i+1][1]) ) )
-                        {
-                            (*pa[j].u.rv)[1]     =
-                                (*pa[j].u.rv)[2] =
-                                    (*pa[j].u.rv)[0];
-                        }
-                        else
-                        {
-                            bKeep[i]         = FALSE;
-                            (*pa[j].u.rv)[1] = dscan(*argc, argv, &i);
-                            if ( (i+1 == *argc) ||
-                                 ( (argv[i+1][0] == '-') &&
-                                   !isdigit(argv[i+1][1]) ) )
-                            {
-                                gmx_fatal(FARGS,
-                                          "%s: vector must have 1 or 3 real parameters",
-                                          pa[j].option);
-                            }
-                            bKeep[i]         = FALSE;
-                            (*pa[j].u.rv)[2] = dscan(*argc, argv, &i);
-                        }
-                        break;
-                    default:
-                        gmx_fatal(FARGS, "Invalid type %d in pargs", pa[j].type);
-                }
-                /* i may be incremented, so set it to not keep */
-                bKeep[i] = FALSE;
-            }
-        }
-    }
-
-    /* Remove used entries */
-    for (i = j = 0; (i <= *argc); i++)
-    {
-        if (bKeep[i])
-        {
-            argv[j++] = argv[i];
-        }
-    }
-    (*argc) = j-1;
-    sfree(bKeep);
-}
-
 int opt2parg_int(const char *option, int nparg, t_pargs pa[])
 {
     int i;
@@ -420,89 +198,141 @@ const char *opt2parg_enum(const char *option, int nparg, t_pargs pa[])
  * parse_common_args()
  */
 
-static void set_default_time_unit(const char *time_list[], gmx_bool bCanTime)
+namespace gmx
 {
-    int         i      = 0;
-    const char *select = NULL;
-
-    if (bCanTime)
-    {
-        select = getenv("GMXTIMEUNIT");
-        if (select != NULL)
-        {
-            i = 1;
-            while (time_list[i] && strcmp(time_list[i], select) != 0)
-            {
-                i++;
-            }
-        }
-    }
-    if (!bCanTime || select == NULL ||
-        time_list[i] == NULL || strcmp(time_list[i], select) != 0)
-    {
-        /* Set it to the default: ps */
-        i = 1;
-        while (time_list[i] && strcmp(time_list[i], "ps") != 0)
-        {
-            i++;
-        }
 
-    }
-    time_list[0] = time_list[i];
-}
-
-static void set_default_xvg_format(const char *xvg_list[])
+namespace
 {
-    int         i;
-    const char *select;
 
-    select = getenv("GMX_VIEW_XVG");
-    if (select == NULL)
-    {
-        /* The default is the first option */
-        xvg_list[0] = xvg_list[1];
-    }
-    else
+/*! \brief
+ * Returns the index of the default xvg format.
+ *
+ * \ingroup module_commandline
+ */
+int getDefaultXvgFormat(gmx::ConstArrayRef<const char *> xvgFormats)
+{
+    const char *const select = getenv("GMX_VIEW_XVG");
+    if (select != NULL)
     {
-        i = 1;
-        while (xvg_list[i] && strcmp(xvg_list[i], select) != 0)
+        ConstArrayRef<const char *>::const_iterator i =
+            std::find(xvgFormats.begin(), xvgFormats.end(), std::string(select));
+        if (i != xvgFormats.end())
         {
-            i++;
-        }
-        if (xvg_list[i] != NULL)
-        {
-            xvg_list[0] = xvg_list[i];
+            return i - xvgFormats.begin();
         }
         else
         {
-            xvg_list[0] = xvg_list[exvgNONE];
+            return exvgNONE - 1;
         }
     }
+    /* The default is the first option */
+    return 0;
 }
 
-static int add_parg(int npargs, t_pargs *pa, t_pargs *pa_add)
-{
-    memcpy(&(pa[npargs]), pa_add, sizeof(*pa_add));
-
-    return npargs+1;
-}
-
-namespace gmx
-{
-
-namespace
-{
-
 /*! \brief
- * Converts a t_filenm option into an Options option.
+ * Conversion helper between t_pargs/t_filenm and Options.
  *
- * \param     options Options object to add the new option to.
- * \param[in] fnm     t_filenm option to convert.
+ * This class holds the necessary mapping between the old C structures and
+ * the new C++ options to allow copying values back after parsing for cases
+ * where the C++ options do not directly provide the type of value required for
+ * the C structures.
  *
  * \ingroup module_commandline
  */
-void filenmToOptions(Options *options, const t_filenm *fnm)
+class OptionsAdapter
 {
+    public:
+        /*! \brief
+         * Initializes the adapter to convert from a specified command line.
+         *
+         * The command line is required, because t_pargs wants to return
+         * strings by reference to the original command line.
+         * OptionsAdapter creates a copy of the `argv` array (but not the
+         * strings) to make this possible, even if the parser removes
+         * options it has recognized.
+         */
+        OptionsAdapter(int argc, const char *const argv[])
+            : argv_(argv, argv + argc)
+        {
+        }
+
+        /*! \brief
+         * Converts a t_filenm option into an Options option.
+         *
+         * \param options Options object to add the new option to.
+         * \param fnm     t_filenm option to convert.
+         */
+        void filenmToOptions(Options *options, t_filenm *fnm);
+        /*! \brief
+         * Converts a t_pargs option into an Options option.
+         *
+         * \param     options Options object to add the new option to.
+         * \param     pa      t_pargs option to convert.
+         */
+        void pargsToOptions(Options *options, t_pargs *pa);
+
+        /*! \brief
+         * Copies values back from options to t_pargs/t_filenm.
+         */
+        void copyValues(bool bReadNode);
+
+    private:
+        struct FileNameData
+        {
+            //! Creates a conversion helper for a given `t_filenm` struct.
+            explicit FileNameData(t_filenm *fnm) : fnm(fnm), optionInfo(NULL)
+            {
+            }
+
+            //! t_filenm structure to receive the final values.
+            t_filenm                 *fnm;
+            //! Option info object for the created FileNameOption.
+            FileNameOptionInfo       *optionInfo;
+            //! Value storage for the created FileNameOption.
+            std::vector<std::string>  values;
+        };
+        struct ProgramArgData
+        {
+            //! Creates a conversion helper for a given `t_pargs` struct.
+            explicit ProgramArgData(t_pargs *pa)
+                : pa(pa), optionInfo(NULL), enumIndex(0), boolValue(false)
+            {
+            }
+
+            //! t_pargs structure to receive the final values.
+            t_pargs                 *pa;
+            //! Option info object for the created option.
+            OptionInfo              *optionInfo;
+            //! Value storage for a non-enum StringOption (unused for other types).
+            std::string              stringValue;
+            //! Value storage for an enum option (unused for other types).
+            int                      enumIndex;
+            //! Value storage for a BooleanOption (unused for other types).
+            bool                     boolValue;
+        };
+
+        std::vector<const char *>    argv_;
+        // These are lists instead of vectors to avoid relocating existing
+        // objects in case the container is reallocated (the Options object
+        // contains pointes to members of the objects, which would get
+        // invalidated).
+        std::list<FileNameData>      fileNameOptions_;
+        std::list<ProgramArgData>    programArgs_;
+
+        GMX_DISALLOW_COPY_AND_ASSIGN(OptionsAdapter);
+};
+
+void OptionsAdapter::filenmToOptions(Options *options, t_filenm *fnm)
+{
+    if (fnm->opt == NULL)
+    {
+        // Existing code may use opt2fn() instead of ftp2fn() for
+        // options that use the default option name, so we need to
+        // keep the old behavior instead of fixing opt2fn().
+        // TODO: Check that this is not the case, remove this, and make
+        // opt2*() work even if fnm->opt is NULL for some options.
+        fnm->opt = ftp2defopt(fnm->ftp);
+    }
     const bool        bRead     = ((fnm->flag & ffREAD)  != 0);
     const bool        bWrite    = ((fnm->flag & ffWRITE) != 0);
     const bool        bOptional = ((fnm->flag & ffOPT)   != 0);
@@ -514,81 +344,136 @@ void filenmToOptions(Options *options, const t_filenm *fnm)
     {
         defName = ftp2defnm(fnm->ftp);
     }
-    // Since we are not (yet) using this for actual parsing, we don't need to
-    // set any storage.
-    options->addOption(
-            FileNameOption(name).defaultBasename(defName).legacyType(fnm->ftp)
-                .readWriteFlags(bRead, bWrite).required(!bOptional)
-                .libraryFile(bLibrary).multiValue(bMultiple)
-                .description(ftp2desc(fnm->ftp)));
+    fileNameOptions_.push_back(FileNameData(fnm));
+    FileNameData &data = fileNameOptions_.back();
+    data.optionInfo = options->addOption(
+                FileNameOption(name).storeVector(&data.values)
+                    .defaultBasename(defName).legacyType(fnm->ftp)
+                    .legacyOptionalBehavior()
+                    .readWriteFlags(bRead, bWrite).required(!bOptional)
+                    .libraryFile(bLibrary).multiValue(bMultiple)
+                    .description(ftp2desc(fnm->ftp)));
 }
 
-/*! \brief
- * Converts a t_pargs option into an Options option.
- *
- * \param     options Options object to add the new option to.
- * \param[in] pa      t_pargs option to convert.
- *
- * \ingroup module_commandline
- */
-void pargsToOptions(Options *options, t_pargs *pa)
+void OptionsAdapter::pargsToOptions(Options *options, t_pargs *pa)
 {
-    const bool        bHidden = is_hidden(pa);
+    const bool        bHidden = startsWith(pa->desc, "HIDDEN");
     const char *const name    = &pa->option[1];
     const char *const desc    = (bHidden ? &pa->desc[6] : pa->desc);
-    // Since we are not (yet) using this for actual parsing, we can take some
-    // shortcuts and not set any storage where there is no direct
-    // correspondence in the types.
+    programArgs_.push_back(ProgramArgData(pa));
+    ProgramArgData   &data = programArgs_.back();
     switch (pa->type)
     {
         case etINT:
-            options->addOption(
-                IntegerOption(name).store(pa->u.i)
-                    .description(desc).hidden(bHidden));
+            data.optionInfo = options->addOption(
+                        IntegerOption(name).store(pa->u.i)
+                            .description(desc).hidden(bHidden));
             return;
         case etINT64:
-            options->addOption(
-                Int64Option(name).store(pa->u.is)
-                    .description(desc).hidden(bHidden));
+            data.optionInfo = options->addOption(
+                        Int64Option(name).store(pa->u.is)
+                            .description(desc).hidden(bHidden));
             return;
         case etREAL:
-            options->addOption(
-                RealOption(name).store(pa->u.r)
-                    .description(desc).hidden(bHidden));
+            data.optionInfo = options->addOption(
+                        RealOption(name).store(pa->u.r)
+                            .description(desc).hidden(bHidden));
             return;
         case etTIME:
-            options->addOption(
-                RealOption(name).store(pa->u.r).timeValue()
-                    .description(desc).hidden(bHidden));
+            data.optionInfo = options->addOption(
+                        RealOption(name).store(pa->u.r).timeValue()
+                            .description(desc).hidden(bHidden));
             return;
         case etSTR:
         {
             const char *const defValue = (*pa->u.c != NULL ? *pa->u.c : "");
-            options->addOption(
-                    StringOption(name).defaultValue(defValue)
-                        .description(desc).hidden(bHidden));
+            data.optionInfo = options->addOption(
+                        StringOption(name).store(&data.stringValue)
+                            .defaultValue(defValue)
+                            .description(desc).hidden(bHidden));
             return;
         }
         case etBOOL:
-            options->addOption(
-                BooleanOption(name).defaultValue(*pa->u.b)
-                    .description(desc).hidden(bHidden));
+            data.optionInfo = options->addOption(
+                        BooleanOption(name).store(&data.boolValue)
+                            .defaultValue(*pa->u.b)
+                            .description(desc).hidden(bHidden));
             return;
         case etRVEC:
-            options->addOption(
-                RealOption(name).store(*pa->u.rv).vector()
-                    .description(desc).hidden(bHidden));
+            data.optionInfo = options->addOption(
+                        RealOption(name).store(*pa->u.rv).vector()
+                            .description(desc).hidden(bHidden));
             return;
         case etENUM:
-            options->addOption(
-                StringOption(name).defaultEnumIndex(nenum(pa->u.c) - 1)
-                    .enumValueFromNullTerminatedArray(pa->u.c + 1)
-                    .description(desc).hidden(bHidden));
+        {
+            const int defaultIndex = (pa->u.c[0] != NULL ? nenum(pa->u.c) - 1 : 0);
+            data.optionInfo = options->addOption(
+                        StringOption(name).storeEnumIndex(&data.enumIndex)
+                            .defaultEnumIndex(defaultIndex)
+                            .enumValueFromNullTerminatedArray(pa->u.c + 1)
+                            .description(desc).hidden(bHidden));
             return;
+        }
     }
     GMX_THROW(NotImplementedError("Argument type not implemented"));
 }
 
+void OptionsAdapter::copyValues(bool bReadNode)
+{
+    std::list<FileNameData>::const_iterator file;
+    for (file = fileNameOptions_.begin(); file != fileNameOptions_.end(); ++file)
+    {
+        // FIXME: FF_NOT_READ_NODE should also skip all fexist() calls in
+        // FileNameOption.  However, it is not currently used, and other
+        // commented out code for using it is also outdated, so left this for
+        // later.
+        if (!bReadNode && (file->fnm->flag & ffREAD))
+        {
+            continue;
+        }
+        if (file->optionInfo->isSet())
+        {
+            file->fnm->flag |= ffSET;
+        }
+        file->fnm->nfiles = file->values.size();
+        snew(file->fnm->fns, file->fnm->nfiles);
+        for (int i = 0; i < file->fnm->nfiles; ++i)
+        {
+            // TODO: Check for out-of-memory.
+            file->fnm->fns[i] = strdup(file->values[i].c_str());
+        }
+    }
+    std::list<ProgramArgData>::const_iterator arg;
+    for (arg = programArgs_.begin(); arg != programArgs_.end(); ++arg)
+    {
+        arg->pa->bSet = arg->optionInfo->isSet();
+        switch (arg->pa->type)
+        {
+            case etSTR:
+            {
+                if (arg->pa->bSet)
+                {
+                    std::vector<const char *>::const_iterator pos =
+                        std::find(argv_.begin(), argv_.end(), arg->stringValue);
+                    GMX_RELEASE_ASSERT(pos != argv_.end(),
+                                       "String argument got a value not in argv");
+                    *arg->pa->u.c = *pos;
+                }
+                break;
+            }
+            case etBOOL:
+                *arg->pa->u.b = arg->boolValue;
+                break;
+            case etENUM:
+                *arg->pa->u.c = arg->pa->u.c[arg->enumIndex + 1];
+                break;
+            default:
+                // For other types, there is nothing type-specific to do.
+                break;
+        }
+    }
+}
+
 } // namespace
 
 } // namespace gmx
@@ -600,279 +485,182 @@ gmx_bool parse_common_args(int *argc, char *argv[], unsigned long Flags,
                            output_env_t *oenv)
 {
     /* This array should match the order of the enum in oenv.h */
-    const char *xvg_format[] = { NULL, "xmgrace", "xmgr", "none", NULL };
-    /* This array should match the order of the enum in oenv.h */
-    const char *time_units[] = {
-        NULL, "fs", "ps", "ns", "us", "ms", "s",
-        NULL
-    };
-    int         nicelevel = 0, debug_level = 0;
-    char       *deffnm    = NULL;
-    real        tbegin    = 0, tend = 0, tdelta = 0;
-    gmx_bool    bView     = FALSE;
-
-    t_pargs    *all_pa = NULL;
-
-    t_pargs     nice_pa   = {
-        "-nice", FALSE, etINT,   {&nicelevel},
-        "Set the nicelevel"
-    };
-    t_pargs     deffnm_pa = {
-        "-deffnm", FALSE, etSTR, {&deffnm},
-        "Set the default filename for all file options"
-    };
-    t_pargs     begin_pa  = {
-        "-b",    FALSE, etTIME,  {&tbegin},
-        "First frame (%t) to read from trajectory"
-    };
-    t_pargs     end_pa    = {
-        "-e",    FALSE, etTIME,  {&tend},
-        "Last frame (%t) to read from trajectory"
-    };
-    t_pargs     dt_pa     = {
-        "-dt",   FALSE, etTIME,  {&tdelta},
-        "Only use frame when t MOD dt = first time (%t)"
-    };
-    t_pargs     view_pa   = {
-        "-w",    FALSE, etBOOL,  {&bView},
-        "View output [TT].xvg[tt], [TT].xpm[tt], [TT].eps[tt] and [TT].pdb[tt] files"
-    };
-    t_pargs     xvg_pa    = {
-        "-xvg",  FALSE, etENUM,  {xvg_format},
-        "xvg plot formatting"
-    };
-    t_pargs     time_pa   = {
-        "-tu",   FALSE, etENUM,  {time_units},
-        "Time unit"
-    };
-    /* Maximum number of extra arguments */
-#define EXTRA_PA 16
-
-    t_pargs  pca_pa[] = {
-        { "-debug", FALSE, etINT, {&debug_level},
-          "HIDDENWrite file with debug information, 1: short, 2: also x and f" },
-    };
-#define NPCA_PA asize(pca_pa)
-    gmx_bool bXvgr;
-    int      i, j, k, npall, max_pa;
+    const char *const xvg_formats[] = { "xmgrace", "xmgr", "none" };
 
     // Handle the flags argument, which is a bit field
     // The FF macro returns whether or not the bit is set
 #define FF(arg) ((Flags & arg) == arg)
 
-    /* Check for double arguments */
-    for (i = 1; (i < *argc); i++)
+    try
     {
-        if (argv[i] && (strlen(argv[i]) > 1) && (!std::isdigit(argv[i][1])))
+        int                        nicelevel = 0, debug_level = 0;
+        double                     tbegin    = 0.0, tend = 0.0, tdelta = 0.0;
+        bool                       bView     = false;
+        int                        xvgFormat = 0;
+        gmx::TimeUnitManager       timeUnitManager;
+        gmx::OptionsAdapter        adapter(*argc, argv);
+        gmx::Options               options(NULL, NULL);
+        gmx::FileNameOptionManager fileOptManager;
+
+        options.addManager(&fileOptManager);
+        options.setDescription(gmx::ConstArrayRef<const char *>(desc, ndesc));
+        options.addOption(
+                gmx::IntegerOption("debug").store(&debug_level).hidden()
+                    .description("Write file with debug information, "
+                                 "1: short, 2: also x and f"));
+
+        options.addOption(
+                gmx::IntegerOption("nice").store(&nicelevel)
+                    .defaultValue(FF(PCA_BE_NICE) ? 19 : 0)
+                    .description("Set the nicelevel"));
+
+        if (FF(PCA_CAN_SET_DEFFNM))
         {
-            for (j = i+1; (j < *argc); j++)
-            {
-                if ( (argv[i][0] == '-') && (argv[j][0] == '-') &&
-                     (strcmp(argv[i], argv[j]) == 0) )
-                {
-                    if (FF(PCA_NOEXIT_ON_ARGS))
-                    {
-                        fprintf(stderr, "Double command line argument %s\n",
-                                argv[i]);
-                    }
-                    else
-                    {
-                        gmx_fatal(FARGS, "Double command line argument %s\n",
-                                  argv[i]);
-                    }
-                }
-            }
+            fileOptManager.addDefaultFileNameOption(&options, "deffnm");
         }
-    }
-
-    /* Check ALL the flags ... */
-    max_pa = NPCA_PA + EXTRA_PA + npargs+1;
-    snew(all_pa, max_pa);
-
-    for (i = npall = 0; (i < static_cast<int>(NPCA_PA)); i++)
-    {
-        npall = add_parg(npall, all_pa, &(pca_pa[i]));
-    }
-
-    if (FF(PCA_BE_NICE))
-    {
-        nicelevel = 19;
-    }
-    npall = add_parg(npall, all_pa, &nice_pa);
-
-    if (FF(PCA_CAN_SET_DEFFNM))
-    {
-        npall = add_parg(npall, all_pa, &deffnm_pa);
-    }
-    if (FF(PCA_CAN_BEGIN))
-    {
-        npall = add_parg(npall, all_pa, &begin_pa);
-    }
-    if (FF(PCA_CAN_END))
-    {
-        npall = add_parg(npall, all_pa, &end_pa);
-    }
-    if (FF(PCA_CAN_DT))
-    {
-        npall = add_parg(npall, all_pa, &dt_pa);
-    }
-    if (FF(PCA_TIME_UNIT))
-    {
-        npall = add_parg(npall, all_pa, &time_pa);
-    }
-    if (FF(PCA_CAN_VIEW))
-    {
-        npall = add_parg(npall, all_pa, &view_pa);
-    }
-
-    bXvgr = FALSE;
-    for (i = 0; (i < nfile); i++)
-    {
-        bXvgr = bXvgr ||  (fnm[i].ftp == efXVG);
-    }
-    if (bXvgr)
-    {
-        npall = add_parg(npall, all_pa, &xvg_pa);
-    }
-
-    /* Now append the program specific arguments */
-    for (i = 0; (i < npargs); i++)
-    {
-        npall = add_parg(npall, all_pa, &(pa[i]));
-    }
-
-    /* set etENUM options to default */
-    for (i = 0; (i < npall); i++)
-    {
-        if (all_pa[i].type == etENUM)
+        if (FF(PCA_CAN_BEGIN))
         {
-            all_pa[i].u.c[0] = all_pa[i].u.c[1];
+            options.addOption(
+                    gmx::DoubleOption("b").store(&tbegin).timeValue()
+                        .description("First frame (%t) to read from trajectory"));
         }
-    }
-    set_default_time_unit(time_units, FF(PCA_TIME_UNIT));
-    set_default_xvg_format(xvg_format);
-
-    /* Now parse all the command-line options */
-    get_pargs(argc, argv, npall, all_pa);
-
-    /* set program name, command line, and default values for output options */
-    output_env_init(oenv, gmx::getProgramContext(), (time_unit_t)nenum(time_units), bView,
-                    (xvg_format_t)nenum(xvg_format), 0, debug_level);
-
-    /* Parse the file args */
-    parse_file_args(argc, argv, nfile, fnm, deffnm, !FF(PCA_NOT_READ_NODE));
-
-    /* Open the debug file */
-    if (debug_level > 0)
-    {
-        char buf[256];
-
-        if (gmx_mpi_initialized())
+        if (FF(PCA_CAN_END))
         {
-            sprintf(buf, "%s%d.debug", output_env_get_short_program_name(*oenv),
-                    gmx_node_rank());
+            options.addOption(
+                    gmx::DoubleOption("e").store(&tend).timeValue()
+                        .description("Last frame (%t) to read from trajectory"));
         }
-        else
+        if (FF(PCA_CAN_DT))
         {
-            sprintf(buf, "%s.debug", output_env_get_short_program_name(*oenv));
+            options.addOption(
+                    gmx::DoubleOption("dt").store(&tdelta).timeValue()
+                        .description("Only use frame when t MOD dt = first time (%t)"));
+        }
+        if (FF(PCA_TIME_UNIT))
+        {
+            timeUnitManager.setTimeUnitFromEnvironment();
+            timeUnitManager.addTimeUnitOption(&options, "tu");
+        }
+        if (FF(PCA_CAN_VIEW))
+        {
+            options.addOption(
+                    gmx::BooleanOption("w").store(&bView)
+                        .description("View output [TT].xvg[tt], [TT].xpm[tt], "
+                                     "[TT].eps[tt] and [TT].pdb[tt] files"));
         }
 
-        init_debug(debug_level, buf);
-        fprintf(stderr, "Opening debug file %s (src code file %s, line %d)\n",
-                buf, __FILE__, __LINE__);
-    }
+        bool bXvgr = false;
+        for (int i = 0; i < nfile; i++)
+        {
+            bXvgr = bXvgr || (fnm[i].ftp == efXVG);
+        }
+        xvgFormat = gmx::getDefaultXvgFormat(xvg_formats);
+        if (bXvgr)
+        {
+            options.addOption(
+                    gmx::StringOption("xvg").enumValue(xvg_formats)
+                        .storeEnumIndex(&xvgFormat)
+                        .description("xvg plot formatting"));
+        }
 
-    /* Now copy the results back... */
-    for (i = 0, k = npall-npargs; (i < npargs); i++, k++)
-    {
-        memcpy(&(pa[i]), &(all_pa[k]), (size_t)sizeof(pa[i]));
-    }
+        /* Now append the program specific arguments */
+        for (int i = 0; i < nfile; i++)
+        {
+            adapter.filenmToOptions(&options, &fnm[i]);
+        }
+        for (int i = 0; i < npargs; i++)
+        {
+            adapter.pargsToOptions(&options, &pa[i]);
+        }
 
-    bool bExit = false;
-    try
-    {
         const gmx::CommandLineHelpContext *context =
             gmx::GlobalCommandLineHelpContext::get();
-        bExit = (context != NULL);
-        if (context != NULL && !(FF(PCA_QUIET)))
+        if (context != NULL)
         {
-            gmx::Options options(NULL, NULL);
-            options.setDescription(gmx::ConstArrayRef<const char *>(desc, ndesc));
-            for (i = 0; i < nfile; i++)
+            if (!(FF(PCA_QUIET)))
             {
-                gmx::filenmToOptions(&options, &fnm[i]);
+                gmx::CommandLineHelpWriter(options)
+                    .setShowDescriptions(true)
+                    .setTimeUnitString(timeUnitManager.timeUnitAsString())
+                    .setKnownIssues(gmx::ConstArrayRef<const char *>(bugs, nbugs))
+                    .writeHelp(*context);
             }
-            for (i = 0; i < npall; i++)
+            return FALSE;
+        }
+
+        /* Now parse all the command-line options */
+        gmx::CommandLineParser(&options).skipUnknown(FF(PCA_NOEXIT_ON_ARGS))
+            .parse(argc, argv);
+        options.finish();
+
+        /* set program name, command line, and default values for output options */
+        output_env_init(oenv, gmx::getProgramContext(),
+                        (time_unit_t)(timeUnitManager.timeUnit() + 1), bView,
+                        (xvg_format_t)(xvgFormat + 1), 0, debug_level);
+
+        /* Open the debug file */
+        if (debug_level > 0)
+        {
+            char buf[256];
+
+            if (gmx_mpi_initialized())
+            {
+                sprintf(buf, "%s%d.debug", output_env_get_short_program_name(*oenv),
+                        gmx_node_rank());
+            }
+            else
             {
-                gmx::pargsToOptions(&options, &all_pa[i]);
+                sprintf(buf, "%s.debug", output_env_get_short_program_name(*oenv));
             }
-            gmx::CommandLineHelpWriter(options)
-                .setShowDescriptions(true)
-                .setTimeUnitString(output_env_get_time_unit(*oenv))
-                .setKnownIssues(gmx::ConstArrayRef<const char *>(bugs, nbugs))
-                .writeHelp(*context);
+
+            init_debug(debug_level, buf);
+            fprintf(stderr, "Opening debug file %s (src code file %s, line %d)\n",
+                    buf, __FILE__, __LINE__);
         }
-    }
-    GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
 
-    /* Set the nice level */
+        /* Set the nice level */
 #ifdef HAVE_UNISTD_H
 #ifndef GMX_NO_NICE
-    /* The some system, e.g. the catamount kernel on cray xt3 do not have nice(2). */
-    if (nicelevel != 0 && !bExit)
-    {
-        static gmx_bool            nice_set   = FALSE; /* only set it once */
-        static tMPI_Thread_mutex_t init_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
-        tMPI_Thread_mutex_lock(&init_mutex);
-        if (!nice_set)
+        /* The some system, e.g. the catamount kernel on cray xt3 do not have nice(2). */
+        if (nicelevel != 0)
         {
-            if (nice(nicelevel) == -1)
+            static gmx_bool            nice_set   = FALSE; /* only set it once */
+            static tMPI_Thread_mutex_t init_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
+            tMPI_Thread_mutex_lock(&init_mutex);
+            if (!nice_set)
             {
-                /* Do nothing, but use the return value to avoid warnings. */
+                if (nice(nicelevel) == -1)
+                {
+                    /* Do nothing, but use the return value to avoid warnings. */
+                }
+                nice_set = TRUE;
             }
-            nice_set = TRUE;
+            tMPI_Thread_mutex_unlock(&init_mutex);
         }
-        tMPI_Thread_mutex_unlock(&init_mutex);
-    }
 #endif
 #endif
 
-    /* convert time options, must be done after printing! */
+        timeUnitManager.scaleTimeOptions(&options);
 
-    for (i = 0; i < npall; i++)
-    {
-        if (all_pa[i].type == etTIME && all_pa[i].bSet)
+        /* Extract Time info from arguments */
+        // TODO: Use OptionInfo objects instead of string constants
+        if (FF(PCA_CAN_BEGIN) && options.isSet("b"))
         {
-            *all_pa[i].u.r *= output_env_get_time_invfactor(*oenv);
+            setTimeValue(TBEGIN, tbegin);
         }
-    }
-
-    /* Extract Time info from arguments */
-    if (FF(PCA_CAN_BEGIN) && opt2parg_bSet("-b", npall, all_pa))
-    {
-        setTimeValue(TBEGIN, opt2parg_real("-b", npall, all_pa));
-    }
-
-    if (FF(PCA_CAN_END) && opt2parg_bSet("-e", npall, all_pa))
-    {
-        setTimeValue(TEND, opt2parg_real("-e", npall, all_pa));
-    }
-
-    if (FF(PCA_CAN_DT) && opt2parg_bSet("-dt", npall, all_pa))
-    {
-        setTimeValue(TDELTA, opt2parg_real("-dt", npall, all_pa));
-    }
-
-    /* clear memory */
-    sfree(all_pa);
-
-    if (!FF(PCA_NOEXIT_ON_ARGS))
-    {
-        if (*argc > 1)
+        if (FF(PCA_CAN_END) && options.isSet("-e"))
+        {
+            setTimeValue(TEND, tend);
+        }
+        if (FF(PCA_CAN_DT) && options.isSet("-dt"))
         {
-            gmx_cmd(argv[1]);
+            setTimeValue(TDELTA, tdelta);
         }
+
+        adapter.copyValues(!FF(PCA_NOT_READ_NODE));
+
+        return TRUE;
     }
-    return !bExit;
+    GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR;
 #undef FF
 }
index b8e5b3adc989eeea19b753e1b7419689b3c88e1e..5d0e7debab2c8740ef32bc20972c48be757dd71e 100644 (file)
@@ -223,15 +223,15 @@ TEST_F(CommandLineHelpWriterTest, HandlesSelectionOptions)
     using gmx::SelectionFileOption;
     using gmx::SelectionOption;
 
-    gmx::Options options(NULL, NULL);
+    gmx::Options                options(NULL, NULL);
+    gmx::SelectionCollection    selections;
+    gmx::SelectionOptionManager manager(&selections);
+    options.addManager(&manager);
     options.addOption(SelectionFileOption("sf"));
     options.addOption(SelectionOption("refsel").required()
                           .description("Reference selection option"));
     options.addOption(SelectionOption("sel").required().valueCount(2)
                           .description("Selection option"));
-    gmx::SelectionCollection    selections;
-    gmx::SelectionOptionManager manager(&selections);
-    setManagerForSelectionOptions(&options, &manager);
     options.finish();
     manager.parseRequestedFromString(
             "resname SOL;"
index ca95dd7db7e4e1e0f3147b7905e2a89a33911df5..a27f3b98f4e90a107356e23778416b63895e1df6 100644 (file)
@@ -323,8 +323,12 @@ TEST_F(ParseCommonArgsTest, ParsesFileArgs)
     EXPECT_STREQ("test.xvg", opt2fn_null("-o2", nfile(), fnm));
     char **files;
     EXPECT_EQ(2, opt2fns(&files, "-om", nfile(), fnm));
-    EXPECT_STREQ("test1.xvg", files[0]);
-    EXPECT_STREQ("test2.xvg", files[1]);
+    EXPECT_TRUE(files != NULL);
+    if (files != NULL)
+    {
+        EXPECT_STREQ("test1.xvg", files[0]);
+        EXPECT_STREQ("test2.xvg", files[1]);
+    }
     EXPECT_STREQ("outm2.xvg", opt2fn("-om2", nfile(), fnm));
     done_filenms(nfile(), fnm);
 }
index de8d84de1ad1a49203b5d938727a41806710e686..0b31d704f5cc639ba6fea5fde6d9d9a0b7973c41 100644 (file)
 #endif
 
 #include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 
-#include "macros.h"
-#include "types/commrec.h"
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/legacyheaders/types/commrec.h"
 
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
-#include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
 /* XDR should be available on all platforms now,
@@ -61,9 +59,6 @@
 /* Use bitflag ... */
 #define IS_SET(fn) ((fn.flag & ffSET) != 0)
 #define IS_OPT(fn) ((fn.flag & ffOPT) != 0)
-#define IS_MULT(fn) ((fn.flag & ffMULT) != 0)
-#define UN_SET(fn) (fn.flag = (fn.flag & ~ffSET))
-#define DO_SET(fn) (fn.flag = (fn.flag |  ffSET))
 
 enum
 {
@@ -336,26 +331,15 @@ const char *ftp2defnm(int ftp)
     }
 }
 
-static void check_opts(int nf, t_filenm fnm[])
+const char *ftp2defopt(int ftp)
 {
-    int              i;
-    const t_deffile *df;
-
-    for (i = 0; (i < nf); i++)
+    if ((0 <= ftp) && (ftp < efNR))
     {
-        df = &(deffile[fnm[i].ftp]);
-        if (fnm[i].opt == NULL)
-        {
-            if (df->defopt == NULL)
-            {
-                gmx_fatal(FARGS, "No default cmd-line option for %s (type %d)\n",
-                          deffile[fnm[i].ftp].ext, fnm[i].ftp);
-            }
-            else
-            {
-                fnm[i].opt = df->defopt;
-            }
-        }
+        return deffile[ftp].defopt;
+    }
+    else
+    {
+        return NULL;
     }
 }
 
@@ -394,246 +378,6 @@ int fn2ftp(const char *fn)
     return i;
 }
 
-static void set_extension(char *buf, int ftp)
-{
-    int              len, extlen;
-    const t_deffile *df;
-
-    /* check if extension is already at end of filename */
-    df     = &(deffile[ftp]);
-    len    = strlen(buf);
-    extlen = strlen(df->ext);
-    if ((len <= extlen) || (gmx_strcasecmp(&(buf[len - extlen]), df->ext) != 0))
-    {
-        strcat(buf, df->ext);
-    }
-}
-
-static void add_filenm(t_filenm *fnm, const char *filenm)
-{
-    srenew(fnm->fns, fnm->nfiles+1);
-    fnm->fns[fnm->nfiles] = strdup(filenm);
-    fnm->nfiles++;
-}
-
-static void set_grpfnm(t_filenm *fnm, const char *name, const char *deffnm)
-{
-    char       buf[256], buf2[256];
-    int        i, type;
-    gmx_bool   bValidExt;
-    int        nopts;
-    const int *ftps;
-
-    nopts = deffile[fnm->ftp].ntps;
-    ftps  = deffile[fnm->ftp].tps;
-    if ((nopts == 0) || (ftps == NULL))
-    {
-        gmx_fatal(FARGS, "nopts == 0 || ftps == NULL");
-    }
-
-    bValidExt = FALSE;
-    if (name && deffnm == NULL)
-    {
-        strcpy(buf, name);
-        /* First check whether we have a valid filename already */
-        type = fn2ftp(name);
-        if ((fnm->flag & ffREAD) && (fnm->ftp == efTRX))
-        {
-            /*if file exist don't add an extension for trajectory reading*/
-            bValidExt = gmx_fexist(name);
-        }
-        for (i = 0; (i < nopts) && !bValidExt; i++)
-        {
-            if (type == ftps[i])
-            {
-                bValidExt = TRUE;
-            }
-        }
-    }
-    else if (deffnm != NULL)
-    {
-        strcpy(buf, deffnm);
-    }
-    else
-    {
-        /* No name given, set the default name */
-        strcpy(buf, ftp2defnm(fnm->ftp));
-    }
-
-    if (!bValidExt && (fnm->flag & ffREAD))
-    {
-        /* for input-files only: search for filenames in the directory */
-        for (i = 0; (i < nopts) && !bValidExt; i++)
-        {
-            type = ftps[i];
-            strcpy(buf2, buf);
-            set_extension(buf2, type);
-            if (gmx_fexist(buf2))
-            {
-                bValidExt = TRUE;
-                strcpy(buf, buf2);
-            }
-        }
-    }
-
-    if (!bValidExt)
-    {
-        /* Use the first extension type */
-        set_extension(buf, ftps[0]);
-    }
-
-    add_filenm(fnm, buf);
-}
-
-static void set_filenm(t_filenm *fnm, const char *name, const char *deffnm,
-                       gmx_bool bReadNode)
-{
-    /* Set the default filename, extension and option for those fields that
-     * are not already set. An extension is added if not present, if fn = NULL
-     * or empty, the default filename is given.
-     */
-    char buf[256];
-    int  i, len, extlen;
-
-    if ((fnm->flag & ffREAD) && !bReadNode)
-    {
-        return;
-    }
-
-    if ((fnm->ftp < 0) || (fnm->ftp >= efNR))
-    {
-        gmx_fatal(FARGS, "file type out of range (%d)", fnm->ftp);
-    }
-
-    if (name)
-    {
-        strcpy(buf, name);
-    }
-    if ((fnm->flag & ffREAD) && name && gmx_fexist(name))
-    {
-        /* check if filename ends in .gz or .Z, if so remove that: */
-        len = strlen(name);
-        for (i = 0; i < NZEXT; i++)
-        {
-            extlen = strlen(z_ext[i]);
-            if (len > extlen)
-            {
-                if (gmx_strcasecmp(name+len-extlen, z_ext[i]) == 0)
-                {
-                    buf[len-extlen] = '\0';
-                    break;
-                }
-            }
-        }
-    }
-
-    if (deffile[fnm->ftp].ntps)
-    {
-        set_grpfnm(fnm, name ? buf : NULL, deffnm);
-    }
-    else
-    {
-        if (name == NULL || deffnm != NULL)
-        {
-            if (deffnm != NULL)
-            {
-                strcpy(buf, deffnm);
-            }
-            else
-            {
-                strcpy(buf, ftp2defnm(fnm->ftp));
-            }
-        }
-        set_extension(buf, fnm->ftp);
-
-        add_filenm(fnm, buf);
-    }
-}
-
-static void set_filenms(int nf, t_filenm fnm[], const char *deffnm, gmx_bool bReadNode)
-{
-    int i;
-
-    for (i = 0; (i < nf); i++)
-    {
-        if (!IS_SET(fnm[i]))
-        {
-            set_filenm(&(fnm[i]), fnm[i].fn, deffnm, bReadNode);
-        }
-    }
-}
-
-void parse_file_args(int *argc, char *argv[], int nf, t_filenm fnm[],
-                     const char *deffnm, gmx_bool bReadNode)
-{
-    int       i, j;
-    gmx_bool *bRemove;
-
-    check_opts(nf, fnm);
-
-    for (i = 0; (i < nf); i++)
-    {
-        UN_SET(fnm[i]);
-    }
-
-    if (*argc > 1)
-    {
-        snew(bRemove, (*argc)+1);
-        i = 1;
-        do
-        {
-            for (j = 0; (j < nf); j++)
-            {
-                if (strcmp(argv[i], fnm[j].opt) == 0)
-                {
-                    DO_SET(fnm[j]);
-                    bRemove[i] = TRUE;
-                    i++;
-                    /* check if we are out of arguments for this option */
-                    if ((i >= *argc) || (argv[i][0] == '-'))
-                    {
-                        set_filenm(&fnm[j], fnm[j].fn, deffnm, bReadNode);
-                    }
-                    /* sweep up all file arguments for this option */
-                    while ((i < *argc) && (argv[i][0] != '-'))
-                    {
-                        set_filenm(&fnm[j], argv[i], NULL, bReadNode);
-                        bRemove[i] = TRUE;
-                        i++;
-                        /* only repeat for 'multiple' file options: */
-                        if (!IS_MULT(fnm[j]))
-                        {
-                            break;
-                        }
-                    }
-
-                    break; /* jump out of 'j' loop */
-                }
-            }
-            /* No file found corresponding to option argv[i] */
-            if (j == nf)
-            {
-                i++;
-            }
-        }
-        while (i < *argc);
-
-        /* Remove used entries */
-        for (i = j = 0; (i <= *argc); i++)
-        {
-            if (!bRemove[i])
-            {
-                argv[j++] = argv[i];
-            }
-        }
-        (*argc) = j - 1;
-        sfree(bRemove);
-    }
-
-    set_filenms(nf, fnm, deffnm, bReadNode);
-
-}
-
 const char *opt2fn(const char *opt, int nfile, const t_filenm fnm[])
 {
     int i;
@@ -818,7 +562,7 @@ int add_suffix_to_output_names(t_filenm *fnm, int nfile, const char *suffix)
                 extpos  = strrchr(buf, '.');
                 *extpos = '\0';
                 sprintf(newname, "%s%s.%s", buf, suffix, extpos + 1);
-                free(fnm[i].fns[j]);
+                sfree(fnm[i].fns[j]);
                 fnm[i].fns[j] = strdup(newname);
             }
         }
index 0463c54a34fac52afec7c04d906f2d36f2f09397..d5c1bd68164191970a6dedd2dc4c7c425b3df3e7 100644 (file)
@@ -115,14 +115,12 @@ const char *ftp2desc(int ftp);
 const char *ftp2defnm(int ftp);
 /* Return default file name for file type */
 
+const char *ftp2defopt(int ftp);
+/* Return default option name for file type */
+
 const char *ftp2ftype(int ftp);
 /* Return Binary or ASCII depending on file type */
 
-void parse_file_args(int *argc, char *argv[], int nf, t_filenm fnm[],
-                     const char *deffnm, gmx_bool bReadNode);
-/* Parse command line for file names. When bKeep is set args are
- * not removed from argv. */
-
 const char *opt2fn(const char *opt, int nfile, const t_filenm fnm[]);
 /* Return the filename belonging to cmd-line option opt, or NULL when
  * no such option. */
index a4c1487d683282c0a829d33fcb70756bda773d0a..39b8355b6d7be3f06da8243731574bfaf988da75 100644 (file)
@@ -45,7 +45,6 @@
 #include <string.h>
 
 #include "gromacs/legacyheaders/copyrite.h"
-#include "gromacs/legacyheaders/index.h"
 #include "gromacs/legacyheaders/types/ifunc.h"
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/utility/futil.h"
@@ -55,6 +54,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/topology/atomprop.h"
+#include "gromacs/topology/residuetypes.h"
 #include "gromacs/topology/symtab.h"
 #include "gromacs/topology/topology.h"
 #include "gromacs/utility/cstringutil.h"
index 3f86100cbe6562910a6498c5568b77d4e6ba0419..90ac8732c9730ec8918819e8afc77a9f905e9bc9 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-#include "gromacs/utility/smalloc.h"
 #include "gstat.h"
+
+#include "gromacs/topology/residuetypes.h"
 #include "gromacs/utility/fatalerror.h"
-#include "index.h"
+#include "gromacs/utility/smalloc.h"
 
 t_dlist *mk_dlist(FILE *log,
                   t_atoms *atoms, int *nlist,
index ee125c8b8e3f95aa6faf2aded1ab51b113b83de1..d0731c210a524b0e1a910adae2c1960f0f4f0d10 100644 (file)
@@ -47,7 +47,6 @@
 #include "gromacs/utility/futil.h"
 #include "gstat.h"
 #include "gromacs/math/vec.h"
-#include "index.h"
 
 #include "gromacs/utility/fatalerror.h"
 
index e0b4d1efe77ae268943e9e90e667579a6c089689..2c46a8f7efdc94c88c144b7dba5ec26d7148bc9d 100644 (file)
@@ -49,7 +49,7 @@
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/tpxio.h"
index 2795b3d2f7b792ebfe344add7a8a2caf7c951df8..b5c3d7e1a3d7d5c10f46643ec08a1d8e536edc1a 100644 (file)
@@ -47,7 +47,7 @@
 #include "gromacs/commandline/pargs.h"
 #include "copyrite.h"
 #include "gromacs/math/vec.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "macros.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/fileio/xvgr.h"
index 7947559761a6a0ed114dfdfc758412eb4f1ab77b..c0ffc08d9a9ec4f70c474d4052b89a8d867fe117 100644 (file)
@@ -46,7 +46,7 @@
 #include "macros.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/fileio/tpxio.h"
index 5cb3c68f89ebaaec63cc531a10876267ae191c36..b0f46c0a0906d0535826a45313430503c7c9a94b 100644 (file)
@@ -50,7 +50,7 @@
 #include "macros.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/units.h"
-#include "index.h"
+#include "gromacs/topology/residuetypes.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/tpxio.h"
index 3d49a95dea8315bafd24889cb49b6d68ae2ba8f2..765105707b0ff118809a1227c7447aeb7a476a79 100644 (file)
@@ -51,7 +51,7 @@
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/math/vec.h"
 #include "macros.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/random/random.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/pbcutil/rmpbc.h"
index b3f770b86ca31f3c0ebe3209c9f3d0230e58587a..0ebf0826eaa39a85e607c797b871d3a67f7c1b68 100644 (file)
@@ -49,7 +49,7 @@
 #include "gromacs/utility/futil.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/utility/smalloc.h"
 #include "nrnb.h"
 #include "gromacs/math/units.h"
index 1ffdeee686c3d04e09b09bc526cb7b510b8e5520..da05a0157d516cfcb15277a727cf55444b9e9a81 100644 (file)
@@ -48,7 +48,7 @@
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/math/vec.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/fileio/confio.h"
index bc77018c309458cab2b539e8e688c5787e0644f1..5b8c50f6c74510cdee44ce3adeb6124baa664c1d 100644 (file)
@@ -52,7 +52,7 @@
 #include "macros.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/fileio/trnio.h"
 #include "gromacs/fileio/xvgr.h"
index 39b9b1b706bc1092c5b6f1e33110c9927b07e28d..5167a590c239bcee5e39d50cfc38f2d0bd641032 100644 (file)
@@ -49,7 +49,7 @@
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/math/units.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/statistics/statistics.h"
 #include "gmx_ana.h"
 #include "macros.h"
index 768d0f90825ab743e1fcbd254951a550929273e3..1cbd6e8ce7f433cba47bd358991fd877738b0b5a 100644 (file)
@@ -49,7 +49,7 @@
 #include "gstat.h"
 #include "viewit.h"
 #include "gromacs/pbcutil/pbc.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/math/units.h"
index e3205c6ce925b4240b1b30c1be6528ad4b648cbf..c17f5400105a8fd4325499971abeb8e2978beda0 100644 (file)
@@ -48,7 +48,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "txtdump.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
index 67acd98ed27b661a6046a72852a29aaaafa5a462..020c7469472cb18d58b9d6403421580c5f86f17e 100644 (file)
@@ -46,7 +46,7 @@
 #include "gstat.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/math/units.h"
index 9e740d6c3b998c5182348f0b669764c49818dc37..2a0ef2cc0757672aac3238b1dff9dd453ca536d9 100644 (file)
@@ -50,7 +50,7 @@
 #include "txtdump.h"
 #include "gromacs/statistics/statistics.h"
 #include "gstat.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/random/random.h"
 #include "names.h"
 #include "gromacs/math/units.h"
index 1efdfb4170132a5591c837e6c6fdff9c69a2fef3..046c51cf121df3163c2ab011e9e6433237c019a8 100644 (file)
@@ -53,7 +53,7 @@
 #include "gstat.h"
 #include "main.h"
 #include "gromacs/fileio/pdbio.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "mdatoms.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
index 7b0cd1421394b8fdd9f607f9cac73d2cb8ae9512..346bfa03e6cdcb832a6e02140b18b35e03b457f2 100644 (file)
@@ -43,7 +43,7 @@
 #include "typedefs.h"
 #include "macros.h"
 #include "gromacs/fileio/pdbio.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gstat.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
index 104e42260db6039f4affae23361687ecb1c9d111..c695cbe1fb9e042ae66852c8f4d04e62cc347602 100644 (file)
@@ -49,7 +49,6 @@
 #include "macros.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/units.h"
-#include "index.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/commandline/pargs.h"
 #include "txtdump.h"
index cc492abd05d1263dc2053b3f5ac3a825db307b9c..55db291afa4c0681e44d8f712158d9e40e065e8e 100644 (file)
@@ -42,7 +42,7 @@
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/pbcutil/pbc.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
index 9106fa66f4ecdb31709bfa04130faf997e35938f..27a157d521203cdfa6e9e125d922077a16083b2c 100644 (file)
@@ -38,7 +38,7 @@
 #include <config.h>
 #endif
 
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/confio.h"
 #include "gromacs/math/units.h"
 #include "gmx_ana.h"
index 3bf14dbf76ee24a1bdd494bbd84b1657dc5205fb..1c1d18c702266071ad63bb54904eeb84775e9162 100644 (file)
@@ -45,7 +45,7 @@
 #include "gromacs/fileio/confio.h"
 #include "macros.h"
 #include "gromacs/fileio/strdb.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "typedefs.h"
 #include "gromacs/gmxlib/conformation-utilities.h"
 #include "gromacs/math/units.h"
index 51b2fad0d174bc1c236f3f60a8d5b01fad320c52..e51ceff0616594e74f1249f6b64d22b17da9e3c6 100644 (file)
@@ -45,7 +45,7 @@
 #include "gromacs/utility/smalloc.h"
 #include "macros.h"
 #include "gromacs/math/vec.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "princ.h"
index 909e855554da4f569b58c1643c15cc0e62e7916b..7699f36f8dc407765fe905de618920452d8771a3 100644 (file)
@@ -56,7 +56,7 @@
 #include "gromacs/fileio/tpxio.h"
 #include "mdrun.h"
 #include "gromacs/random/random.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gmx_ana.h"
 
 static void insert_ion(int nsa, int *nwater,
index 71d2a2077206d0ee21caba70803a4b50d821956e..4d2891cc13a7aaebb1ccd8f8b6f332a42955798b 100644 (file)
@@ -48,7 +48,7 @@
 #include "gromacs/utility/futil.h"
 #include "macros.h"
 #include "gromacs/math/vec.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gmx_ana.h"
index 6ca8bbff713c3665a2b341cf4c3a9846c6582a53..0ffb34ead55672e657bfb7970dde8088d296b422 100644 (file)
@@ -47,7 +47,7 @@
 #include "macros.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/xvgr.h"
 #include "viewit.h"
 #include "princ.h"
index 7c23c3d9db3b464ce1e3d76634ed36b834dd6ee8..7a47f5c412a4a3833fad7d5040dd7ea7725dabc0 100644 (file)
@@ -51,7 +51,7 @@
 #include "viewit.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/commandline/pargs.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gmx_ana.h"
 #include "gromacs/fileio/trxio.h"
 
index 79a46cb57b9b5eec7bf1b7c3d383dfa2fc2313fb..5c28edf3d9c7a2d1d46d30bb3b294608e2e35eaa 100644 (file)
@@ -47,7 +47,7 @@
 #include "gromacs/math/units.h"
 #include "macros.h"
 #include "gromacs/utility/fatalerror.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/fileio/xvgr.h"
index aa7fd92db96a0784dcbf1c28a421b1615262f1b0..21630d3526571c6da930f960e2548051ed774f56 100644 (file)
@@ -50,7 +50,6 @@
 #include "gromacs/math/utilities.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
-#include "index.h"
 #include "gromacs/utility/smalloc.h"
 #include "txtdump.h"
 #include "typedefs.h"
index 503c2e7016d837bddc7f41c7dc179c1879d2f5e0..6481cd3ed09a71f99d2c068c64a213be7e70961c 100644 (file)
@@ -43,7 +43,7 @@
 #include "typedefs.h"
 #include "macros.h"
 #include "gromacs/math/vec.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gstat.h"
 #include "gmx_ana.h"
 
index 165f388513109177a2f5ac93efd762efaf9938d5..d57a40d998213eb934159d454fea903d39f9da29 100644 (file)
@@ -46,7 +46,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "binsearch.h"
index d376119b95acb7cd8cd9c98bdfd4dd0122efddfa..7340e853cba14436c2144e39b56ab3bf4f3579cb 100644 (file)
@@ -58,7 +58,7 @@
 #include "gromacs/fileio/xvgr.h"
 #include "txtdump.h"
 #include "eigio.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/utility/cstringutil.h"
 
 typedef struct
index 9e3d47739dc2b70e797d30b75f12450aff937ec1..3e48c99a264628710de5ffb8ea09286ef045fbaa 100644 (file)
@@ -45,9 +45,8 @@
 #include "macros.h"
 #include "gromacs/fileio/confio.h"
 #include "typedefs.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/math/vec.h"
-#include "index.h"
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/topology/block.h"
index 1d0473fdcce40a1708effd84e5adf7f6978900fb..46ea9a0a7abe0aed39a2c68c43de3fa41c4e4d76 100644 (file)
@@ -51,7 +51,7 @@
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/fileio/matio.h"
 #include "gromacs/fileio/xvgr.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/pbcutil/rmpbc.h"
index 787a6b0d0948b042f1ada8a49bad14858438d866..c13e907598c98bf30bd0796a7bf1a2b901ae70fd 100644 (file)
@@ -51,7 +51,7 @@
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/commandline/pargs.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/pbcutil/rmpbc.h"
index dadb1590f966fd48fe08db1468ef713c6595a256..e36ebeab79594a18a527e0d047c973848075540e 100644 (file)
@@ -41,7 +41,7 @@
 #include "macros.h"
 #include "gromacs/fileio/confio.h"
 #include "viewit.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gmx_ana.h"
 #include "gromacs/fileio/trxio.h"
 
index bfdbac55aee016782e8797f4b929365b94a61184..0692168a8b4fa6a2187e03aa7b72f6c8d1d212f3 100644 (file)
@@ -44,7 +44,7 @@
 #include "macros.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "typedefs.h"
 #include "viewit.h"
 #include "gstat.h"
index 5497dfd0985bf0478332cf84830c7dc637ca1532..7e2b5f8bde6e59e6407abc344cf4bb1ce86f3440 100644 (file)
@@ -45,7 +45,6 @@
 #include "macros.h"
 #include "copyrite.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
 #include "gstat.h"
 #include "txtdump.h"
 #include "eigio.h"
index 4ddf1300ca0ef69c802fa00ecec7dc67b1526157..f496b4d4d0d61603488240e36c0462acc3f46117 100644 (file)
@@ -48,7 +48,7 @@
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
index b5edf8b564af9219d0dc9890761d08f30416c149..4275f9cc873f90f3a466e29b859cc729a886e167 100644 (file)
@@ -49,7 +49,6 @@
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
index 91f90383ae486bdf4d37c0ad39e50b65f0ddb9c0..b316179423b032f89b02691039faec29bbc4945e 100644 (file)
@@ -48,7 +48,7 @@
 #include "viewit.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/fileio/confio.h"
index 44fe45d299768a0b20ab1dd364781aa7190c3cfd..7d6cacd7aede7f285a943534165f871685af13b9 100644 (file)
@@ -46,7 +46,7 @@
 #include "gromacs/utility/futil.h"
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/math/vec.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "macros.h"
 #include "gromacs/fileio/xvgr.h"
 #include "viewit.h"
index 163522eacddac72e8a928dae4f0ef2addd0a72fa..4957f6eab48223b598a634ae4c1a3d28ab0313c4 100644 (file)
@@ -52,7 +52,7 @@
 #include "viewit.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/commandline/pargs.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gmx_ana.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/fileio/trxio.h"
index a46e1826a216e2bab7992bfaff74b8a9bc833155..72db5d6ba57262164977fc3bb4e252b85f49aa07 100644 (file)
@@ -47,7 +47,7 @@
 #include "macros.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "princ.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "txtdump.h"
index 6cfe0c49977d86316837bbb827c9def11ffc74d1..ab57c674cc4b4d5b3857057d4b460ebb3e887fcc 100644 (file)
@@ -50,7 +50,6 @@
 #include "gromacs/math/units.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/commandline/pargs.h"
-#include "index.h"
 #include "nrama.h"
 #include "gmx_ana.h"
 
index 58c755afa133ffc28b9afc7ff29e64d9bb4d5e76..94f39ab1e0e3a0a1624d13509c81d5ff2147e986 100644 (file)
@@ -49,7 +49,7 @@
 #include "gromacs/utility/futil.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "nrnb.h"
 #include "coulomb.h"
 #include "gstat.h"
index ca69a60ab54ca715e43b8dfd083d530215c9824e..9776ea4af52cba557fd44923083b6bd688add3fb 100644 (file)
@@ -48,7 +48,7 @@
 #include "copyrite.h"
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/math/vec.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "princ.h"
index 4c85111ffb09ba306dcbad674bdf7f437646edbf..4c190b3bfc92afaed662531291845141c7427136 100644 (file)
@@ -50,7 +50,7 @@
 #include "gromacs/fileio/strdb.h"
 #include "gromacs/math/vec.h"
 #include "macros.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/fileio/xvgr.h"
 #include "viewit.h"
index 45e24b622c8244659bca2c98f46ca7214c101e1a..d882951db3843c9a24335b00055455a396b44922 100644 (file)
@@ -47,7 +47,7 @@
 #include "viewit.h"
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/math/vec.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
index 17c92c2c4cd00fdd542220678b868b7a94439fb0..17af340ff78426db81d586b6de23086258f04146 100644 (file)
@@ -43,7 +43,7 @@
 
 #include "typedefs.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "macros.h"
 #include "gstat.h"
 #include "gromacs/math/vec.h"
index c1844bd62f36aaf4f3e7633a45ebe525dc3c56e9..4fcbb79f2e2a08dcde996dc0e3a43b45cc7fa60e 100644 (file)
@@ -45,7 +45,7 @@
 #include "macros.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/xvgr.h"
 #include "viewit.h"
 #include "gromacs/pbcutil/rmpbc.h"
index 75730a68f8aa216300774c3ffbb9a4ddc0ad09e0..a41a8dd18abf1c944a8342a8cf48b3e7a894a109 100644 (file)
@@ -41,7 +41,7 @@
 #include "macros.h"
 #include "gromacs/math/vec.h"
 #include "copyrite.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gstat.h"
 #include "gmx_ana.h"
 #include "nsfactor.h"
index 1e1f75cd8a52c4a4da669b86fb8d3551f4b119cf..8f94c4175a4eaf6d2db6332bfa6fd27700faaed0 100644 (file)
@@ -43,7 +43,7 @@
 #include "gromacs/math/vec.h"
 #include "viewit.h"
 #include "gromacs/pbcutil/pbc.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gmx_ana.h"
index 9293e30f6cbb9b5a50d3e5efbdae3761f5193617..640541c090ecc520db5599516a79ed0a1c208da6 100644 (file)
@@ -45,7 +45,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/pbcutil/rmpbc.h"
 #include "gmx_ana.h"
index afc8560e8e71e1d2f64b000792798154a088ba9b..e526dc10627c8d8f9ef67fac2a6b886f6651d02c 100644 (file)
@@ -42,7 +42,7 @@
 #include "gstat.h"
 #include "viewit.h"
 #include "gromacs/pbcutil/pbc.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
 #include "gromacs/math/units.h"
index 2a000147f40aa4a37399f652ee3e8b92aab1291e..8435a86280b0a5272ed68afc4b92e49c47895d5a 100644 (file)
@@ -49,7 +49,7 @@
 #include "macros.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/units.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/commandline/pargs.h"
 #include "txtdump.h"
index 3f4a2e0e4decd9fc9db99c2f540d6a65bac23c2e..b0182605931669faf01b0af86fc533db9c5607d2 100644 (file)
@@ -48,7 +48,7 @@
 #include "macros.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/xvgr.h"
 #include "viewit.h"
 #include "gromacs/fileio/tpxio.h"
index ce279a078f622dc86c7d02f0185252aca756883d..fee1ce8020c1e910d099f05b0e6eee0dc78a32aa 100644 (file)
@@ -56,7 +56,7 @@
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/fileio/confio.h"
 #include "names.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/fileio/xtcio.h"
 #include "gromacs/fileio/xvgr.h"
index 62726f169ba85cfa92a9639636435577b0fd046d..2c52f8e85efcb906681d831f5dd1087bca73d6f6 100644 (file)
@@ -54,7 +54,7 @@
 #include "gromacs/fileio/pdbio.h"
 #include "gromacs/fileio/confio.h"
 #include "names.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/fileio/xtcio.h"
 #include "viewit.h"
index 9f17214b9695395707261a7fcf15748159b5781f..a9c2622785bf3344763b587cff905d0a9fd0e9e2 100644 (file)
@@ -49,7 +49,7 @@
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/xvgr.h"
 
 #include "gromacs/pbcutil/rmpbc.h"
index 640d786db9000a5dbbf731f11a837e29bf90b4de..8d773d91099e59ea2800426d2566e10da651e98c 100644 (file)
@@ -48,7 +48,7 @@
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/utility/futil.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "typedefs.h"
 #include "gromacs/fileio/xvgr.h"
 #include "viewit.h"
index 1a86e56b282c91dc37a0ea815b5e324d4dc2a905..4103fc84f64a48847510ff39f35e8c30822ef3e5 100644 (file)
@@ -49,7 +49,7 @@
 #include "macros.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/units.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/commandline/pargs.h"
 #include "txtdump.h"
index 25768eff358eebd594a3d6a279ec3e4562487afb..146756b7cd543940e603fdfc6ab781bb72b08857 100644 (file)
@@ -47,7 +47,6 @@
 #include "gromacs/utility/smalloc.h"
 #include "macros.h"
 #include "gromacs/math/vec.h"
-#include "index.h"
 #include "gstat.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gmx_ana.h"
index 959a86d937d65930dabee641731c9262ca040d5d..7bfb9a257d04f876d663d1778f34a70e9a9fcbbb 100644 (file)
 #define GMX_GMXANA_GSTAT_H
 
 #include "../legacyheaders/typedefs.h"
-#include "../commandline/pargs.h"
 #include "../legacyheaders/oenv.h"
-#include "../legacyheaders/index.h"
+#include "../commandline/pargs.h"
+#include "../topology/index.h"
+#include "../topology/residuetypes.h"
 
 #ifdef __cplusplus
 extern "C" {
index 5a999cec6655af0c7cac25bfd6a7590f65be86dc..776b26ff440834bab5d6a69690cc249ea50674eb 100644 (file)
@@ -45,7 +45,7 @@
 #include "macros.h"
 #include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "hxprops.h"
 #include "gromacs/utility/smalloc.h"
 #include "bondf.h"
index ebe6b808745dafe5cfc91273b72fea6382baaa32..c833a5521de8467d88d903b7d09d374d3e85c1c5 100644 (file)
@@ -36,7 +36,6 @@
 #ifndef _nsfactor_h
 #define _nsfactor_h
 
-#include "gromacs/legacyheaders/index.h"
 #include "gromacs/legacyheaders/oenv.h"
 #include "gromacs/legacyheaders/types/simple.h"
 
index fdc251882d5a175d1fce325a1d223cc0972d3048..e6e5a35b342633101408c29bcb5a4fbc4c2c214a 100644 (file)
@@ -44,7 +44,7 @@
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/math/vec.h"
 #include "macros.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/fileio/strdb.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
index 6eae7881167c3c42a25b9d14a904634554044fca..d9099a8bd3fd934cee350ad5d16a460c62e6d74f 100644 (file)
@@ -37,7 +37,6 @@
 #ifndef _sfactor_h
 #define _sfactor_h
 
-#include "index.h"
 #include "types/simple.h"
 #include "../math/gmxcomplex.h"
 #include "oenv.h"
index f0a69ab6ff78f99582d3de818eff44b0da8a2f8b..c3cdddb5976215c45a02f8239e03a5ec66a8e9ef 100644 (file)
 #include "gromacs/math/vec.h"
 #include "toputil.h"
 #include "gromacs/math/units.h"
-#include "index.h"
 #include "names.h"
 #include "gromacs/utility/futil.h"
 #include "gpp_atomtype.h"
 #include "fflibutil.h"
 
+#include "gromacs/topology/residuetypes.h"
 #include "gromacs/topology/symtab.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
index 1cfeba8e7b2f82e448b3fed82f0d519dc01fd4c3..2eef5b7b63baf691e67e63330d927c7fda4ff653 100644 (file)
@@ -62,7 +62,6 @@
 #include "gromacs/gmxpreprocess/sortwater.h"
 #include "convparm.h"
 #include "warninp.h"
-#include "index.h"
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/trnio.h"
 #include "gromacs/fileio/tpxio.h"
index db0a5412560a6aec35b301cc68bc734de6b3f5a2..cf0bc05f2fcfc1d0401cab1326c062447c908be9 100644 (file)
@@ -62,7 +62,7 @@
 #include "gromacs/gmxlib/conformation-utilities.h"
 #include "genhydro.h"
 #include "readinp.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "fflibutil.h"
 #include "macros.h"
 
@@ -70,6 +70,8 @@
 #include "gromacs/fileio/strdb.h"
 #include "gromacs/topology/atomprop.h"
 #include "gromacs/topology/block.h"
+#include "gromacs/topology/index.h"
+#include "gromacs/topology/residuetypes.h"
 #include "gromacs/topology/symtab.h"
 #include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/fatalerror.h"
index f660c51f1f8b218b7b67a254855d13a33872210a..676ba94c42dd60d9a053067411ea0f4b28093a83 100644 (file)
@@ -57,7 +57,6 @@
 #include "gromacs/fileio/pdbio.h"
 #include "gen_ad.h"
 #include "gromacs/fileio/filenm.h"
-#include "index.h"
 #include "gen_vsite.h"
 #include "add_par.h"
 #include "toputil.h"
@@ -65,6 +64,7 @@
 #include "copyrite.h"
 
 #include "gromacs/fileio/strdb.h"
+#include "gromacs/topology/residuetypes.h"
 #include "gromacs/topology/symtab.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/fatalerror.h"
index 7f2970bb28f161174b04f3a75f9c104abf3ab0dd..5f10cc499d4050d38a135225d28eaddda7cb7a41 100644 (file)
@@ -50,7 +50,7 @@
 #include "genhydro.h"
 #include "gromacs/fileio/tpxio.h"
 #include "gromacs/fileio/trxio.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/math/vec.h"
 #include "hackblock.h"
 
index 3d560b9330f5e02c7cedfe6bb9532652fc915ae2..b8e9e6d9b8bb623b11a16a5a12be482f2c834c3c 100644 (file)
 #include "gromacs/math/units.h"
 #include "names.h"
 #include "macros.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/utility/cstringutil.h"
 #include "readinp.h"
 #include "warninp.h"
 #include "readir.h"
 #include "toputil.h"
-#include "index.h"
 #include "network.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/pbc.h"
index da3dedec0306861eae1f6fd1c8a688d50854918d..0e9706a7aea58d90b1f12e3b280bfe377b2b3ee2 100644 (file)
@@ -49,7 +49,6 @@
 #include "names.h"
 #include "gromacs/utility/fatalerror.h"
 #include "macros.h"
-#include "index.h"
 #include "readinp.h"
 #include "readir.h"
 #include "mdatoms.h"
index 773266ae92c27676385bac16a503490cfe0d0acb..6b8daa9919fc53ee5887813510caa1e5aa5c931b 100644 (file)
@@ -50,7 +50,6 @@
 #include "gromacs/math/vec.h"
 #include "toputil.h"
 #include "gromacs/math/units.h"
-#include "index.h"
 #include "names.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/cstringutil.h"
index f98cc2a09b0cc8b98a966045b247a23317614bc8..b9400345dd1a851aad6f5cc1dffa659ff27f51d7 100644 (file)
 #include <string.h>
 
 #include "typedefs.h"
-#include "index.h"
 #include "fflibutil.h"
 #include "hackblock.h"
 #include "xlate.h"
 
 #include "gromacs/fileio/strdb.h"
+#include "gromacs/topology/residuetypes.h"
 #include "gromacs/topology/symtab.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
index 892569fb6c4487eb388ba71da6a3c1e4ce1f0aa5..9ed45b9b75a5f5579443c8deb7dbcbbd91ba09e1 100644 (file)
@@ -38,7 +38,7 @@
 #ifndef GMX_GMXPREPROCESS_XLATE_H
 #define GMX_GMXPREPROCESS_XLATE_H
 
-#include "index.h"
+#include "gromacs/topology/residuetypes.h"
 
 #ifdef __cplusplus
 extern "C" {
index ea365d2773b8f5fbf372e54537cdf1ef0789fcdc..4c0153b834b65a72d891c1db069715bc44883ba1 100644 (file)
@@ -67,6 +67,7 @@ namespace gmx
 
 class AbstractOptionStorage;
 template <typename T> class OptionStorageTemplate;
+class OptionManagerContainer;
 class Options;
 
 //! Smart pointer for managing an AbstractOptionStorage object.
@@ -108,8 +109,10 @@ class AbstractOption
         /*! \brief
          * Creates a default storage object for the option.
          *
-         * \returns The created storage object.
-         * \throws  APIError if invalid option settings have been provided.
+         * \param[in] managers  Manager container (unused if the option does
+         *     not use a manager).
+         * \returns   The created storage object.
+         * \throws    APIError if invalid option settings have been provided.
          *
          * This method is called by Options::addOption() when initializing an
          * option from the settings.
@@ -120,7 +123,8 @@ class AbstractOption
          *
          * Should only be called by Options::addOption().
          */
-        virtual AbstractOptionStoragePointer createStorage() const = 0;
+        virtual AbstractOptionStoragePointer createStorage(
+            const OptionManagerContainer &managers) const = 0;
 
         //! Sets the description for the option.
         void setDescription(const char *descr) { descr_ = descr; }
index f1af57aa32bed7ea3c075503fbfb457b610b6b42..205a3c102334b72dd5ca6e5dc83fce4a69df175b 100644 (file)
@@ -138,7 +138,8 @@ bool BooleanOptionInfo::defaultValue() const
  * BooleanOption
  */
 
-AbstractOptionStoragePointer BooleanOption::createStorage() const
+AbstractOptionStoragePointer
+BooleanOption::createStorage(const OptionManagerContainer & /*managers*/) const
 {
     return AbstractOptionStoragePointer(new BooleanOptionStorage(*this));
 }
@@ -195,7 +196,8 @@ IntegerOptionInfo::IntegerOptionInfo(IntegerOptionStorage *option)
  * IntegerOption
  */
 
-AbstractOptionStoragePointer IntegerOption::createStorage() const
+AbstractOptionStoragePointer
+IntegerOption::createStorage(const OptionManagerContainer & /*managers*/) const
 {
     return AbstractOptionStoragePointer(new IntegerOptionStorage(*this));
 }
@@ -242,7 +244,8 @@ Int64OptionInfo::Int64OptionInfo(Int64OptionStorage *option)
  * Int64Option
  */
 
-AbstractOptionStoragePointer Int64Option::createStorage() const
+AbstractOptionStoragePointer
+Int64Option::createStorage(const OptionManagerContainer & /*managers*/) const
 {
     return AbstractOptionStoragePointer(new Int64OptionStorage(*this));
 }
@@ -343,7 +346,8 @@ void DoubleOptionInfo::setScaleFactor(double factor)
  * DoubleOption
  */
 
-AbstractOptionStoragePointer DoubleOption::createStorage() const
+AbstractOptionStoragePointer
+DoubleOption::createStorage(const OptionManagerContainer & /*managers*/) const
 {
     return AbstractOptionStoragePointer(new DoubleOptionStorage(*this));
 }
@@ -446,7 +450,8 @@ void FloatOptionInfo::setScaleFactor(double factor)
  * FloatOption
  */
 
-AbstractOptionStoragePointer FloatOption::createStorage() const
+AbstractOptionStoragePointer
+FloatOption::createStorage(const OptionManagerContainer & /*managers*/) const
 {
     return AbstractOptionStoragePointer(new FloatOptionStorage(*this));
 }
@@ -631,7 +636,8 @@ const std::vector<std::string> &StringOptionInfo::allowedValues() const
  * StringOption
  */
 
-AbstractOptionStoragePointer StringOption::createStorage() const
+AbstractOptionStoragePointer
+StringOption::createStorage(const OptionManagerContainer & /*managers*/) const
 {
     return AbstractOptionStoragePointer(new StringOptionStorage(*this));
 }
index 35e91cc817ddb6145a87399a97baf1ea5cf5a578..992d19ed009db906e9fb5f092302b4a3cd4b655e 100644 (file)
@@ -98,7 +98,8 @@ class BooleanOption : public OptionTemplate<bool, BooleanOption>
 
     private:
         //! Creates a BooleanOptionStorage object.
-        virtual AbstractOptionStoragePointer createStorage() const;
+        virtual AbstractOptionStoragePointer createStorage(
+            const OptionManagerContainer &managers) const;
 };
 
 /*! \brief
@@ -140,7 +141,8 @@ class IntegerOption : public OptionTemplate<int, IntegerOption>
 
     private:
         //! Creates an IntegerOptionStorage object.
-        virtual AbstractOptionStoragePointer createStorage() const;
+        virtual AbstractOptionStoragePointer createStorage(
+            const OptionManagerContainer &managers) const;
 
         /*! \brief
          * Needed to initialize IntegerOptionStorage from this class without
@@ -169,7 +171,8 @@ class Int64Option : public OptionTemplate<gmx_int64_t, Int64Option>
 
     private:
         //! Creates an Int64OptionStorage object.
-        virtual AbstractOptionStoragePointer createStorage() const;
+        virtual AbstractOptionStoragePointer createStorage(
+            const OptionManagerContainer &managers) const;
 
         /*! \brief
          * Needed to initialize Int64OptionStorage from this class without
@@ -214,7 +217,8 @@ class DoubleOption : public OptionTemplate<double, DoubleOption>
 
     private:
         //! Creates a DoubleOptionStorage object.
-        virtual AbstractOptionStoragePointer createStorage() const;
+        virtual AbstractOptionStoragePointer createStorage(
+            const OptionManagerContainer &managers) const;
 
         bool bTime_;
 
@@ -252,7 +256,8 @@ class FloatOption : public OptionTemplate<float, FloatOption>
 
     private:
         //! Creates a FloatOptionStorage object.
-        virtual AbstractOptionStoragePointer createStorage() const;
+        virtual AbstractOptionStoragePointer createStorage(
+            const OptionManagerContainer &managers) const;
 
         bool bTime_;
 
@@ -372,7 +377,8 @@ class StringOption : public OptionTemplate<std::string, StringOption>
 
     private:
         //! Creates a StringOptionStorage object.
-        virtual AbstractOptionStoragePointer createStorage() const;
+        virtual AbstractOptionStoragePointer createStorage(
+            const OptionManagerContainer &managers) const;
 
         const char *const      *enumValues_;
         int                     enumValuesCount_;
index 37d3a6a0ccc0036a1bfc95e00c8b5d5035dad0c8..e821eed476488882f5aada88c03777fc4d5c02cd 100644 (file)
 #include "filenameoption.h"
 #include "filenameoptionstorage.h"
 
+#include <cstring>
+
 #include <string>
 #include <vector>
 
 #include "gromacs/fileio/filenm.h"
 #include "gromacs/options/filenameoptionmanager.h"
+#include "gromacs/options/optionmanagercontainer.h"
 #include "gromacs/utility/arrayref.h"
 #include "gromacs/utility/file.h"
 #include "gromacs/utility/gmxassert.h"
@@ -58,26 +61,60 @@ namespace gmx
 namespace
 {
 
-class FileTypeRegistry;
-
 //! \addtogroup module_options
 //! \{
 
-//! Shorthand for a list of file extensions.
-typedef std::vector<const char *> ExtensionList;
+/*! \brief
+ * Mapping from OptionFileType to a file type in filenm.h.
+ */
+struct FileTypeMapping
+{
+    //! OptionFileType value to map.
+    OptionFileType optionType;
+    //! Corresponding file type from filenm.h.
+    int            fileType;
+};
+
+//! Mappings from OptionFileType to file types in filenm.h.
+const FileTypeMapping c_fileTypeMapping[] =
+{
+    { eftTopology,    efTPS },
+    { eftTrajectory,  efTRX },
+    { eftPDB,         efPDB },
+    { eftIndex,       efNDX },
+    { eftPlot,        efXVG },
+    { eftGenericData, efDAT }
+};
+
+//! Extensions that are recognized as compressed files.
+const char *const c_compressedExtensions[] =
+{ ".gz", ".Z" };
 
 /********************************************************************
  * FileTypeHandler
  */
 
-/*! \internal \brief
+/*! \internal
+ * \brief
  * Handles a single file type known to FileNameOptionStorage.
+ *
+ * Methods in this class do not throw, except for a possible std::bad_alloc
+ * when constructing std::string return values.
  */
 class FileTypeHandler
 {
     public:
-        //! Returns the list of extensions for this file type.
-        const ExtensionList &extensions() const { return extensions_; }
+        /*! \brief
+         * Returns a handler for a single file type.
+         *
+         * \param[in] fileType  File type (from filenm.h) to use.
+         */
+        explicit FileTypeHandler(int fileType);
+
+        //! Returns the number of acceptable extensions for this file type.
+        int extensionCount() const;
+        //! Returns the extension with the given index.
+        const char *extension(int i) const;
 
         //! Returns whether \p filename has a valid extension for this type.
         bool hasKnownExtension(const std::string &filename) const;
@@ -94,168 +131,125 @@ class FileTypeHandler
         std::string findFileWithExtension(const std::string &filename) const;
 
     private:
-        //! Possible extensions for this file type.
-        ExtensionList extensions_;
-
         /*! \brief
-         * Needed for initialization; all initialization is handled by
-         * FileTypeRegistry.
+         * File type (from filenm.h) represented by this handler.
+         *
+         * -1 represents an unknown file type.
+         */
+        int        fileType_;
+        //! Number of different extensions this type supports.
+        int        extensionCount_;
+        /*! \brief
+         * List of simple file types that are included in this type.
+         *
+         * If `fileType_` represents a generic type in filenm.h, i.e., a type
+         * that accepts multiple different types of files, then this is an
+         * array of `extensionCount_` elements, each element specifying one
+         * non-generic file type that this option accepts.
+         * `NULL` for single-extension types.
          */
-        friend class FileTypeRegistry;
+        const int *genericTypes_;
 };
 
-bool
-FileTypeHandler::hasKnownExtension(const std::string &filename) const
+FileTypeHandler::FileTypeHandler(int fileType)
+    : fileType_(fileType), extensionCount_(0), genericTypes_(NULL)
 {
-    for (size_t i = 0; i < extensions_.size(); ++i)
+    if (fileType_ >= 0)
     {
-        if (endsWith(filename, extensions_[i]))
+        const int genericTypeCount = ftp2generic_count(fileType_);
+        if (genericTypeCount > 0)
         {
-            return true;
+            extensionCount_ = genericTypeCount;
+            genericTypes_   = ftp2generic_list(fileType_);
+        }
+        else if (ftp2ext_with_dot(fileType_)[0] != '\0')
+        {
+            extensionCount_ = 1;
         }
     }
-    return false;
 }
 
-std::string
-FileTypeHandler::addExtension(const std::string &filename) const
+int FileTypeHandler::extensionCount() const
 {
-    if (extensions_.empty())
-    {
-        return filename;
-    }
-    return filename + extensions_[0];
+    return extensionCount_;
 }
 
-std::string
-FileTypeHandler::findFileWithExtension(const std::string &filename) const
+const char *FileTypeHandler::extension(int i) const
 {
-    for (size_t i = 0; i < extensions_.size(); ++i)
+    GMX_ASSERT(i >= 0 && i < extensionCount_, "Invalid extension index");
+    if (genericTypes_ != NULL)
     {
-        std::string testFilename(filename + extensions_[i]);
-        if (File::exists(testFilename))
-        {
-            return testFilename;
-        }
+        return ftp2ext_with_dot(genericTypes_[i]);
     }
-    return std::string();
+    return ftp2ext_with_dot(fileType_);
 }
 
-/********************************************************************
- * FileTypeRegistry
- */
-
-/*! \internal \brief
- * Singleton for managing static file type info for FileNameOptionStorage.
- */
-class FileTypeRegistry
-{
-    public:
-        //! Returns a singleton instance of this class.
-        static const FileTypeRegistry &instance();
-        //! Returns a handler for a single file type.
-        const FileTypeHandler &
-        handlerForType(OptionFileType type, int legacyType) const;
-
-    private:
-        //! Initializes the file type registry.
-        FileTypeRegistry();
-
-        //! Registers a file type that corresponds to a ftp in filenm.h.
-        void registerType(int type, int ftp);
-        //! Registers a file type with a single extension.
-        void registerType(int type, const char *extension);
-
-        std::vector<FileTypeHandler> filetypes_;
-};
-
-// static
-const FileTypeRegistry &
-FileTypeRegistry::instance()
-{
-    static FileTypeRegistry singleton;
-    return singleton;
-}
-
-const FileTypeHandler &
-FileTypeRegistry::handlerForType(OptionFileType type, int legacyType) const
+bool
+FileTypeHandler::hasKnownExtension(const std::string &filename) const
 {
-    int index = type;
-    if (type == eftUnknown && legacyType >= 0)
+    for (int i = 0; i < extensionCount(); ++i)
     {
-        index = eftOptionFileType_NR + legacyType;
+        if (endsWith(filename, extension(i)))
+        {
+            return true;
+        }
     }
-    GMX_RELEASE_ASSERT(index >= 0 && static_cast<size_t>(index) < filetypes_.size(),
-                       "Invalid file type");
-    return filetypes_[index];
+    return false;
 }
 
-FileTypeRegistry::FileTypeRegistry()
+std::string
+FileTypeHandler::addExtension(const std::string &filename) const
 {
-    filetypes_.resize(eftOptionFileType_NR + efNR);
-    registerType(eftTopology,    efTPS);
-    registerType(eftTrajectory,  efTRX);
-    registerType(eftPDB,         efPDB);
-    registerType(eftIndex,       efNDX);
-    registerType(eftPlot,        efXVG);
-    registerType(eftGenericData, efDAT);
-    for (int i = 0; i < efNR; ++i)
+    if (extensionCount() == 0)
     {
-        registerType(eftOptionFileType_NR + i, i);
+        return filename;
     }
+    return filename + extension(0);
 }
 
-void FileTypeRegistry::registerType(int type, int ftp)
+std::string
+FileTypeHandler::findFileWithExtension(const std::string &filename) const
 {
-    GMX_RELEASE_ASSERT(type >= 0 && static_cast<size_t>(type) < filetypes_.size(),
-                       "Invalid file type");
-    const int genericTypeCount = ftp2generic_count(ftp);
-    if (genericTypeCount > 0)
+    for (int i = 0; i < extensionCount(); ++i)
     {
-        const int *const genericTypes = ftp2generic_list(ftp);
-        filetypes_[type].extensions_.clear();
-        filetypes_[type].extensions_.reserve(genericTypeCount);
-        for (int i = 0; i < genericTypeCount; ++i)
+        std::string testFilename(filename + extension(i));
+        if (File::exists(testFilename))
         {
-            filetypes_[type].extensions_.push_back(ftp2ext_with_dot(genericTypes[i]));
+            return testFilename;
         }
     }
-    else
-    {
-        registerType(type, ftp2ext_with_dot(ftp));
-    }
-}
-
-void FileTypeRegistry::registerType(int type, const char *extension)
-{
-    GMX_RELEASE_ASSERT(type >= 0 && static_cast<size_t>(type) < filetypes_.size(),
-                       "Invalid file type");
-    filetypes_[type].extensions_.assign(1, extension);
+    return std::string();
 }
 
 /*! \brief
  * Helper method to complete a file name provided to a file name option.
  *
- * \param[in] value      Value provided to the file name option.
- * \param[in] filetype   File type for the option.
- * \param[in] legacyType If \p filetype is eftUnknown, this gives the type as
- *     an enum value from filenm.h.
+ * \param[in] value       Value provided to the file name option.
+ * \param[in] typeHandler Handler for the file type.
  * \param[in] bCompleteToExisting
  *     Whether to check existing files when completing the extension.
  * \returns   \p value with possible extension added.
  */
-std::string completeFileName(const std::string &value, OptionFileType filetype,
-                             int legacyType, bool bCompleteToExisting)
+std::string completeFileName(const std::string     &value,
+                             const FileTypeHandler &typeHandler,
+                             bool                   bCompleteToExisting)
 {
     if (bCompleteToExisting && File::exists(value))
     {
         // TODO: This may not work as expected if the value is passed to a
         // function that uses fn2ftp() to determine the file type and the input
         // file has an unrecognized extension.
+        ConstArrayRef<const char *>                 compressedExtensions(c_compressedExtensions);
+        ConstArrayRef<const char *>::const_iterator ext;
+        for (ext = compressedExtensions.begin(); ext != compressedExtensions.end(); ++ext)
+        {
+            if (endsWith(value, *ext))
+            {
+                return value.substr(0, value.length() - std::strlen(*ext));
+            }
+        }
         return value;
     }
-    const FileTypeRegistry &registry    = FileTypeRegistry::instance();
-    const FileTypeHandler  &typeHandler = registry.handlerForType(filetype, legacyType);
     if (typeHandler.hasKnownExtension(value))
     {
         return value;
@@ -279,60 +273,63 @@ std::string completeFileName(const std::string &value, OptionFileType filetype,
  * FileNameOptionStorage
  */
 
-FileNameOptionStorage::FileNameOptionStorage(const FileNameOption &settings)
-    : MyBase(settings), info_(this), manager_(NULL),
-      filetype_(settings.filetype_), legacyType_(settings.legacyType_),
+FileNameOptionStorage::FileNameOptionStorage(const FileNameOption  &settings,
+                                             FileNameOptionManager *manager)
+    : MyBase(settings), info_(this), manager_(manager), fileType_(-1),
       bRead_(settings.bRead_), bWrite_(settings.bWrite_),
       bLibrary_(settings.bLibrary_)
 {
     GMX_RELEASE_ASSERT(!hasFlag(efOption_MultipleTimes),
                        "allowMultiple() is not supported for file name options");
+    if (settings.optionType_ == eftUnknown && settings.legacyType_ >= 0)
+    {
+        fileType_ = settings.legacyType_;
+    }
+    else
+    {
+        ConstArrayRef<FileTypeMapping>                 map(c_fileTypeMapping);
+        ConstArrayRef<FileTypeMapping>::const_iterator i;
+        for (i = map.begin(); i != map.end(); ++i)
+        {
+            if (i->optionType == settings.optionType_)
+            {
+                fileType_ = i->fileType;
+                break;
+            }
+        }
+    }
     if (settings.defaultBasename_ != NULL)
     {
-        std::string defaultValue =
-            completeFileName(settings.defaultBasename_, filetype_,
-                             legacyType_, false);
+        std::string defaultValue(settings.defaultBasename_);
+        defaultValue.append(defaultExtension());
         setDefaultValueIfSet(defaultValue);
-        if (isRequired())
+        if (isRequired() || settings.bLegacyOptionalBehavior_)
         {
             setDefaultValue(defaultValue);
         }
     }
 }
 
-void FileNameOptionStorage::setManager(FileNameOptionManager *manager)
-{
-    GMX_RELEASE_ASSERT(manager_ == NULL || manager_ == manager,
-                       "Manager cannot be changed once set");
-    if (manager_ == NULL)
-    {
-        manager_ = manager;
-    }
-}
-
 std::string FileNameOptionStorage::typeString() const
 {
-    const FileTypeRegistry       &registry    = FileTypeRegistry::instance();
-    const FileTypeHandler        &typeHandler = registry.handlerForType(filetype_, legacyType_);
-    const ExtensionList          &extensions  = typeHandler.extensions();
-    std::string                   result;
-    ExtensionList::const_iterator i;
-    int                           count = 0;
-    for (i = extensions.begin(); count < 2 && i != extensions.end(); ++i, ++count)
+    FileTypeHandler typeHandler(fileType_);
+    std::string     result;
+    int             count;
+    for (count = 0; count < 2 && count < typeHandler.extensionCount(); ++count)
     {
-        if (i != extensions.begin())
+        if (count > 0)
         {
             result.append("/");
         }
-        result.append(*i);
+        result.append(typeHandler.extension(count));
     }
-    if (i != extensions.end())
+    if (count < typeHandler.extensionCount())
     {
         result.append("/...");
     }
     if (result.empty())
     {
-        if (legacyType_ == efRND)
+        if (isDirectoryOption())
         {
             result = "dir";
         }
@@ -346,18 +343,16 @@ std::string FileNameOptionStorage::typeString() const
 
 std::string FileNameOptionStorage::formatExtraDescription() const
 {
-    const FileTypeRegistry       &registry    = FileTypeRegistry::instance();
-    const FileTypeHandler        &typeHandler = registry.handlerForType(filetype_, legacyType_);
-    const ExtensionList          &extensions  = typeHandler.extensions();
-    std::string                   result;
-    if (extensions.size() > 2)
+    FileTypeHandler typeHandler(fileType_);
+    std::string     result;
+    if (typeHandler.extensionCount() > 2)
     {
         result.append(":");
-        ExtensionList::const_iterator i;
-        for (i = extensions.begin(); i != extensions.end(); ++i)
+        for (int i = 0; i < typeHandler.extensionCount(); ++i)
         {
             result.append(" ");
-            result.append((*i) + 1);
+            // Skip the dot.
+            result.append(typeHandler.extension(i) + 1);
         }
     }
     return result;
@@ -370,32 +365,33 @@ std::string FileNameOptionStorage::formatSingleValue(const std::string &value) c
 
 void FileNameOptionStorage::convertValue(const std::string &value)
 {
-    bool bInput = isInputFile() || isInputOutputFile();
-    addValue(completeFileName(value, filetype_, legacyType_, bInput));
+    const bool      bInput = isInputFile() || isInputOutputFile();
+    FileTypeHandler typeHandler(fileType_);
+    addValue(completeFileName(value, typeHandler, bInput));
 }
 
 void FileNameOptionStorage::processAll()
 {
-    if (hasFlag(efOption_HasDefaultValue))
+    FileTypeHandler typeHandler(fileType_);
+    if (hasFlag(efOption_HasDefaultValue) && typeHandler.extensionCount() > 0)
     {
-        const bool              bInput      = isInputFile() || isInputOutputFile();
-        const FileTypeRegistry &registry    = FileTypeRegistry::instance();
-        const FileTypeHandler  &typeHandler = registry.handlerForType(filetype_, legacyType_);
-        const ExtensionList    &extensions  = typeHandler.extensions();
-        ValueList              &valueList   = values();
+        const bool  bInput      = isInputFile() || isInputOutputFile();
+        ValueList  &valueList   = values();
         GMX_RELEASE_ASSERT(valueList.size() == 1,
                            "There should be only one default value");
-        const bool              bGlobalDefault =
+        const bool  bGlobalDefault =
             (manager_ != NULL && !manager_->defaultFileName().empty());
-        if (!valueList[0].empty() && (extensions.size() > 1 || bGlobalDefault))
+        if (!valueList[0].empty() && (typeHandler.extensionCount() > 1 || bGlobalDefault))
         {
-            std::string oldValue = valueList[0];
-            std::string newValue = stripSuffixIfPresent(oldValue, extensions[0]);
+            const std::string &oldValue = valueList[0];
+            GMX_ASSERT(endsWith(oldValue, defaultExtension()),
+                       "Default value does not have the expected extension");
+            std::string prefix = stripSuffixIfPresent(oldValue, defaultExtension());
             if (bGlobalDefault)
             {
-                newValue = manager_->defaultFileName();
+                prefix = manager_->defaultFileName();
             }
-            newValue = completeFileName(newValue, filetype_, legacyType_, bInput);
+            std::string newValue = completeFileName(prefix, typeHandler, bInput);
             if (newValue != oldValue)
             {
                 valueList[0] = newValue;
@@ -407,15 +403,29 @@ void FileNameOptionStorage::processAll()
 
 bool FileNameOptionStorage::isDirectoryOption() const
 {
-    return legacyType_ == efRND;
+    return fileType_ == efRND;
 }
 
-ConstArrayRef<const char *> FileNameOptionStorage::extensions() const
+const char *FileNameOptionStorage::defaultExtension() const
 {
-    const FileTypeRegistry &registry    = FileTypeRegistry::instance();
-    const FileTypeHandler  &typeHandler = registry.handlerForType(filetype_, legacyType_);
-    const ExtensionList    &extensions  = typeHandler.extensions();
-    return ConstArrayRef<const char *>(extensions.begin(), extensions.end());
+    FileTypeHandler typeHandler(fileType_);
+    if (typeHandler.extensionCount() == 0)
+    {
+        return "";
+    }
+    return typeHandler.extension(0);
+}
+
+std::vector<const char *> FileNameOptionStorage::extensions() const
+{
+    FileTypeHandler           typeHandler(fileType_);
+    std::vector<const char *> result;
+    result.reserve(typeHandler.extensionCount());
+    for (int i = 0; i < typeHandler.extensionCount(); ++i)
+    {
+        result.push_back(typeHandler.extension(i));
+    }
+    return result;
 }
 
 /********************************************************************
@@ -427,21 +437,11 @@ FileNameOptionInfo::FileNameOptionInfo(FileNameOptionStorage *option)
 {
 }
 
-FileNameOptionStorage &FileNameOptionInfo::option()
-{
-    return static_cast<FileNameOptionStorage &>(OptionInfo::option());
-}
-
 const FileNameOptionStorage &FileNameOptionInfo::option() const
 {
     return static_cast<const FileNameOptionStorage &>(OptionInfo::option());
 }
 
-void FileNameOptionInfo::setManager(FileNameOptionManager *manager)
-{
-    option().setManager(manager);
-}
-
 bool FileNameOptionInfo::isInputFile() const
 {
     return option().isInputFile();
@@ -467,6 +467,11 @@ bool FileNameOptionInfo::isDirectoryOption() const
     return option().isDirectoryOption();
 }
 
+const char *FileNameOptionInfo::defaultExtension() const
+{
+    return option().defaultExtension();
+}
+
 FileNameOptionInfo::ExtensionList FileNameOptionInfo::extensions() const
 {
     return option().extensions();
@@ -476,9 +481,11 @@ FileNameOptionInfo::ExtensionList FileNameOptionInfo::extensions() const
  * FileNameOption
  */
 
-AbstractOptionStoragePointer FileNameOption::createStorage() const
+AbstractOptionStoragePointer
+FileNameOption::createStorage(const OptionManagerContainer &managers) const
 {
-    return AbstractOptionStoragePointer(new FileNameOptionStorage(*this));
+    return AbstractOptionStoragePointer(
+            new FileNameOptionStorage(*this, managers.get<FileNameOptionManager>()));
 }
 
 } // namespace gmx
index c00e71254d4120e357d140acdd7f55e06c20ecfa..d8843cb38c3154867581ad414899fcb5a9b20259 100644 (file)
@@ -44,6 +44,7 @@
 #define GMX_OPTIONS_FILENAMEOPTION_H
 
 #include <string>
+#include <vector>
 
 #include "abstractoption.h"
 #include "optionfiletype.h"
@@ -72,8 +73,8 @@ class FileNameOption : public OptionTemplate<std::string, FileNameOption>
 
         //! Initializes an option with the given name.
         explicit FileNameOption(const char *name)
-            : MyBase(name), filetype_(eftUnknown), legacyType_(-1),
-              defaultBasename_(NULL),
+            : MyBase(name), optionType_(eftUnknown), legacyType_(-1),
+              defaultBasename_(NULL), bLegacyOptionalBehavior_(false),
               bRead_(false), bWrite_(false), bLibrary_(false)
         {
         }
@@ -84,7 +85,7 @@ class FileNameOption : public OptionTemplate<std::string, FileNameOption>
          * Either this attribute or legacyType() must be provided.
          */
         MyClass &filetype(OptionFileType type)
-        { filetype_ = type; return me(); }
+        { optionType_ = type; return me(); }
         /*! \brief
          * Sets the type of the file from an enum in filenm.h.
          *
@@ -93,6 +94,16 @@ class FileNameOption : public OptionTemplate<std::string, FileNameOption>
          */
         MyClass &legacyType(int type)
         { legacyType_ = type; return me(); }
+        /*! \brief
+         * Changes the behavior of optional options to match old t_filenm.
+         *
+         * If this is not set, optional options return an empty string if not
+         * set.  If this is set, a non-empty value is always returned.
+         * In the latter case, whether the option is set only affects the
+         * return value of OptionInfo::isSet() and Options::isSet().
+         */
+        MyClass &legacyOptionalBehavior()
+        { bLegacyOptionalBehavior_ = true; return me(); }
         //! Tells that the file provided by this option is used for input only.
         MyClass &inputFile()
         { bRead_ = true; bWrite_ = false; return me(); }
@@ -155,11 +166,13 @@ class FileNameOption : public OptionTemplate<std::string, FileNameOption>
         using MyBase::defaultValueIfSet;
 
         //! Creates a FileNameOptionStorage object.
-        virtual AbstractOptionStoragePointer createStorage() const;
+        virtual AbstractOptionStoragePointer createStorage(
+            const OptionManagerContainer &managers) const;
 
-        OptionFileType          filetype_;
+        OptionFileType          optionType_;
         int                     legacyType_;
         const char             *defaultBasename_;
+        bool                    bLegacyOptionalBehavior_;
         bool                    bRead_;
         bool                    bWrite_;
         bool                    bLibrary_;
@@ -181,26 +194,11 @@ class FileNameOptionInfo : public OptionInfo
 {
     public:
         //! Shorthand for a list of extensions.
-        typedef ConstArrayRef<const char *> ExtensionList;
+        typedef std::vector<const char *> ExtensionList;
 
         //! Creates an option info object for the given option.
         explicit FileNameOptionInfo(FileNameOptionStorage *option);
 
-        /*! \brief
-         * Set manager for handling interaction with other options.
-         *
-         * \param   manager  File name option manager to set.
-         *
-         * This must be called before the values are added.
-         *
-         * Typically it is called through setManagerForFileNameOptions(),
-         * which recursively sets the manager for all file name options in
-         * an Options object.
-         *
-         * Does not throw.
-         */
-        void setManager(FileNameOptionManager *manager);
-
         //! Whether the option specifies an input file.
         bool isInputFile() const;
         //! Whether the option specifies an output file.
@@ -216,11 +214,12 @@ class FileNameOptionInfo : public OptionInfo
 
         //! Whether the option specifies directories.
         bool isDirectoryOption() const;
+        //! Returns the default extension for this option.
+        const char *defaultExtension() const;
         //! Returns the list of extensions this option accepts.
         ExtensionList extensions() const;
 
     private:
-        FileNameOptionStorage &option();
         const FileNameOptionStorage &option() const;
 };
 
index db7b2fde10e24ee25ebf66d929735df64426e965..3ba0aeac410719eb5bbb21c17828c22d72608d35 100644 (file)
@@ -46,7 +46,6 @@
 #include "gromacs/options/basicoptions.h"
 #include "gromacs/options/filenameoption.h"
 #include "gromacs/options/options.h"
-#include "gromacs/options/optionsvisitor.h"
 
 namespace gmx
 {
@@ -93,54 +92,4 @@ const std::string &FileNameOptionManager::defaultFileName() const
     return impl_->defaultFileName_;
 }
 
-/********************************************************************
- * Global functions
- */
-
-namespace
-{
-
-/*! \internal \brief
- * Visitor that sets the manager for each file name option.
- *
- * \ingroup module_options
- */
-class FileNameOptionManagerSetter : public OptionsModifyingVisitor
-{
-    public:
-        //! Construct a visitor that sets given manager.
-        explicit FileNameOptionManagerSetter(FileNameOptionManager *manager)
-            : manager_(manager)
-        {
-        }
-
-        void visitSubSection(Options *section)
-        {
-            OptionsModifyingIterator iterator(section);
-            iterator.acceptSubSections(this);
-            iterator.acceptOptions(this);
-        }
-
-        void visitOption(OptionInfo *option)
-        {
-            FileNameOptionInfo *fileOption
-                = option->toType<FileNameOptionInfo>();
-            if (fileOption != NULL)
-            {
-                fileOption->setManager(manager_);
-            }
-        }
-
-    private:
-        FileNameOptionManager *manager_;
-};
-
-}   // namespace
-
-void setManagerForFileNameOptions(Options               *options,
-                                  FileNameOptionManager *manager)
-{
-    FileNameOptionManagerSetter(manager).visitSubSection(options);
-}
-
 } // namespace gmx
index 24853ce7b75861bbbe1290591495abc3af1d5b00..caa96443639bc98acbf1409d98491a05ebe0722c 100644 (file)
@@ -45,6 +45,8 @@
 
 #include <string>
 
+#include "options.h"
+
 #include "../utility/common.h"
 
 namespace gmx
@@ -64,20 +66,20 @@ class Options;
  * most of the non-trivial file name completion logic in this class, so that
  * the customizations would be centralized here.
  *
- * Creating a FileNameOptionManager for an Options object is optional, even if
+ * Adding a FileNameOptionManager for an Options object is optional, even if
  * the Options contains FileNameOption options.  Features from the manager are
  * not available if the manager is not created, but otherwise the options work.
  *
- * \see setManagerForFileNameOptions()
+ * \see Options::addManager()
  *
  * \inpublicapi
  * \ingroup module_selection
  */
-class FileNameOptionManager
+class FileNameOptionManager : public OptionManagerInterface
 {
     public:
         FileNameOptionManager();
-        ~FileNameOptionManager();
+        virtual ~FileNameOptionManager();
 
         /*! \brief
          * Adds an option for setting the default global file name.
@@ -102,20 +104,6 @@ class FileNameOptionManager
         PrivateImplPointer<Impl> impl_;
 };
 
-/*! \brief
- * Set manager for all file name options.
- *
- * Recursively sets the manager to \p manager for all file name options in
- * \p options.
- * Must be called before value assignment starts for \p options.
- *
- * Does not throw.
- *
- * \inpublicapi
- */
-void setManagerForFileNameOptions(Options               *options,
-                                  FileNameOptionManager *manager);
-
 } // namespace gmx
 
 #endif
index e90470775879e512628012111518ae924e9fead8..c7c1bf171f085f3234e10aa933bb7f216e5b0c93 100644 (file)
@@ -43,6 +43,7 @@
 #define GMX_OPTIONS_FILENAMEOPTIONSTORAGE_H
 
 #include <string>
+#include <vector>
 
 #include "filenameoption.h"
 #include "optionfiletype.h"
@@ -60,17 +61,20 @@ class FileNameOptionManager;
 class FileNameOptionStorage : public OptionStorageTemplate<std::string>
 {
     public:
-        //! \copydoc StringOptionStorage::StringOptionStorage()
-        explicit FileNameOptionStorage(const FileNameOption &settings);
+        /*! \brief
+         * Initializes the storage from option settings.
+         *
+         * \param[in] settings   Storage settings.
+         * \param     manager    Manager for this object (can be NULL).
+         */
+        FileNameOptionStorage(const FileNameOption  &settings,
+                              FileNameOptionManager *manager);
 
         virtual OptionInfo &optionInfo() { return info_; }
         virtual std::string typeString() const;
         virtual std::string formatExtraDescription() const;
         virtual std::string formatSingleValue(const std::string &value) const;
 
-        //! \copydoc FileNameOptionInfo::setManager()
-        void setManager(FileNameOptionManager *manager);
-
         //! \copydoc FileNameOptionInfo::isInputFile()
         bool isInputFile() const { return bRead_ && !bWrite_; }
         //! \copydoc FileNameOptionInfo::isOutputFile()
@@ -82,8 +86,10 @@ class FileNameOptionStorage : public OptionStorageTemplate<std::string>
 
         //! \copydoc FileNameOptionInfo::isDirectoryOption()
         bool isDirectoryOption() const;
+        //! \copydoc FileNameOptionInfo::defaultExtension()
+        const char *defaultExtension() const;
         //! \copydoc FileNameOptionInfo::extensions()
-        ConstArrayRef<const char *> extensions() const;
+        std::vector<const char *> extensions() const;
 
     private:
         virtual void convertValue(const std::string &value);
@@ -91,8 +97,7 @@ class FileNameOptionStorage : public OptionStorageTemplate<std::string>
 
         FileNameOptionInfo      info_;
         FileNameOptionManager  *manager_;
-        OptionFileType          filetype_;
-        int                     legacyType_;
+        int                     fileType_;
         bool                    bRead_;
         bool                    bWrite_;
         bool                    bLibrary_;
diff --git a/src/gromacs/options/optionmanagercontainer.h b/src/gromacs/options/optionmanagercontainer.h
new file mode 100644 (file)
index 0000000..b282cd6
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2014, 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.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \libinternal \file
+ * \brief
+ * Declares gmx::OptionManagerContainer.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \inlibraryapi
+ * \ingroup module_options
+ */
+#ifndef GMX_OPTIONS_OPTIONMANAGERCONTAINER_H
+#define GMX_OPTIONS_OPTIONMANAGERCONTAINER_H
+
+#include <vector>
+
+#include "gromacs/utility/common.h"
+#include "gromacs/utility/gmxassert.h"
+
+namespace gmx
+{
+
+class OptionManagerInterface;
+
+/*! \libinternal
+ * \brief
+ * Container to keep managers added with Options::addManager() and pass them
+ * to options.
+ *
+ * Consistency of the managers (e.g., that there is at most one manager of a
+ * certain type) is only checked when the managers are accessed.
+ *
+ * \inlibraryapi
+ * \ingroup module_options
+ */
+class OptionManagerContainer
+{
+    public:
+        OptionManagerContainer()
+        {
+        }
+
+        //! Returns `true` if there are no managers.
+        bool empty() const { return list_.empty(); }
+
+        //! Adds a manager to the container.
+        void add(OptionManagerInterface *manager)
+        {
+            list_.push_back(manager);
+        }
+        /*! \brief
+         * Retrieves a manager of a certain type.
+         *
+         * \tparam  ManagerType  Type of manager to retrieve
+         *     (should derive from OptionManagerInterface).
+         * \returns The manager, or `NULL` if there is none.
+         *
+         * This method is used in AbstractOption::createStorage() to retrieve
+         * a manager of a certain type for options that use a manager.
+         *
+         * The return value is `NULL` if there is no manager of the given type.
+         * The caller needs to handle this (either by asserting, or by handling
+         * the manager as optional).
+         */
+        template <class ManagerType>
+        ManagerType *get() const
+        {
+            ManagerType *result = NULL;
+            for (ListType::const_iterator i = list_.begin(); i != list_.end(); ++i)
+            {
+                ManagerType *curr = dynamic_cast<ManagerType *>(*i);
+                if (curr != NULL)
+                {
+                    GMX_RELEASE_ASSERT(result == NULL,
+                                       "More than one applicable option manager is set");
+                    result = curr;
+                }
+            }
+            return result;
+        }
+
+    private:
+        //! Shorthand for the internal container type.
+        typedef std::vector<OptionManagerInterface *> ListType;
+
+        ListType  list_;
+
+        GMX_DISALLOW_COPY_AND_ASSIGN(OptionManagerContainer);
+};
+
+} // namespace gmx
+
+#endif
index 6b06f1fcd7c4820941f66733dd3be0b91b53843a..c126f07e8579236a660aa2c9ca46a3d6daee7a71 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014, 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.
@@ -46,6 +46,7 @@
 #include <vector>
 
 #include "abstractoption.h"
+#include "optionmanagercontainer.h"
 #include "options.h"
 
 namespace gmx
@@ -107,6 +108,12 @@ class Options::Impl
         std::string             title_;
         //! Full description for the Options object.
         std::string             description_;
+        /*! \brief
+         * Option managers set for this collection.
+         *
+         * This is non-empty only for the top-level Options object.
+         */
+        OptionManagerContainer  managers_;
         /*! \brief
          * List of subsections, in insertion order.
          *
index 8b3c22e2646ec3970f1bff7054c397d1c187d1e9..b64f285268d408a51d31db01e27301eeb59390c6 100644 (file)
 namespace gmx
 {
 
+/********************************************************************
+ * OptionManagerInterface
+ */
+
+OptionManagerInterface::~OptionManagerInterface()
+{
+}
+
 /********************************************************************
  * Options::Impl
  */
@@ -148,8 +156,28 @@ void Options::setDescription(const ConstArrayRef<const char *> &descArray)
     impl_->description_ = concatenateStrings(descArray.data(), descArray.size());
 }
 
+void Options::addManager(OptionManagerInterface *manager)
+{
+    GMX_RELEASE_ASSERT(impl_->parent_ == NULL,
+                       "Can only add a manager in a top-level Options object");
+    // This ensures that all options see the same set of managers.
+    GMX_RELEASE_ASSERT(impl_->options_.empty(),
+                       "Can only add a manager before options");
+    // This check could be relaxed if we instead checked that the subsections
+    // do not have options.
+    GMX_RELEASE_ASSERT(impl_->subSections_.empty(),
+                       "Can only add a manager before subsections");
+    impl_->managers_.add(manager);
+}
+
 void Options::addSubSection(Options *section)
 {
+    // This is required, because managers are used from the root Options
+    // object, so they are only seen after the subsection has been added.
+    GMX_RELEASE_ASSERT(section->impl_->options_.empty(),
+                       "Can only add a subsection before it has any options");
+    GMX_RELEASE_ASSERT(section->impl_->managers_.empty(),
+                       "Can only have managers in a top-level Options object");
     // Make sure that section is not already inserted somewhere.
     GMX_RELEASE_ASSERT(section->impl_->parent_ == NULL,
                        "Cannot add as subsection twice");
@@ -162,7 +190,12 @@ void Options::addSubSection(Options *section)
 
 OptionInfo *Options::addOption(const AbstractOption &settings)
 {
-    AbstractOptionStoragePointer option(settings.createStorage());
+    Options::Impl *root = impl_.get();
+    while (root->parent_ != NULL)
+    {
+        root = root->parent_->impl_.get();
+    }
+    AbstractOptionStoragePointer option(settings.createStorage(root->managers_));
     if (impl_->findOption(option->name().c_str()) != NULL)
     {
         GMX_THROW(APIError("Duplicate option: " + option->name()));
index cd5f1dc7b012c1cc5da47db40b596c08214c0aa2..7623086796c57ac63347d1afcafec2dc2fea5a22 100644 (file)
@@ -62,6 +62,27 @@ class AbstractOption;
 class OptionsAssigner;
 class OptionsIterator;
 
+/*! \brief
+ * Base class for option managers.
+ *
+ * This class is used as a marker for all classes that are used with
+ * Options::addManager().  It doesn't provide any methods, but only supports
+ * transporting these classes through the Options collection into the
+ * individual option implementation classes.
+ *
+ * The virtual destructor is present to make this class polymorphic, such that
+ * `dynamic_cast` can be used when retrieving a manager of a certain type for
+ * the individual options.
+ *
+ * \inlibraryapi
+ * \ingroup module_options
+ */
+class OptionManagerInterface
+{
+    protected:
+        virtual ~OptionManagerInterface();
+};
+
 /*! \brief
  * Collection of options.
  *
@@ -152,6 +173,28 @@ class Options
          */
         void setDescription(const ConstArrayRef<const char *> &descArray);
 
+        /*! \brief
+         * Adds an option manager.
+         *
+         * \param    manager Manager to add.
+         * \throws   std::bad_alloc if out of memory.
+         *
+         * Option managers are used by some types of options that require
+         * interaction between different option instances (e.g., selection
+         * options), or need to support globally set properties (e.g., a global
+         * default file prefix).  Option objects can retrieve the pointer to
+         * their manager when they are created, and the caller can alter the
+         * behavior of the options through the manager.
+         * See the individual managers for details.
+         *
+         * Caller is responsible for memory management of \p manager.
+         * The Options object (and its contained options) only stores a
+         * reference to the object.
+         *
+         * This method cannot be called after adding options or subsections.
+         */
+        void addManager(OptionManagerInterface *manager);
+
         /*! \brief
          * Adds an option collection as a subsection of this collection.
          *
@@ -161,9 +204,8 @@ class Options
          * subsection.  If an attempt is made to add two different subsections
          * with the same name, this function asserts.
          *
-         * For certain functionality to work properly, no options should
-         * be added to the subsection after it has been added to another
-         * collection.
+         * \p section should not have any options added at the point this
+         * method is called.
          *
          * Only a pointer to the provided object is stored.  The caller is
          * responsible that the object exists for the lifetime of the
index 716e0b1f56de278c8b101c4d6015b84ad2a7f437..6df36ee6eb63c1f1654232ca282de8a37bf1ecca 100644 (file)
@@ -151,7 +151,8 @@ class MockOption : public gmx::OptionTemplate<std::string, MockOption>
         }
 
     private:
-        virtual gmx::AbstractOptionStoragePointer createStorage() const
+        virtual gmx::AbstractOptionStoragePointer createStorage(
+            const gmx::OptionManagerContainer & /*managers*/) const
         {
             return gmx::AbstractOptionStoragePointer(new MockOptionStorage(*this));
         }
index 949928c182328cc2569493ef81f54fb5284fa822..be0acd969b8fa9084c440b52be7e5f2a59f24cf4 100644 (file)
@@ -237,12 +237,12 @@ TEST(FileNameOptionTest, AddsMissingExtensionForRequiredFromDefaultNameOptionBas
     gmx::FileNameOptionManager manager;
     gmx::Options               options(NULL, NULL);
     std::string                value;
+    ASSERT_NO_THROW_GMX(options.addManager(&manager));
     ASSERT_NO_THROW_GMX(options.addOption(
                                 FileNameOption("f").store(&value).required()
                                     .filetype(gmx::eftTrajectory).inputFile()
                                     .defaultBasename("foo")));
     ASSERT_NO_THROW_GMX(manager.addDefaultFileNameOption(&options, "deffnm"));
-    ASSERT_NO_THROW_GMX(setManagerForFileNameOptions(&options, &manager));
     EXPECT_EQ("foo.xtc", value);
 
     gmx::OptionsAssigner assigner(&options);
@@ -266,12 +266,12 @@ TEST(FileNameOptionTest, AddsMissingExtensionForOptionalFromDefaultNameOptionBas
     gmx::FileNameOptionManager manager;
     gmx::Options               options(NULL, NULL);
     std::string                value;
+    ASSERT_NO_THROW_GMX(options.addManager(&manager));
     ASSERT_NO_THROW_GMX(options.addOption(
                                 FileNameOption("f").store(&value)
                                     .filetype(gmx::eftTrajectory).inputFile()
                                     .defaultBasename("foo")));
     ASSERT_NO_THROW_GMX(manager.addDefaultFileNameOption(&options, "deffnm"));
-    ASSERT_NO_THROW_GMX(setManagerForFileNameOptions(&options, &manager));
 
     gmx::OptionsAssigner assigner(&options);
     EXPECT_NO_THROW_GMX(assigner.start());
index e12d787ba2c29ff7ce3222a5fe123106c58aa992..8fb44f0bd4b9e3113a4db68fab42c45c5750c3b1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014, 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.
@@ -183,11 +183,11 @@ TEST(OptionsAssignerTest, HandlesSubSections)
     int          value1 = 1;
     int          value2 = 2;
     using gmx::IntegerOption;
+    ASSERT_NO_THROW(options.addSubSection(&sub1));
+    ASSERT_NO_THROW(options.addSubSection(&sub2));
     ASSERT_NO_THROW(options.addOption(IntegerOption("p").store(&value)));
     ASSERT_NO_THROW(sub1.addOption(IntegerOption("p").store(&value1)));
     ASSERT_NO_THROW(sub2.addOption(IntegerOption("p").store(&value2)));
-    ASSERT_NO_THROW(options.addSubSection(&sub1));
-    ASSERT_NO_THROW(options.addSubSection(&sub2));
 
     gmx::OptionsAssigner assigner(&options);
     EXPECT_NO_THROW(assigner.start());
@@ -223,13 +223,13 @@ TEST(OptionsAssignerTest, HandlesNoStrictSubSections)
     int          pvalue2 = 2;
     int          rvalue  = 5;
     using gmx::IntegerOption;
+    ASSERT_NO_THROW(options.addSubSection(&sub1));
+    ASSERT_NO_THROW(options.addSubSection(&sub2));
     ASSERT_NO_THROW(options.addOption(IntegerOption("p").store(&pvalue)));
     ASSERT_NO_THROW(sub1.addOption(IntegerOption("p").store(&pvalue1)));
     ASSERT_NO_THROW(sub1.addOption(IntegerOption("q").store(&qvalue)));
     ASSERT_NO_THROW(sub2.addOption(IntegerOption("p").store(&pvalue2)));
     ASSERT_NO_THROW(sub2.addOption(IntegerOption("r").store(&rvalue)));
-    ASSERT_NO_THROW(options.addSubSection(&sub1));
-    ASSERT_NO_THROW(options.addSubSection(&sub2));
 
     gmx::OptionsAssigner assigner(&options);
     assigner.setNoStrictSectioning(true);
index ec2882d3cd2e7b2c67e3caf9728dc978541ddf74..721a61c01d84b1d1dcc6cb6ab6f5bd57d21c7d23 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014, 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/options/timeunitmanager.h"
 
+#include <cstdlib>
+
+#include <algorithm>
+
 #include "gromacs/options/basicoptions.h"
 #include "gromacs/options/options.h"
 #include "gromacs/options/optionsvisitor.h"
+#include "gromacs/utility/arrayref.h"
+#include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/stringutil.h"
 
 namespace
 {
@@ -108,6 +115,27 @@ double TimeUnitManager::inverseTimeScaleFactor() const
     return 1.0 / timeScaleFactor();
 }
 
+void TimeUnitManager::setTimeUnitFromEnvironment()
+{
+    const char *const value = std::getenv("GMXTIMEUNIT");
+    if (value != NULL)
+    {
+        ConstArrayRef<const char *>                 timeUnits(g_timeUnits);
+        ConstArrayRef<const char *>::const_iterator i =
+            std::find(timeUnits.begin(), timeUnits.end(), std::string(value));
+        if (i == timeUnits.end())
+        {
+            std::string message = formatString(
+                        "Time unit provided with environment variable GMXTIMEUNIT=%s "
+                        "is not recognized as a valid time unit.\n"
+                        "Possible values are: %s",
+                        value, joinStrings(timeUnits, ", ").c_str());
+            GMX_THROW(InvalidInputError(message));
+        }
+        timeUnit_ = i - timeUnits.begin();
+    }
+}
+
 void TimeUnitManager::addTimeUnitOption(Options *options, const char *name)
 {
     options->addOption(StringOption(name).enumValue(g_timeUnits)
index 34f11d97fa1bb40819054f48264c0a951ced1a50..7ad7fe3243a56dcf88d11eee5d4699d0b0befd68 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014, 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.
@@ -117,6 +117,10 @@ class TimeUnitManager
         //! Returns the scaling factor to convert times from ps.
         double inverseTimeScaleFactor() const;
 
+        /*! \brief
+         * Sets the time unit in this manager from an environment variable.
+         */
+        void setTimeUnitFromEnvironment();
         /*! \brief
          * Adds a common option for selecting the time unit.
          *
index 265749eeee20aab14b3bcee408136f9898d319fd..77a773c9e49cb252334b95c97a98a613aa36b71f 100644 (file)
@@ -44,7 +44,6 @@
 #include <string.h>
 
 #include "gromacs/utility/futil.h"
-#include "index.h"
 #include "typedefs.h"
 #include "types/commrec.h"
 #include "network.h"
index 6cd0cef2ff3d4608f34aa397a1d1555cfd8ae320..1b13d4eabc6dce991d08e7acaca37a95c2946644 100644 (file)
@@ -48,7 +48,6 @@
 #include "names.h"
 #include "gromacs/utility/fatalerror.h"
 #include "macros.h"
-#include "index.h"
 #include "gromacs/fileio/confio.h"
 #include "network.h"
 #include "gromacs/pbcutil/pbc.h"
index b2f5b053bff5b2a63f0e428e1329b5701df88556..f921caeaac856565f63e953a9df31505d35d9589 100644 (file)
@@ -47,9 +47,8 @@
 #include <string>
 #include <vector>
 
-#include "gromacs/legacyheaders/index.h"
-
 #include "gromacs/topology/block.h"
+#include "gromacs/topology/index.h"
 #include "gromacs/topology/topology.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
index c0a70dad005beb6cc5ba8231b76b61d5f05bc1d7..773bff96b3821a77a663aa5946537dc0d888c24f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014, 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.
@@ -76,7 +76,8 @@ class SelectionFileOption : public AbstractOption
         explicit SelectionFileOption(const char *name);
 
     private:
-        virtual AbstractOptionStoragePointer createStorage() const;
+        virtual AbstractOptionStoragePointer createStorage(
+            const OptionManagerContainer &managers) const;
 };
 
 /*! \libinternal \brief
@@ -94,13 +95,6 @@ class SelectionFileOptionInfo : public OptionInfo
          * Does not throw.
          */
         explicit SelectionFileOptionInfo(SelectionFileOptionStorage *option);
-
-        //! \copydoc SelectionOptionInfo::setManager()
-        void setManager(SelectionOptionManager *manager);
-
-    private:
-        SelectionFileOptionStorage &option();
-        const SelectionFileOptionStorage &option() const;
 };
 
 } // namespace gmx
index a19321962fe2d2314b490cec50c456b721da8f16..ac628bf7ba26a7b47ab034a0614b2ed883d8dbb5 100644 (file)
@@ -63,29 +63,25 @@ class SelectionFileOptionStorage : public AbstractOptionStorage
          * Initializes the storage from option settings.
          *
          * \param[in] settings   Storage settings.
+         * \param     manager    Manager for this object.
          */
-        SelectionFileOptionStorage(const SelectionFileOption &settings);
+        SelectionFileOptionStorage(const SelectionFileOption &settings,
+                                   SelectionOptionManager    *manager);
 
         virtual OptionInfo &optionInfo() { return info_; }
         virtual std::string typeString() const { return "file"; }
         virtual int valueCount() const { return 0; }
         virtual std::string formatValue(int /*i*/) const { return ""; }
 
-        //! \copydoc SelectionFileOptionInfo::setManager()
-        void setManager(SelectionOptionManager *manager)
-        {
-            manager_ = manager;
-        }
-
     private:
         virtual void clearSet();
         virtual void convertValue(const std::string &value);
         virtual void processSet();
         virtual void processAll() {}
 
-        SelectionFileOptionInfo info_;
-        SelectionOptionManager *manager_;
-        bool                    bValueParsed_;
+        SelectionFileOptionInfo  info_;
+        SelectionOptionManager  &manager_;
+        bool                     bValueParsed_;
 };
 
 } // namespace gmx
index 41da1f5de019f73d4364cc9fe94ca04b2ddbc66f..62fbc9cf50d32933cf5ebb61dfb30493f34ba0ba 100644 (file)
@@ -46,6 +46,7 @@
 
 #include <string>
 
+#include "gromacs/options/optionmanagercontainer.h"
 #include "gromacs/selection/selection.h"
 #include "gromacs/selection/selectionoptionmanager.h"
 #include "gromacs/utility/exceptions.h"
@@ -59,26 +60,18 @@ namespace gmx
  * SelectionOptionStorage
  */
 
-SelectionOptionStorage::SelectionOptionStorage(const SelectionOption &settings)
+SelectionOptionStorage::SelectionOptionStorage(const SelectionOption  &settings,
+                                               SelectionOptionManager *manager)
     : MyBase(settings, OptionFlags() | efOption_NoDefaultValue
              | efOption_DontCheckMinimumCount),
-      info_(this), manager_(NULL), defaultText_(settings.defaultText_),
+      info_(this), manager_(*manager), defaultText_(settings.defaultText_),
       selectionFlags_(settings.selectionFlags_)
 {
+    GMX_RELEASE_ASSERT(manager != NULL,
+                       "SelectionOptionManager must be added before SelectionOption");
     GMX_RELEASE_ASSERT(!hasFlag(efOption_MultipleTimes),
                        "allowMultiple() is not supported for selection options");
-}
-
-
-void SelectionOptionStorage::setManager(SelectionOptionManager *manager)
-{
-    GMX_RELEASE_ASSERT(manager_ == NULL || manager_ == manager,
-                       "Manager cannot be changed once set");
-    if (manager_ == NULL)
-    {
-        manager->registerOption(this);
-        manager_ = manager;
-    }
+    manager_.registerOption(this);
 }
 
 
@@ -124,18 +117,14 @@ void SelectionOptionStorage::addSelections(
 
 void SelectionOptionStorage::convertValue(const std::string &value)
 {
-    GMX_RELEASE_ASSERT(manager_ != NULL, "Manager is not set");
-
-    manager_->convertOptionValue(this, value, false);
+    manager_.convertOptionValue(this, value, false);
 }
 
 void SelectionOptionStorage::processSetValues(ValueList *values)
 {
-    GMX_RELEASE_ASSERT(manager_ != NULL, "Manager is not set");
-
     if (values->size() == 0)
     {
-        manager_->requestOptionDelayedParsing(this);
+        manager_.requestOptionDelayedParsing(this);
     }
     else if (values->size() < static_cast<size_t>(minValueCount()))
     {
@@ -145,14 +134,13 @@ void SelectionOptionStorage::processSetValues(ValueList *values)
 
 void SelectionOptionStorage::processAll()
 {
-    GMX_RELEASE_ASSERT(manager_ != NULL, "Manager is not set");
     if (!isSet() && !defaultText_.empty())
     {
-        manager_->convertOptionValue(this, defaultText_, true);
+        manager_.convertOptionValue(this, defaultText_, true);
     }
     if (isRequired() && !isSet())
     {
-        manager_->requestOptionDelayedParsing(this);
+        manager_.requestOptionDelayedParsing(this);
         markAsSet();
     }
 }
@@ -227,11 +215,6 @@ const SelectionOptionStorage &SelectionOptionInfo::option() const
     return static_cast<const SelectionOptionStorage &>(OptionInfo::option());
 }
 
-void SelectionOptionInfo::setManager(SelectionOptionManager *manager)
-{
-    option().setManager(manager);
-}
-
 void SelectionOptionInfo::setValueCount(int count)
 {
     option().setAllowedValueCount(count);
@@ -267,9 +250,12 @@ void SelectionOptionInfo::setDynamicMask(bool bEnabled)
  * SelectionOption
  */
 
-AbstractOptionStoragePointer SelectionOption::createStorage() const
+AbstractOptionStoragePointer
+SelectionOption::createStorage(const OptionManagerContainer &managers) const
 {
-    return AbstractOptionStoragePointer(new SelectionOptionStorage(*this));
+    return AbstractOptionStoragePointer(
+            new SelectionOptionStorage(
+                    *this, managers.get<SelectionOptionManager>()));
 }
 
 
@@ -277,11 +263,14 @@ AbstractOptionStoragePointer SelectionOption::createStorage() const
  * SelectionFileOptionStorage
  */
 
-SelectionFileOptionStorage::SelectionFileOptionStorage(const SelectionFileOption &settings)
+SelectionFileOptionStorage::SelectionFileOptionStorage(
+        const SelectionFileOption &settings, SelectionOptionManager *manager)
     : AbstractOptionStorage(settings, OptionFlags() | efOption_MultipleTimes
                             | efOption_DontCheckMinimumCount),
-      info_(this), manager_(NULL), bValueParsed_(false)
+      info_(this), manager_(*manager), bValueParsed_(false)
 {
+    GMX_RELEASE_ASSERT(manager != NULL,
+                       "SelectionOptionManager must be added before SelectionFileOption");
 }
 
 void SelectionFileOptionStorage::clearSet()
@@ -291,15 +280,13 @@ void SelectionFileOptionStorage::clearSet()
 
 void SelectionFileOptionStorage::convertValue(const std::string &value)
 {
-    GMX_RELEASE_ASSERT(manager_ != NULL, "Manager is not set");
-
     if (bValueParsed_)
     {
         GMX_THROW(InvalidInputError("More than one file name provided"));
     }
     bValueParsed_ = true;
     // TODO: Should we throw an InvalidInputError if the file does not exist?
-    manager_->parseRequestedFromFile(value);
+    manager_.parseRequestedFromFile(value);
 }
 
 void SelectionFileOptionStorage::processSet()
@@ -320,21 +307,6 @@ SelectionFileOptionInfo::SelectionFileOptionInfo(SelectionFileOptionStorage *opt
 {
 }
 
-SelectionFileOptionStorage &SelectionFileOptionInfo::option()
-{
-    return static_cast<SelectionFileOptionStorage &>(OptionInfo::option());
-}
-
-const SelectionFileOptionStorage &SelectionFileOptionInfo::option() const
-{
-    return static_cast<const SelectionFileOptionStorage &>(OptionInfo::option());
-}
-
-void SelectionFileOptionInfo::setManager(SelectionOptionManager *manager)
-{
-    option().setManager(manager);
-}
-
 
 /********************************************************************
  * SelectionFileOption
@@ -346,9 +318,12 @@ SelectionFileOption::SelectionFileOption(const char *name)
     setDescription("Provide selections from files");
 }
 
-AbstractOptionStoragePointer SelectionFileOption::createStorage() const
+AbstractOptionStoragePointer
+SelectionFileOption::createStorage(const OptionManagerContainer &managers) const
 {
-    return AbstractOptionStoragePointer(new SelectionFileOptionStorage(*this));
+    return AbstractOptionStoragePointer(
+            new SelectionFileOptionStorage(
+                    *this, managers.get<SelectionOptionManager>()));
 }
 
 } // namespace gmx
index cba014a055ab048070dfc87dd061f6edcf477e69..a67e4e337ba1d975942d26120b81d32432e91318 100644 (file)
@@ -60,6 +60,10 @@ class SelectionOptionStorage;
  *
  * Public methods in this class do not throw.
  *
+ * To use options of this type, SelectionOptionManager must first be added to
+ * the Options collection.  For trajectory analysis tools, the framework takes
+ * care of this.
+ *
  * \todo
  * Support for specifying that an option accepts, e.g., two to four selections.
  * Currently, only a fixed count or any number of selections is possible.
@@ -145,7 +149,8 @@ class SelectionOption : public OptionTemplate<Selection, SelectionOption>
         using MyBase::defaultValue;
         using MyBase::defaultValueIfSet;
 
-        virtual AbstractOptionStoragePointer createStorage() const;
+        virtual AbstractOptionStoragePointer createStorage(
+            const OptionManagerContainer &managers) const;
 
         const char             *defaultText_;
         SelectionFlags          selectionFlags_;
@@ -211,22 +216,6 @@ class SelectionOptionInfo : public OptionInfo
          */
         explicit SelectionOptionInfo(SelectionOptionStorage *option);
 
-        /*! \brief
-         * Set manager for handling interaction with other options and the
-         * selection collection.
-         *
-         * \param   manager  Selection manager to set.
-         *
-         * This must be called before the values are added.
-         *
-         * Typically it is called through setManagerForSelectionOptions(),
-         * which recursively sets the manager for all selection options in
-         * an Options object.
-         *
-         * Does not throw.
-         */
-        void setManager(SelectionOptionManager *manager);
-
         /*! \brief
          * Sets the number of selections allowed for the option.
          *
index 3600bd29233994a659941d064dcb21cd43be3b4b..effb758ba09914d4bcceb5de6fda2d7ffbda21a5 100644 (file)
@@ -43,7 +43,6 @@
 
 #include <cstdio>
 
-#include "gromacs/options/optionsvisitor.h"
 #include "gromacs/selection/selection.h"
 #include "gromacs/selection/selectioncollection.h"
 #include "gromacs/selection/selectionoption.h"
@@ -331,60 +330,4 @@ SelectionOptionManager::parseRequestedFromString(const std::string &str)
     impl_->placeSelectionsInRequests(selections);
 }
 
-/********************************************************************
- * Global functions
- */
-
-namespace
-{
-
-/*! \internal \brief
- * Visitor that sets the manager for each selection option.
- *
- * \ingroup module_selection
- */
-class SelectionOptionManagerSetter : public OptionsModifyingVisitor
-{
-    public:
-        //! Construct a visitor that sets given manager.
-        explicit SelectionOptionManagerSetter(SelectionOptionManager *manager)
-            : manager_(manager)
-        {
-        }
-
-        void visitSubSection(Options *section)
-        {
-            OptionsModifyingIterator iterator(section);
-            iterator.acceptSubSections(this);
-            iterator.acceptOptions(this);
-        }
-
-        void visitOption(OptionInfo *option)
-        {
-            SelectionOptionInfo *selOption
-                = option->toType<SelectionOptionInfo>();
-            if (selOption != NULL)
-            {
-                selOption->setManager(manager_);
-            }
-            SelectionFileOptionInfo *selFileOption
-                = option->toType<SelectionFileOptionInfo>();
-            if (selFileOption != NULL)
-            {
-                selFileOption->setManager(manager_);
-            }
-        }
-
-    private:
-        SelectionOptionManager *manager_;
-};
-
-}   // namespace
-
-void setManagerForSelectionOptions(Options                *options,
-                                   SelectionOptionManager *manager)
-{
-    SelectionOptionManagerSetter(manager).visitSubSection(options);
-}
-
 } // namespace gmx
index 8545661bbf2d2115cc71ee4aa5617c5327e8cf61..ec26193b58876a7a4e5ffae6a44622fa0a61dfa6 100644 (file)
@@ -45,6 +45,7 @@
 
 #include <string>
 
+#include "../options/options.h"
 #include "../utility/common.h"
 
 namespace gmx
@@ -62,6 +63,8 @@ class SelectionOptionStorage;
  * require actions outside options parsing.
  * It also implements the coupling between SelectionOption and
  * SelectionFileOption.
+ * It needs to be added using Options::addManager() before SelectionOption or
+ * SelectionFileOption options can be added to an Options collection.
  *
  * The main features of this class are:
  *  - convertOptionValue(), which is used to convert string values into
@@ -73,12 +76,10 @@ class SelectionOptionStorage;
  *    parseRequestedFromStdin(), parseRequestedFromFile() or
  *    parseRequstedFromString().
  *
- * \see setManagerForSelectionOptions()
- *
  * \inpublicapi
  * \ingroup module_selection
  */
-class SelectionOptionManager
+class SelectionOptionManager : public OptionManagerInterface
 {
     public:
         /*! \brief
@@ -87,7 +88,7 @@ class SelectionOptionManager
          * \throws  std::bad_alloc if out of memory.
          */
         explicit SelectionOptionManager(SelectionCollection *selections);
-        ~SelectionOptionManager();
+        virtual ~SelectionOptionManager();
 
         /*! \brief
          * Adds a selection option to be managed.
@@ -209,20 +210,6 @@ class SelectionOptionManager
         friend class SelectionOptionStorage;
 };
 
-/*! \brief
- * Set manager for all selection options.
- *
- * Recursively sets the manager to \p manager for all selection options in
- * \p options.
- * Must be called before value assignment starts for \p options.
- *
- * Does not throw.
- *
- * \inpublicapi
- */
-void setManagerForSelectionOptions(Options                *options,
-                                   SelectionOptionManager *manager);
-
 } // namespace gmx
 
 #endif
index 00e3622ba82717d2811090dc789c7e9703308524..fb9300d2b10eda04dba0e7fb1bb3ad5271c44c95 100644 (file)
@@ -69,16 +69,15 @@ class SelectionOptionStorage : public OptionStorageTemplate<Selection>
          * Initializes the storage from option settings.
          *
          * \param[in] settings   Storage settings.
+         * \param     manager    Manager for this object.
          */
-        SelectionOptionStorage(const SelectionOption &settings);
+        SelectionOptionStorage(const SelectionOption  &settings,
+                               SelectionOptionManager *manager);
 
         virtual OptionInfo &optionInfo() { return info_; }
         virtual std::string typeString() const { return "selection"; }
         virtual std::string formatSingleValue(const Selection &value) const;
 
-        //! \copydoc SelectionOptionInfo::setManager()
-        void setManager(SelectionOptionManager *manager);
-
         /*! \brief
          * Adds selections to the storage.
          *
@@ -127,7 +126,7 @@ class SelectionOptionStorage : public OptionStorageTemplate<Selection>
         virtual void processAll();
 
         SelectionOptionInfo     info_;
-        SelectionOptionManager *manager_;
+        SelectionOptionManager &manager_;
         std::string             defaultText_;
         SelectionFlags          selectionFlags_;
 };
index 4c464006905a2313c77200627d1b16c8e18b189c..dc5c3ec79967191432a7f17e0bfdfbe4a91b6c63 100644 (file)
@@ -69,7 +69,6 @@ class SelectionOptionTestBase : public ::testing::Test
     public:
         SelectionOptionTestBase();
 
-        void setManager();
         void loadTopology(const char *filename);
 
         gmx::SelectionCollection    sc_;
@@ -83,15 +82,11 @@ class SelectionOptionTestBase : public ::testing::Test
 SelectionOptionTestBase::SelectionOptionTestBase()
     : manager_(&sc_), options_(NULL, NULL)
 {
+    options_.addManager(&manager_);
     sc_.setReferencePosType("atom");
     sc_.setOutputPosType("atom");
 }
 
-void SelectionOptionTestBase::setManager()
-{
-    setManagerForSelectionOptions(&options_, &manager_);
-}
-
 void SelectionOptionTestBase::loadTopology(const char *filename)
 {
     topManager_.loadTopology(filename);
@@ -112,7 +107,6 @@ TEST_F(SelectionOptionTest, ParsesSimpleSelection)
     gmx::Selection sel;
     using gmx::SelectionOption;
     ASSERT_NO_THROW_GMX(options_.addOption(SelectionOption("sel").store(&sel)));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -132,7 +126,6 @@ TEST_F(SelectionOptionTest, HandlesDynamicSelectionWhenStaticRequired)
     using gmx::SelectionOption;
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("sel").store(&sel).onlyStatic()));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -150,7 +143,6 @@ TEST_F(SelectionOptionTest, HandlesNonAtomicSelectionWhenAtomsRequired)
     using gmx::SelectionOption;
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("sel").store(&sel).onlyAtoms()));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -171,7 +163,6 @@ TEST_F(SelectionOptionTest, ChecksEmptySelections)
     using gmx::SelectionOption;
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("sel").store(&sel)));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -191,7 +182,6 @@ TEST_F(SelectionOptionTest, ChecksEmptyDelayedSelections)
     using gmx::SelectionOption;
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("sel").store(&sel)));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -210,7 +200,6 @@ TEST_F(SelectionOptionTest, HandlesTooManySelections)
     gmx::Selection sel;
     using gmx::SelectionOption;
     ASSERT_NO_THROW_GMX(options_.addOption(SelectionOption("sel").store(&sel)));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -229,7 +218,6 @@ TEST_F(SelectionOptionTest, HandlesTooFewSelections)
     using gmx::SelectionOption;
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("sel").store(sel).valueCount(2)));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -247,7 +235,6 @@ TEST_F(SelectionOptionTest, HandlesDefaultSelectionText)
     using gmx::SelectionOption;
     options_.addOption(SelectionOption("sel").store(&sel)
                            .defaultSelectionText("all"));
-    setManager();
 
     EXPECT_NO_THROW_GMX(options_.finish());
 
@@ -266,7 +253,6 @@ TEST_F(SelectionOptionTest, HandlesAdjuster)
     using gmx::SelectionOption;
     gmx::SelectionOptionInfo *info = options_.addOption(
                 SelectionOption("sel").storeVector(&sel).multiValue());
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -286,7 +272,6 @@ TEST_F(SelectionOptionTest, HandlesDynamicWhenStaticRequiredWithAdjuster)
     using gmx::SelectionOption;
     gmx::SelectionOptionInfo *info = options_.addOption(
                 SelectionOption("sel").store(&sel));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -305,7 +290,6 @@ TEST_F(SelectionOptionTest, HandlesTooManySelectionsWithAdjuster)
     using gmx::SelectionOption;
     gmx::SelectionOptionInfo *info = options_.addOption(
                 SelectionOption("sel").storeVector(&sel).multiValue());
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -325,7 +309,6 @@ TEST_F(SelectionOptionTest, HandlesTooFewSelectionsWithAdjuster)
     using gmx::SelectionOption;
     gmx::SelectionOptionInfo *info = options_.addOption(
                 SelectionOption("sel").storeVector(&sel).multiValue());
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -344,7 +327,6 @@ TEST_F(SelectionOptionTest, HandlesDelayedRequiredSelection)
     using gmx::SelectionOption;
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("sel").store(&sel).required()));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -362,7 +344,6 @@ TEST_F(SelectionOptionTest, HandlesTooFewDelayedRequiredSelections)
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("sel").store(sel).required()
                                     .valueCount(2)));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -377,7 +358,6 @@ TEST_F(SelectionOptionTest, HandlesDelayedOptionalSelection)
     gmx::Selection sel;
     using gmx::SelectionOption;
     ASSERT_NO_THROW_GMX(options_.addOption(SelectionOption("sel").store(&sel)));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -396,7 +376,6 @@ TEST_F(SelectionOptionTest, HandlesDelayedSelectionWithAdjuster)
     using gmx::SelectionOption;
     gmx::SelectionOptionInfo *info = options_.addOption(
                 SelectionOption("sel").storeVector(&sel).valueCount(3));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -435,7 +414,6 @@ TEST_F(SelectionFileOptionTest, HandlesSingleSelectionOptionFromFile)
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("reqsel").storeVector(&reqsel)
                                     .multiValue().required()));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -464,7 +442,6 @@ TEST_F(SelectionFileOptionTest, HandlesTwoSeparateSelectionOptions)
                                 SelectionOption("sel1").storeVector(&sel1).multiValue()));
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("sel2").storeVector(&sel2).multiValue()));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     std::string          value(TestFileManager::getInputFilePath("selfile.dat"));
@@ -501,7 +478,6 @@ TEST_F(SelectionFileOptionTest, HandlesTwoSelectionOptionsFromSingleFile)
                                 SelectionOption("sel1").storeVector(&sel1)));
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("sel2").storeVector(&sel2)));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     std::string          value(TestFileManager::getInputFilePath("selfile.dat"));
@@ -535,7 +511,6 @@ TEST_F(SelectionFileOptionTest, HandlesRequiredOptionFromFile)
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("optsel").storeVector(&optsel)
                                     .multiValue()));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -569,7 +544,6 @@ TEST_F(SelectionFileOptionTest, HandlesRequiredOptionFromFileWithOtherOptionSet)
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("sel2").storeVector(&sel2)
                                     .multiValue().required()));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -600,7 +574,6 @@ TEST_F(SelectionFileOptionTest, HandlesTwoRequiredOptionsFromSingleFile)
                                 SelectionOption("sel1").storeVector(&sel1).required()));
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("sel2").storeVector(&sel2).required()));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     std::string          value(TestFileManager::getInputFilePath("selfile.dat"));
@@ -625,7 +598,6 @@ TEST_F(SelectionFileOptionTest, GivesErrorWithNoFile)
     using gmx::SelectionOption;
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("sel").storeVector(&sel).multiValue()));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -644,7 +616,6 @@ TEST_F(SelectionFileOptionTest, GivesErrorWithNonExistentFile)
     using gmx::SelectionOption;
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("sel").storeVector(&sel).multiValue()));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
@@ -667,7 +638,6 @@ TEST_F(SelectionFileOptionTest, GivesErrorWithMultipleFiles)
     using gmx::SelectionOption;
     ASSERT_NO_THROW_GMX(options_.addOption(
                                 SelectionOption("sel").storeVector(&sel).multiValue()));
-    setManager();
 
     gmx::OptionsAssigner assigner(&options_);
     EXPECT_NO_THROW_GMX(assigner.start());
index 47c703efa5aef4909c3f4aab19b83ff68d555891..ce319bff893fe140aed204f164a9a222e455b823 100644 (file)
@@ -46,7 +46,7 @@
 #include "txtdump.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/math/units.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "names.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/fileio/gmxfio.h"
index 16becfb6c381144253113f9ad16ebcbd4c72b5e1..21204a11b76ff930332601628557c1bb567838fb 100644 (file)
@@ -43,7 +43,7 @@
 #include "gromacs/legacyheaders/types/inputrec.h"
 #include "gromacs/legacyheaders/types/simple.h"
 #include "gromacs/legacyheaders/types/state.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "macros.h"
 #include "names.h"
 #include "gromacs/gmxpreprocess/readir.h"
index fb900cfca091208dc068006c50d3cf4cfd5a65e5..ffc2379e839c32e2177ce1bbd747868e8e8457cf 100644 (file)
@@ -40,6 +40,7 @@ set(TOPOLOGY_PUBLIC_HEADERS
     atoms.h
     block.h
     idef.h
+    index.h
     mtop_util.h
     symtab.h
     topology.h)
index 519a5bb897a31e0fb03325db63ea60d5de839d6a..5bba2874597b3b7332326de3b3a096c2c73f3b0c 100644 (file)
@@ -45,8 +45,8 @@
 
 #include "gromacs/fileio/strdb.h"
 #include "gromacs/legacyheaders/copyrite.h"
-#include "gromacs/legacyheaders/index.h"
 #include "gromacs/math/utilities.h"
+#include "gromacs/topology/residuetypes.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
similarity index 80%
rename from src/gromacs/gmxlib/index.c
rename to src/gromacs/topology/index.cpp
index 3adb8aca29e3e0c8351e8b28b206f3b608aa481d..d0afa4658f67603542ad3c573dd930523bf209df 100644 (file)
@@ -34,6 +34,8 @@
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
+#include "gromacs/topology/index.h"
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 #include <stdlib.h>
 #include <string.h>
 
-#include "macros.h"
-#include "names.h"
-#include "typedefs.h"
-#include "macros.h"
-#include "index.h"
-#include "txtdump.h"
+#include <algorithm>
+
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/legacyheaders/txtdump.h"
 
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/strdb.h"
+#include "gromacs/topology/atoms.h"
+#include "gromacs/topology/block.h"
 #include "gromacs/topology/invblock.h"
+#include "gromacs/topology/residuetypes.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
-#include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 
-const char gmx_residuetype_undefined[] = "Other";
-
-struct gmx_residuetype
-{
-    int      n;
-    char **  resname;
-    char **  restype;
-
-};
-
-
 static gmx_bool gmx_ask_yesno(gmx_bool bASK)
 {
     char c;
@@ -182,8 +173,6 @@ static void
 p_status(const char **restype, int nres, const char **typenames, int ntypes)
 {
     int   i, j;
-    int   found;
-
     int * counter;
 
     snew(counter, ntypes);
@@ -193,7 +182,6 @@ p_status(const char **restype, int nres, const char **typenames, int ntypes)
     }
     for (i = 0; i < nres; i++)
     {
-        found = 0;
         for (j = 0; j < ntypes; j++)
         {
             if (!gmx_strcasecmp(restype[i], typenames[j]))
@@ -215,7 +203,7 @@ p_status(const char **restype, int nres, const char **typenames, int ntypes)
 }
 
 
-atom_id *
+static atom_id *
 mk_aid(t_atoms *atoms, const char ** restype, const char * typestring, int *nra, gmx_bool bMatch)
 /* Make an array of atom_ids for all atoms with residuetypes matching typestring, or the opposite if bMatch is false */
 {
@@ -371,7 +359,7 @@ typedef struct gmx_help_make_index_group
     /** The set of atom names that will be used to form this index group */
     const char **defining_atomnames;
     /** Size of the defining_atomnames array */
-    const int    num_defining_atomnames;
+    int          num_defining_atomnames;
     /** Name of this index group */
     const char  *group_name;
     /** Whether the above atom names name the atoms in the group, or
@@ -422,7 +410,7 @@ static void analyse_prot(const char ** restype, t_atoms *atoms,
 
     int         n, j;
     atom_id    *aid;
-    int         nra, nnpres, npres;
+    int         nra, npres;
     gmx_bool    match;
     char        ndx_name[STRLEN], *atnm;
     int         i;
@@ -580,7 +568,6 @@ static void analyse_prot(const char ** restype, t_atoms *atoms,
             if (nra > 0)
             {
                 add_grp(gb, gn, nra, aid, "SwapSC-CO");
-                nra = 0;
             }
         }
     }
@@ -588,245 +575,6 @@ static void analyse_prot(const char ** restype, t_atoms *atoms,
 }
 
 
-
-
-/* Return 0 if the name was found, otherwise -1.
- * p_restype is set to a pointer to the type name, or 'Other' if we did not find it.
- */
-int
-gmx_residuetype_get_type(gmx_residuetype_t rt, const char * resname, const char ** p_restype)
-{
-    int    i, rc;
-
-    rc = -1;
-    for (i = 0; i < rt->n && rc; i++)
-    {
-        rc = gmx_strcasecmp(rt->resname[i], resname);
-    }
-
-    *p_restype = (rc == 0) ? rt->restype[i-1] : gmx_residuetype_undefined;
-
-    return rc;
-}
-
-int
-gmx_residuetype_add(gmx_residuetype_t rt, const char *newresname, const char *newrestype)
-{
-    int           i;
-    int           found;
-    const char *  p_oldtype;
-
-    found = !gmx_residuetype_get_type(rt, newresname, &p_oldtype);
-
-    if (found && gmx_strcasecmp(p_oldtype, newrestype))
-    {
-        fprintf(stderr, "Warning: Residue '%s' already present with type '%s' in database, ignoring new type '%s'.",
-                newresname, p_oldtype, newrestype);
-    }
-
-    if (found == 0)
-    {
-        srenew(rt->resname, rt->n+1);
-        srenew(rt->restype, rt->n+1);
-        rt->resname[rt->n] = strdup(newresname);
-        rt->restype[rt->n] = strdup(newrestype);
-        rt->n++;
-    }
-
-    return 0;
-}
-
-
-int
-gmx_residuetype_init(gmx_residuetype_t *prt)
-{
-    FILE                 *  db;
-    char                    line[STRLEN];
-    char                    resname[STRLEN], restype[STRLEN], dum[STRLEN];
-    char                 *  p;
-    int                     i;
-    struct gmx_residuetype *rt;
-
-    snew(rt, 1);
-    *prt = rt;
-
-    rt->n        = 0;
-    rt->resname  = NULL;
-    rt->restype  = NULL;
-
-    db = libopen("residuetypes.dat");
-
-    while (get_a_line(db, line, STRLEN))
-    {
-        strip_comment(line);
-        trim(line);
-        if (line[0] != '\0')
-        {
-            if (sscanf(line, "%s %s %s", resname, restype, dum) != 2)
-            {
-                gmx_fatal(FARGS, "Incorrect number of columns (2 expected) for line in residuetypes.dat");
-            }
-            gmx_residuetype_add(rt, resname, restype);
-        }
-    }
-
-    fclose(db);
-
-    return 0;
-}
-
-
-
-int
-gmx_residuetype_destroy(gmx_residuetype_t rt)
-{
-    int i;
-
-    for (i = 0; i < rt->n; i++)
-    {
-        sfree(rt->resname[i]);
-        sfree(rt->restype[i]);
-    }
-    sfree(rt->resname);
-    sfree(rt->restype);
-    sfree(rt);
-
-    return 0;
-}
-
-int
-gmx_residuetype_get_alltypes(gmx_residuetype_t    rt,
-                             const char ***       p_typenames,
-                             int *                ntypes)
-{
-    int            i, j, n;
-    int            found;
-    const char **  my_typename;
-    char       *   p;
-
-    n = 0;
-
-    my_typename = NULL;
-    for (i = 0; i < rt->n; i++)
-    {
-        p     = rt->restype[i];
-        found = 0;
-        for (j = 0; j < n && !found; j++)
-        {
-            found = !gmx_strcasecmp(p, my_typename[j]);
-        }
-
-        if (!found)
-        {
-            srenew(my_typename, n+1);
-            my_typename[n] = p;
-            n++;
-        }
-    }
-    *ntypes      = n;
-    *p_typenames = my_typename;
-
-    return 0;
-}
-
-
-
-gmx_bool
-gmx_residuetype_is_protein(gmx_residuetype_t rt, const char *resnm)
-{
-    gmx_bool    rc;
-    const char *p_type;
-
-    if (gmx_residuetype_get_type(rt, resnm, &p_type) == 0 &&
-        gmx_strcasecmp(p_type, "Protein") == 0)
-    {
-        rc = TRUE;
-    }
-    else
-    {
-        rc = FALSE;
-    }
-    return rc;
-}
-
-gmx_bool
-gmx_residuetype_is_dna(gmx_residuetype_t rt, const char *resnm)
-{
-    gmx_bool    rc;
-    const char *p_type;
-
-    if (gmx_residuetype_get_type(rt, resnm, &p_type) == 0 &&
-        gmx_strcasecmp(p_type, "DNA") == 0)
-    {
-        rc = TRUE;
-    }
-    else
-    {
-        rc = FALSE;
-    }
-    return rc;
-}
-
-gmx_bool
-gmx_residuetype_is_rna(gmx_residuetype_t rt, const char *resnm)
-{
-    gmx_bool    rc;
-    const char *p_type;
-
-    if (gmx_residuetype_get_type(rt, resnm, &p_type) == 0 &&
-        gmx_strcasecmp(p_type, "RNA") == 0)
-    {
-        rc = TRUE;
-    }
-    else
-    {
-        rc = FALSE;
-    }
-    return rc;
-}
-
-/* Return the size of the arrays */
-int
-gmx_residuetype_get_size(gmx_residuetype_t rt)
-{
-    return rt->n;
-}
-
-/* Search for a residuetype with name resnm within the
- * gmx_residuetype database. Return the index if found,
- * otherwise -1.
- */
-int
-gmx_residuetype_get_index(gmx_residuetype_t rt, const char *resnm)
-{
-    int i, rc;
-
-    rc = -1;
-    for (i = 0; i < rt->n && rc; i++)
-    {
-        rc = gmx_strcasecmp(rt->resname[i], resnm);
-    }
-
-    return (0 == rc) ? i-1 : -1;
-}
-
-/* Return the name of the residuetype with the given index, or
- * NULL if not found. */
-const char *
-gmx_residuetype_get_name(gmx_residuetype_t rt, int index)
-{
-    if (index >= 0 && index < rt->n)
-    {
-        return rt->resname[index];
-    }
-    else
-    {
-        return NULL;
-    }
-}
-
-
-
 void analyse(t_atoms *atoms, t_blocka *gb, char ***gn, gmx_bool bASK, gmx_bool bVerb)
 {
     gmx_residuetype_t rt = NULL;
@@ -835,9 +583,7 @@ void analyse(t_atoms *atoms, t_blocka *gb, char ***gn, gmx_bool bASK, gmx_bool b
     const char    **  restype;
     int               nra;
     int               i, k;
-    size_t            j;
     int               ntypes;
-    char           *  p;
     const char     ** p_typename;
     int               iwater, iion;
     int               nwater, nion;
@@ -874,6 +620,7 @@ void analyse(t_atoms *atoms, t_blocka *gb, char ***gn, gmx_bool bASK, gmx_bool b
         found = 0;
         for (k = 0; k < ntypes && !found; k++)
         {
+            assert(p_typename != NULL);
             found = !strcmp(restype[i], p_typename[k]);
         }
         if (!found)
@@ -1007,81 +754,52 @@ t_blocka *init_index(const char *gfile, char ***grpname)
 {
     FILE      *in;
     t_blocka  *b;
-    int        a, maxentries;
-    int        i, j, ng, nread;
+    int        maxentries;
+    int        i, j;
     char       line[STRLEN], *pt, str[STRLEN];
 
     in = gmx_fio_fopen(gfile, "r");
     snew(b, 1);
-    get_a_line(in, line, STRLEN);
-    if (line[0] == '[')
+    b->nr      = 0;
+    b->index   = NULL;
+    b->nra     = 0;
+    b->a       = NULL;
+    *grpname   = NULL;
+    maxentries = 0;
+    while (get_a_line(in, line, STRLEN))
     {
-        /* new format */
-        b->nr      = 0;
-        b->index   = NULL;
-        b->nra     = 0;
-        b->a       = NULL;
-        *grpname   = NULL;
-        maxentries = 0;
-        do
+        if (get_header(line, str))
         {
-            if (get_header(line, str))
+            b->nr++;
+            srenew(b->index, b->nr+1);
+            srenew(*grpname, b->nr);
+            if (b->nr == 1)
             {
-                b->nr++;
-                srenew(b->index, b->nr+1);
-                srenew(*grpname, b->nr);
-                if (b->nr == 1)
-                {
-                    b->index[0] = 0;
-                }
-                b->index[b->nr]     = b->index[b->nr-1];
-                (*grpname)[b->nr-1] = strdup(str);
-            }
-            else
-            {
-                if (b->nr == 0)
-                {
-                    gmx_fatal(FARGS, "The first header of your indexfile is invalid");
-                }
-                pt = line;
-                while (sscanf(pt, "%s", str) == 1)
-                {
-                    i = b->index[b->nr];
-                    if (i >= maxentries)
-                    {
-                        maxentries += 1024;
-                        srenew(b->a, maxentries);
-                    }
-                    b->a[i] = strtol(str, NULL, 10)-1;
-                    b->index[b->nr]++;
-                    (b->nra)++;
-                    pt = strstr(pt, str)+strlen(str);
-                }
+                b->index[0] = 0;
             }
+            b->index[b->nr]     = b->index[b->nr-1];
+            (*grpname)[b->nr-1] = strdup(str);
         }
-        while (get_a_line(in, line, STRLEN));
-    }
-    else
-    {
-        /* old format */
-        sscanf(line, "%d%d", &b->nr, &b->nra);
-        snew(b->index, b->nr+1);
-        snew(*grpname, b->nr);
-        b->index[0] = 0;
-        snew(b->a, b->nra);
-        for (i = 0; (i < b->nr); i++)
+        else
         {
-            nread         = fscanf(in, "%s%d", str, &ng);
-            (*grpname)[i] = strdup(str);
-            b->index[i+1] = b->index[i]+ng;
-            if (b->index[i+1] > b->nra)
+            if (b->nr == 0)
             {
-                gmx_fatal(FARGS, "Something wrong in your indexfile at group %s", str);
+                gmx_fatal(FARGS, "The first header of your indexfile is invalid");
             }
-            for (j = 0; (j < ng); j++)
+            pt = line;
+            while (sscanf(pt, "%s", str) == 1)
             {
-                nread               = fscanf(in, "%d", &a);
-                b->a[b->index[i]+j] = a;
+                i = b->index[b->nr];
+                if (i >= maxentries)
+                {
+                    maxentries += 1024;
+                    srenew(b->a, maxentries);
+                }
+                assert(b->a != NULL); // for clang analyzer
+                b->a[i] = strtol(str, NULL, 10)-1;
+                b->index[b->nr]++;
+                (b->nra)++;
+                pt = strstr(pt, str)+strlen(str);
             }
         }
     }
@@ -1089,6 +807,7 @@ t_blocka *init_index(const char *gfile, char ***grpname)
 
     for (i = 0; (i < b->nr); i++)
     {
+        assert(b->a != NULL); // for clang analyzer
         for (j = b->index[i]; (j < b->index[i+1]); j++)
         {
             if (b->a[j] < 0)
@@ -1329,7 +1048,7 @@ t_cluster_ndx *cluster_index(FILE *fplog, const char *ndx)
     c->maxframe  = -1;
     for (i = 0; (i < c->clust->nra); i++)
     {
-        c->maxframe = max(c->maxframe, c->clust->a[i]);
+        c->maxframe = std::max(c->maxframe, c->clust->a[i]);
     }
     fprintf(fplog ? fplog : stdout,
             "There are %d clusters containing %d structures, highest framenr is %d\n",
similarity index 79%
rename from src/gromacs/legacyheaders/index.h
rename to src/gromacs/topology/index.h
index 940dc0820b8c3b61ab7fa83847af1dc924e22c12..4bba1f80217541ebd406653a493be3fa0698d0c2 100644 (file)
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
-
-#ifndef _index_h
-#define _index_h
+#ifndef GMX_TOPOLOGY_INDEX_H
+#define GMX_TOPOLOGY_INDEX_H
 
 #include <stdio.h>
 
-#include "types/simple.h"
+#include "../legacyheaders/types/simple.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -96,53 +95,6 @@ typedef struct {
 
 t_cluster_ndx *cluster_index(FILE *fplog, const char *ndx);
 
-typedef struct {
-    int    n;
-    char **name;
-} t_names;
-
-typedef struct gmx_residuetype *
-    gmx_residuetype_t;
-
-int
-gmx_residuetype_init(gmx_residuetype_t *rt);
-
-int
-gmx_residuetype_destroy(gmx_residuetype_t rt);
-
-int
-gmx_residuetype_get_type(gmx_residuetype_t rt, const char * resname, const char ** p_restype);
-
-int
-gmx_residuetype_add(gmx_residuetype_t rt, const char *newresname, const char *newrestype);
-
-int
-gmx_residuetype_get_alltypes(gmx_residuetype_t    rt,
-                             const char ***       p_typenames,
-                             int *                ntypes);
-
-gmx_bool
-gmx_residuetype_is_protein(gmx_residuetype_t rt, const char *resnm);
-
-gmx_bool
-gmx_residuetype_is_dna(gmx_residuetype_t rt, const char *resnm);
-
-gmx_bool
-gmx_residuetype_is_rna(gmx_residuetype_t rt, const char *resnm);
-
-int
-gmx_residuetype_get_size(gmx_residuetype_t rt);
-
-int
-gmx_residuetype_get_index(gmx_residuetype_t rt, const char *resnm);
-
-const char *
-gmx_residuetype_get_name(gmx_residuetype_t rt, int index);
-
-
-
-
-
 
 void write_index(const char *outf, struct t_blocka *b, char **gnames, gmx_bool bDuplicate, int natoms);
 /* Writes index blocks to outf (writes an indexfile) */
@@ -163,4 +115,4 @@ int find_group(char s[], int ngrps, char **grpname);
 }
 #endif
 
-#endif  /* _index_h */
+#endif
diff --git a/src/gromacs/topology/residuetypes.cpp b/src/gromacs/topology/residuetypes.cpp
new file mode 100644 (file)
index 0000000..461405b
--- /dev/null
@@ -0,0 +1,277 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2010,2013,2014, 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.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#include "gromacs/topology/residuetypes.h"
+
+#include <cassert>
+#include <cstdio>
+
+#include "gromacs/fileio/strdb.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
+#include "gromacs/utility/smalloc.h"
+
+const char gmx_residuetype_undefined[] = "Other";
+
+struct gmx_residuetype
+{
+    int      n;
+    char **  resname;
+    char **  restype;
+};
+
+int
+gmx_residuetype_init(gmx_residuetype_t *prt)
+{
+    FILE                 *  db;
+    char                    line[STRLEN];
+    char                    resname[STRLEN], restype[STRLEN], dum[STRLEN];
+    struct gmx_residuetype *rt;
+
+    snew(rt, 1);
+    *prt = rt;
+
+    rt->n        = 0;
+    rt->resname  = NULL;
+    rt->restype  = NULL;
+
+    db = libopen("residuetypes.dat");
+
+    while (get_a_line(db, line, STRLEN))
+    {
+        strip_comment(line);
+        trim(line);
+        if (line[0] != '\0')
+        {
+            if (sscanf(line, "%1000s %1000s %1000s", resname, restype, dum) != 2)
+            {
+                gmx_fatal(FARGS, "Incorrect number of columns (2 expected) for line in residuetypes.dat");
+            }
+            gmx_residuetype_add(rt, resname, restype);
+        }
+    }
+
+    fclose(db);
+
+    return 0;
+}
+
+int
+gmx_residuetype_destroy(gmx_residuetype_t rt)
+{
+    int i;
+
+    for (i = 0; i < rt->n; i++)
+    {
+        sfree(rt->resname[i]);
+        sfree(rt->restype[i]);
+    }
+    sfree(rt->resname);
+    sfree(rt->restype);
+    sfree(rt);
+
+    return 0;
+}
+
+/* Return 0 if the name was found, otherwise -1.
+ * p_restype is set to a pointer to the type name, or 'Other' if we did not find it.
+ */
+int
+gmx_residuetype_get_type(gmx_residuetype_t rt, const char * resname, const char ** p_restype)
+{
+    int    i, rc;
+
+    rc = -1;
+    for (i = 0; i < rt->n && rc; i++)
+    {
+        rc = gmx_strcasecmp(rt->resname[i], resname);
+    }
+
+    *p_restype = (rc == 0) ? rt->restype[i-1] : gmx_residuetype_undefined;
+
+    return rc;
+}
+
+int
+gmx_residuetype_add(gmx_residuetype_t rt, const char *newresname, const char *newrestype)
+{
+    int           found;
+    const char *  p_oldtype;
+
+    found = !gmx_residuetype_get_type(rt, newresname, &p_oldtype);
+
+    if (found && gmx_strcasecmp(p_oldtype, newrestype))
+    {
+        fprintf(stderr, "Warning: Residue '%s' already present with type '%s' in database, ignoring new type '%s'.",
+                newresname, p_oldtype, newrestype);
+    }
+
+    if (found == 0)
+    {
+        srenew(rt->resname, rt->n+1);
+        srenew(rt->restype, rt->n+1);
+        rt->resname[rt->n] = gmx_strdup(newresname);
+        rt->restype[rt->n] = gmx_strdup(newrestype);
+        rt->n++;
+    }
+
+    return 0;
+}
+
+int
+gmx_residuetype_get_alltypes(gmx_residuetype_t    rt,
+                             const char ***       p_typenames,
+                             int *                ntypes)
+{
+    int            i, n;
+    const char **  my_typename;
+
+    n           = 0;
+    my_typename = NULL;
+    for (i = 0; i < rt->n; i++)
+    {
+        const char *const p      = rt->restype[i];
+        bool              bFound = false;
+        for (int j = 0; j < n && !bFound; j++)
+        {
+            assert(my_typename != NULL);
+            bFound = !gmx_strcasecmp(p, my_typename[j]);
+        }
+        if (!bFound)
+        {
+            srenew(my_typename, n+1);
+            my_typename[n] = p;
+            n++;
+        }
+    }
+    *ntypes      = n;
+    *p_typenames = my_typename;
+
+    return 0;
+}
+
+gmx_bool
+gmx_residuetype_is_protein(gmx_residuetype_t rt, const char *resnm)
+{
+    gmx_bool    rc;
+    const char *p_type;
+
+    if (gmx_residuetype_get_type(rt, resnm, &p_type) == 0 &&
+        gmx_strcasecmp(p_type, "Protein") == 0)
+    {
+        rc = TRUE;
+    }
+    else
+    {
+        rc = FALSE;
+    }
+    return rc;
+}
+
+gmx_bool
+gmx_residuetype_is_dna(gmx_residuetype_t rt, const char *resnm)
+{
+    gmx_bool    rc;
+    const char *p_type;
+
+    if (gmx_residuetype_get_type(rt, resnm, &p_type) == 0 &&
+        gmx_strcasecmp(p_type, "DNA") == 0)
+    {
+        rc = TRUE;
+    }
+    else
+    {
+        rc = FALSE;
+    }
+    return rc;
+}
+
+gmx_bool
+gmx_residuetype_is_rna(gmx_residuetype_t rt, const char *resnm)
+{
+    gmx_bool    rc;
+    const char *p_type;
+
+    if (gmx_residuetype_get_type(rt, resnm, &p_type) == 0 &&
+        gmx_strcasecmp(p_type, "RNA") == 0)
+    {
+        rc = TRUE;
+    }
+    else
+    {
+        rc = FALSE;
+    }
+    return rc;
+}
+
+/* Return the size of the arrays */
+int
+gmx_residuetype_get_size(gmx_residuetype_t rt)
+{
+    return rt->n;
+}
+
+/* Search for a residuetype with name resnm within the
+ * gmx_residuetype database. Return the index if found,
+ * otherwise -1.
+ */
+int
+gmx_residuetype_get_index(gmx_residuetype_t rt, const char *resnm)
+{
+    int i, rc;
+
+    rc = -1;
+    for (i = 0; i < rt->n && rc; i++)
+    {
+        rc = gmx_strcasecmp(rt->resname[i], resnm);
+    }
+
+    return (0 == rc) ? i-1 : -1;
+}
+
+/* Return the name of the residuetype with the given index, or
+ * NULL if not found. */
+const char *
+gmx_residuetype_get_name(gmx_residuetype_t rt, int index)
+{
+    if (index >= 0 && index < rt->n)
+    {
+        return rt->resname[index];
+    }
+    else
+    {
+        return NULL;
+    }
+}
diff --git a/src/gromacs/topology/residuetypes.h b/src/gromacs/topology/residuetypes.h
new file mode 100644 (file)
index 0000000..82c24e8
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2010,2014, 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.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+#ifndef GMX_TOPOLOGY_RESIDUETYPES_H
+#define GMX_TOPOLOGY_RESIDUETYPES_H
+
+#include "gromacs/utility/basedefinitions.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef struct gmx_residuetype *gmx_residuetype_t;
+
+int
+gmx_residuetype_init(gmx_residuetype_t *rt);
+
+int
+gmx_residuetype_destroy(gmx_residuetype_t rt);
+
+int
+gmx_residuetype_get_type(gmx_residuetype_t rt, const char *resname, const char **p_restype);
+
+int
+gmx_residuetype_add(gmx_residuetype_t rt, const char *newresname, const char *newrestype);
+
+int
+gmx_residuetype_get_alltypes(gmx_residuetype_t    rt,
+                             const char        ***p_typenames,
+                             int                 *ntypes);
+
+gmx_bool
+gmx_residuetype_is_protein(gmx_residuetype_t rt, const char *resnm);
+
+gmx_bool
+gmx_residuetype_is_dna(gmx_residuetype_t rt, const char *resnm);
+
+gmx_bool
+gmx_residuetype_is_rna(gmx_residuetype_t rt, const char *resnm);
+
+int
+gmx_residuetype_get_size(gmx_residuetype_t rt);
+
+int
+gmx_residuetype_get_index(gmx_residuetype_t rt, const char *resnm);
+
+const char *
+gmx_residuetype_get_name(gmx_residuetype_t rt, int index);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index b7165f94bf776076cbdf8a6f32d214f61a0a905c..d80bc883aee8221a2d4c0bc9d4d3ea966b95d737 100644 (file)
@@ -108,20 +108,20 @@ TrajectoryAnalysisCommandLineRunner::Impl::parseOptions(
         SelectionCollection *selections,
         int *argc, char *argv[])
 {
-    Options options(NULL, NULL);
-    Options moduleOptions(module_->name(), module_->description());
-    Options commonOptions("common", "Common analysis control");
-    Options selectionOptions("selection", "Common selection control");
-    module_->initOptions(&moduleOptions, settings);
-    common->initOptions(&commonOptions);
-    selections->initOptions(&selectionOptions);
+    SelectionOptionManager seloptManager(selections);
+    Options                options(NULL, NULL);
+    Options                moduleOptions(module_->name(), module_->description());
+    Options                commonOptions("common", "Common analysis control");
+    Options                selectionOptions("selection", "Common selection control");
 
+    options.addManager(&seloptManager);
     options.addSubSection(&commonOptions);
     options.addSubSection(&selectionOptions);
     options.addSubSection(&moduleOptions);
 
-    SelectionOptionManager seloptManager(selections);
-    setManagerForSelectionOptions(&options, &seloptManager);
+    module_->initOptions(&moduleOptions, settings);
+    common->initOptions(&commonOptions);
+    selections->initOptions(&selectionOptions);
 
     {
         CommandLineParser  parser(&options);
@@ -254,21 +254,20 @@ TrajectoryAnalysisCommandLineRunner::writeHelp(const CommandLineHelpContext &con
     TrajectoryAnalysisSettings      settings;
     TrajectoryAnalysisRunnerCommon  common(&settings);
 
-    Options options(NULL, NULL);
-    Options moduleOptions(impl_->module_->name(), impl_->module_->description());
-    Options commonOptions("common", "Common analysis control");
-    Options selectionOptions("selection", "Common selection control");
-
-    impl_->module_->initOptions(&moduleOptions, &settings);
-    common.initOptions(&commonOptions);
-    selections.initOptions(&selectionOptions);
+    SelectionOptionManager          seloptManager(&selections);
+    Options                         options(NULL, NULL);
+    Options                         moduleOptions(impl_->module_->name(), impl_->module_->description());
+    Options                         commonOptions("common", "Common analysis control");
+    Options                         selectionOptions("selection", "Common selection control");
 
+    options.addManager(&seloptManager);
     options.addSubSection(&commonOptions);
     options.addSubSection(&selectionOptions);
     options.addSubSection(&moduleOptions);
 
-    SelectionOptionManager seloptManager(&selections);
-    setManagerForSelectionOptions(&options, &seloptManager);
+    impl_->module_->initOptions(&moduleOptions, &settings);
+    common.initOptions(&commonOptions);
+    selections.initOptions(&selectionOptions);
 
     CommandLineHelpWriter(options)
         .setShowDescriptions(true)
index 56a2c725c7f3334407f628bb1f52d08c114d25ac..88c78dc9be381fbf3cde0db6ae2127b585800d4f 100644 (file)
@@ -46,7 +46,6 @@
 #include "mdebin.h"
 #include "nrnb.h"
 #include "calcmu.h"
-#include "index.h"
 #include "vsite.h"
 #include "update.h"
 #include "ns.h"
index 04ebc2a94d1b69c1b8c0266592c37fd9793ee495..0bd722ab1ffd04c72e902cc0bf82e2445859e384 100644 (file)
@@ -45,7 +45,7 @@
 #include "macros.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/essentialdynamics/edsam.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "names.h"
 #include "gromacs/topology/mtop_util.h"
 #include "gromacs/fileio/tpxio.h"
index 8534a3a765f9d04ed6438728062ba324178c1cbc..a8888546185e75033231426d088679e4cf5a86e5 100644 (file)
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
 #include "macros.h"
-#include "index.h"
+#include "gromacs/topology/index.h"
 #include "xdlghi.h"
 #include "dialogs.h"
-#include "index.h"
 #include "gromacs/utility/fatalerror.h"
 
 t_filter *init_filter(t_atoms *atoms, const char *fn, int natom_trx)
index cedcc1dfe6c7b650ef89e1f0b2260767409ed224..8ca224cb9d9250cd9627441b1e409d0c0456b68a 100644 (file)
@@ -98,6 +98,7 @@ if (CPPCHECK_EXECUTABLE AND UNIX)
         --suppress=unnecessaryForwardDeclaration
         --suppress=invalidscanf:src/gromacs/fileio/matio.cpp
         --suppress=invalidscanf:src/gromacs/fileio/xvgr.cpp
+        --suppress=invalidscanf:src/gromacs/topology/index.cpp
         --suppress=invalidscanf:src/gromacs/gmxpreprocess/pdb2top.cpp)
 
     # This list will hold the list of all files with cppcheck errors