#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"
#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)
#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[])
#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"
#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"
#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;
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;
* 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);
{
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
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
}
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;"
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);
}
#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,
/* 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
{
}
}
-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;
}
}
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;
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);
}
}
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. */
#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"
#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"
#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,
#include "gromacs/utility/futil.h"
#include "gstat.h"
#include "gromacs/math/vec.h"
-#include "index.h"
#include "gromacs/utility/fatalerror.h"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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,
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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
#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"
#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"
#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"
#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"
#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"
#include "macros.h"
#include "copyrite.h"
#include "gromacs/utility/futil.h"
-#include "index.h"
#include "gstat.h"
#include "txtdump.h"
#include "eigio.h"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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" {
#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"
#ifndef _nsfactor_h
#define _nsfactor_h
-#include "gromacs/legacyheaders/index.h"
#include "gromacs/legacyheaders/oenv.h"
#include "gromacs/legacyheaders/types/simple.h"
#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"
#ifndef _sfactor_h
#define _sfactor_h
-#include "index.h"
#include "types/simple.h"
#include "../math/gmxcomplex.h"
#include "oenv.h"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#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"
#include "names.h"
#include "gromacs/utility/fatalerror.h"
#include "macros.h"
-#include "index.h"
#include "readinp.h"
#include "readir.h"
#include "mdatoms.h"
#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"
#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"
#ifndef GMX_GMXPREPROCESS_XLATE_H
#define GMX_GMXPREPROCESS_XLATE_H
-#include "index.h"
+#include "gromacs/topology/residuetypes.h"
#ifdef __cplusplus
extern "C" {
class AbstractOptionStorage;
template <typename T> class OptionStorageTemplate;
+class OptionManagerContainer;
class Options;
//! Smart pointer for managing an AbstractOptionStorage object.
/*! \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.
*
* 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; }
* BooleanOption
*/
-AbstractOptionStoragePointer BooleanOption::createStorage() const
+AbstractOptionStoragePointer
+BooleanOption::createStorage(const OptionManagerContainer & /*managers*/) const
{
return AbstractOptionStoragePointer(new BooleanOptionStorage(*this));
}
* IntegerOption
*/
-AbstractOptionStoragePointer IntegerOption::createStorage() const
+AbstractOptionStoragePointer
+IntegerOption::createStorage(const OptionManagerContainer & /*managers*/) const
{
return AbstractOptionStoragePointer(new IntegerOptionStorage(*this));
}
* Int64Option
*/
-AbstractOptionStoragePointer Int64Option::createStorage() const
+AbstractOptionStoragePointer
+Int64Option::createStorage(const OptionManagerContainer & /*managers*/) const
{
return AbstractOptionStoragePointer(new Int64OptionStorage(*this));
}
* DoubleOption
*/
-AbstractOptionStoragePointer DoubleOption::createStorage() const
+AbstractOptionStoragePointer
+DoubleOption::createStorage(const OptionManagerContainer & /*managers*/) const
{
return AbstractOptionStoragePointer(new DoubleOptionStorage(*this));
}
* FloatOption
*/
-AbstractOptionStoragePointer FloatOption::createStorage() const
+AbstractOptionStoragePointer
+FloatOption::createStorage(const OptionManagerContainer & /*managers*/) const
{
return AbstractOptionStoragePointer(new FloatOptionStorage(*this));
}
* StringOption
*/
-AbstractOptionStoragePointer StringOption::createStorage() const
+AbstractOptionStoragePointer
+StringOption::createStorage(const OptionManagerContainer & /*managers*/) const
{
return AbstractOptionStoragePointer(new StringOptionStorage(*this));
}
private:
//! Creates a BooleanOptionStorage object.
- virtual AbstractOptionStoragePointer createStorage() const;
+ virtual AbstractOptionStoragePointer createStorage(
+ const OptionManagerContainer &managers) const;
};
/*! \brief
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
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
private:
//! Creates a DoubleOptionStorage object.
- virtual AbstractOptionStoragePointer createStorage() const;
+ virtual AbstractOptionStoragePointer createStorage(
+ const OptionManagerContainer &managers) const;
bool bTime_;
private:
//! Creates a FloatOptionStorage object.
- virtual AbstractOptionStoragePointer createStorage() const;
+ virtual AbstractOptionStoragePointer createStorage(
+ const OptionManagerContainer &managers) const;
bool bTime_;
private:
//! Creates a StringOptionStorage object.
- virtual AbstractOptionStoragePointer createStorage() const;
+ virtual AbstractOptionStoragePointer createStorage(
+ const OptionManagerContainer &managers) const;
const char *const *enumValues_;
int enumValuesCount_;
#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"
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;
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 ®istry = FileTypeRegistry::instance();
- const FileTypeHandler &typeHandler = registry.handlerForType(filetype, legacyType);
if (typeHandler.hasKnownExtension(value))
{
return value;
* 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 ®istry = 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";
}
std::string FileNameOptionStorage::formatExtraDescription() const
{
- const FileTypeRegistry ®istry = 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;
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 ®istry = 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;
bool FileNameOptionStorage::isDirectoryOption() const
{
- return legacyType_ == efRND;
+ return fileType_ == efRND;
}
-ConstArrayRef<const char *> FileNameOptionStorage::extensions() const
+const char *FileNameOptionStorage::defaultExtension() const
{
- const FileTypeRegistry ®istry = 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;
}
/********************************************************************
{
}
-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();
return option().isDirectoryOption();
}
+const char *FileNameOptionInfo::defaultExtension() const
+{
+ return option().defaultExtension();
+}
+
FileNameOptionInfo::ExtensionList FileNameOptionInfo::extensions() const
{
return option().extensions();
* 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
#define GMX_OPTIONS_FILENAMEOPTION_H
#include <string>
+#include <vector>
#include "abstractoption.h"
#include "optionfiletype.h"
//! 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)
{
}
* 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.
*
*/
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(); }
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_;
{
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.
//! 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;
};
#include "gromacs/options/basicoptions.h"
#include "gromacs/options/filenameoption.h"
#include "gromacs/options/options.h"
-#include "gromacs/options/optionsvisitor.h"
namespace gmx
{
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
#include <string>
+#include "options.h"
+
#include "../utility/common.h"
namespace gmx
* 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.
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
#define GMX_OPTIONS_FILENAMEOPTIONSTORAGE_H
#include <string>
+#include <vector>
#include "filenameoption.h"
#include "optionfiletype.h"
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()
//! \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);
FileNameOptionInfo info_;
FileNameOptionManager *manager_;
- OptionFileType filetype_;
- int legacyType_;
+ int fileType_;
bool bRead_;
bool bWrite_;
bool bLibrary_;
--- /dev/null
+/*
+ * 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
/*
* 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.
#include <vector>
#include "abstractoption.h"
+#include "optionmanagercontainer.h"
#include "options.h"
namespace gmx
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.
*
namespace gmx
{
+/********************************************************************
+ * OptionManagerInterface
+ */
+
+OptionManagerInterface::~OptionManagerInterface()
+{
+}
+
/********************************************************************
* Options::Impl
*/
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");
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()));
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.
*
*/
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.
*
* 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
}
private:
- virtual gmx::AbstractOptionStoragePointer createStorage() const
+ virtual gmx::AbstractOptionStoragePointer createStorage(
+ const gmx::OptionManagerContainer & /*managers*/) const
{
return gmx::AbstractOptionStoragePointer(new MockOptionStorage(*this));
}
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);
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());
/*
* 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.
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());
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);
/*
* 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
{
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)
/*
* 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.
//! 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.
*
#include <string.h>
#include "gromacs/utility/futil.h"
-#include "index.h"
#include "typedefs.h"
#include "types/commrec.h"
#include "network.h"
#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"
#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"
/*
* 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.
explicit SelectionFileOption(const char *name);
private:
- virtual AbstractOptionStoragePointer createStorage() const;
+ virtual AbstractOptionStoragePointer createStorage(
+ const OptionManagerContainer &managers) const;
};
/*! \libinternal \brief
* Does not throw.
*/
explicit SelectionFileOptionInfo(SelectionFileOptionStorage *option);
-
- //! \copydoc SelectionOptionInfo::setManager()
- void setManager(SelectionOptionManager *manager);
-
- private:
- SelectionFileOptionStorage &option();
- const SelectionFileOptionStorage &option() const;
};
} // namespace gmx
* 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
#include <string>
+#include "gromacs/options/optionmanagercontainer.h"
#include "gromacs/selection/selection.h"
#include "gromacs/selection/selectionoptionmanager.h"
#include "gromacs/utility/exceptions.h"
* 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);
}
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()))
{
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();
}
}
return static_cast<const SelectionOptionStorage &>(OptionInfo::option());
}
-void SelectionOptionInfo::setManager(SelectionOptionManager *manager)
-{
- option().setManager(manager);
-}
-
void SelectionOptionInfo::setValueCount(int count)
{
option().setAllowedValueCount(count);
* 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>()));
}
* 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()
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()
{
}
-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
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
*
* 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.
using MyBase::defaultValue;
using MyBase::defaultValueIfSet;
- virtual AbstractOptionStoragePointer createStorage() const;
+ virtual AbstractOptionStoragePointer createStorage(
+ const OptionManagerContainer &managers) const;
const char *defaultText_;
SelectionFlags selectionFlags_;
*/
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.
*
#include <cstdio>
-#include "gromacs/options/optionsvisitor.h"
#include "gromacs/selection/selection.h"
#include "gromacs/selection/selectioncollection.h"
#include "gromacs/selection/selectionoption.h"
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
#include <string>
+#include "../options/options.h"
#include "../utility/common.h"
namespace gmx
* 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
* parseRequestedFromStdin(), parseRequestedFromFile() or
* parseRequstedFromString().
*
- * \see setManagerForSelectionOptions()
- *
* \inpublicapi
* \ingroup module_selection
*/
-class SelectionOptionManager
+class SelectionOptionManager : public OptionManagerInterface
{
public:
/*! \brief
* \throws std::bad_alloc if out of memory.
*/
explicit SelectionOptionManager(SelectionCollection *selections);
- ~SelectionOptionManager();
+ virtual ~SelectionOptionManager();
/*! \brief
* Adds a selection option to be managed.
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
* 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.
*
virtual void processAll();
SelectionOptionInfo info_;
- SelectionOptionManager *manager_;
+ SelectionOptionManager &manager_;
std::string defaultText_;
SelectionFlags selectionFlags_;
};
public:
SelectionOptionTestBase();
- void setManager();
void loadTopology(const char *filename);
gmx::SelectionCollection sc_;
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);
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());
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());
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());
using gmx::SelectionOption;
ASSERT_NO_THROW_GMX(options_.addOption(
SelectionOption("sel").store(&sel)));
- setManager();
gmx::OptionsAssigner assigner(&options_);
EXPECT_NO_THROW_GMX(assigner.start());
using gmx::SelectionOption;
ASSERT_NO_THROW_GMX(options_.addOption(
SelectionOption("sel").store(&sel)));
- setManager();
gmx::OptionsAssigner assigner(&options_);
EXPECT_NO_THROW_GMX(assigner.start());
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());
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());
using gmx::SelectionOption;
options_.addOption(SelectionOption("sel").store(&sel)
.defaultSelectionText("all"));
- setManager();
EXPECT_NO_THROW_GMX(options_.finish());
using gmx::SelectionOption;
gmx::SelectionOptionInfo *info = options_.addOption(
SelectionOption("sel").storeVector(&sel).multiValue());
- setManager();
gmx::OptionsAssigner assigner(&options_);
EXPECT_NO_THROW_GMX(assigner.start());
using gmx::SelectionOption;
gmx::SelectionOptionInfo *info = options_.addOption(
SelectionOption("sel").store(&sel));
- setManager();
gmx::OptionsAssigner assigner(&options_);
EXPECT_NO_THROW_GMX(assigner.start());
using gmx::SelectionOption;
gmx::SelectionOptionInfo *info = options_.addOption(
SelectionOption("sel").storeVector(&sel).multiValue());
- setManager();
gmx::OptionsAssigner assigner(&options_);
EXPECT_NO_THROW_GMX(assigner.start());
using gmx::SelectionOption;
gmx::SelectionOptionInfo *info = options_.addOption(
SelectionOption("sel").storeVector(&sel).multiValue());
- setManager();
gmx::OptionsAssigner assigner(&options_);
EXPECT_NO_THROW_GMX(assigner.start());
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());
ASSERT_NO_THROW_GMX(options_.addOption(
SelectionOption("sel").store(sel).required()
.valueCount(2)));
- setManager();
gmx::OptionsAssigner assigner(&options_);
EXPECT_NO_THROW_GMX(assigner.start());
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());
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());
ASSERT_NO_THROW_GMX(options_.addOption(
SelectionOption("reqsel").storeVector(&reqsel)
.multiValue().required()));
- setManager();
gmx::OptionsAssigner assigner(&options_);
EXPECT_NO_THROW_GMX(assigner.start());
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"));
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"));
ASSERT_NO_THROW_GMX(options_.addOption(
SelectionOption("optsel").storeVector(&optsel)
.multiValue()));
- setManager();
gmx::OptionsAssigner assigner(&options_);
EXPECT_NO_THROW_GMX(assigner.start());
ASSERT_NO_THROW_GMX(options_.addOption(
SelectionOption("sel2").storeVector(&sel2)
.multiValue().required()));
- setManager();
gmx::OptionsAssigner assigner(&options_);
EXPECT_NO_THROW_GMX(assigner.start());
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"));
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());
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());
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());
#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"
#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"
atoms.h
block.h
idef.h
+ index.h
mtop_util.h
symtab.h
topology.h)
#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"
* 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;
p_status(const char **restype, int nres, const char **typenames, int ntypes)
{
int i, j;
- int found;
-
int * counter;
snew(counter, ntypes);
}
for (i = 0; i < nres; i++)
{
- found = 0;
for (j = 0; j < ntypes; j++)
{
if (!gmx_strcasecmp(restype[i], typenames[j]))
}
-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 */
{
/** 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
int n, j;
atom_id *aid;
- int nra, nnpres, npres;
+ int nra, npres;
gmx_bool match;
char ndx_name[STRLEN], *atnm;
int i;
if (nra > 0)
{
add_grp(gb, gn, nra, aid, "SwapSC-CO");
- nra = 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 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;
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;
found = 0;
for (k = 0; k < ntypes && !found; k++)
{
+ assert(p_typename != NULL);
found = !strcmp(restype[i], p_typename[k]);
}
if (!found)
{
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);
}
}
}
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)
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",
* 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" {
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) */
}
#endif
-#endif /* _index_h */
+#endif
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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
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);
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)
#include "mdebin.h"
#include "nrnb.h"
#include "calcmu.h"
-#include "index.h"
#include "vsite.h"
#include "update.h"
#include "ns.h"
#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"
#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)
--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