/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012, by the GROMACS development team, led by
- * David van der Spoel, Berk Hess, Erik Lindahl, and including many
- * others, as listed in the AUTHORS file in the top-level source
- * directory and at http://www.gromacs.org.
+ * 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.
*
* GROMACS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
#ifndef GMX_TRAJECTORYANALYSIS_CMDLINERUNNER_H
#define GMX_TRAJECTORYANALYSIS_CMDLINERUNNER_H
-#include "../utility/common.h"
+#include "gromacs/trajectoryanalysis/analysismodule.h"
+#include "gromacs/utility/common.h"
namespace gmx
{
-class HelpWriterContext;
-class TrajectoryAnalysisModule;
+class CommandLineModuleManager;
+class CommandLineHelpContext;
/*! \brief
* Runner class for command-line analysis tools.
class TrajectoryAnalysisCommandLineRunner
{
public:
+ /*! \brief
+ * Factory method type for creating a trajectory analysis module.
+ *
+ * This method allows the module creation to be postponed to be inside
+ * the try/catch block in runAsMain()/registerModule() implementation
+ * methods and still keep the implementation out of the header, making
+ * the ABI more stable.
+ */
+ typedef TrajectoryAnalysisModulePointer (*ModuleFactoryMethod)();
+
+ /*! \brief
+ * Implements a main() method that runs a given module.
+ *
+ * \tparam ModuleType Trajectory analysis module.
+ * \param argc \c argc passed to main().
+ * \param argv \c argv passed to main().
+ *
+ * This method abstracts away all the logic required to implement a
+ * main() method in user tools, allowing that to be changed without
+ * requiring changes to the tools themselves.
+ *
+ * \p ModuleType should be default-constructible and derive from
+ * TrajectoryAnalysisModule.
+ *
+ * Does not throw. All exceptions are caught and handled internally.
+ */
+ template <class ModuleType>
+ static int runAsMain(int argc, char *argv[])
+ {
+ return runAsMain(argc, argv, &createModule<ModuleType>);
+ }
+ /*! \brief
+ * Registers a command-line module that runs a given module.
+ *
+ * \tparam ModuleType Trajectory analysis module.
+ * \param manager Manager to register the module to.
+ * \param name Name of the module to register.
+ * \param description One-line description for the module to register.
+ *
+ * \p ModuleType should be default-constructible and derive from
+ * TrajectoryAnalysisModule.
+ *
+ * \p name and \p descriptions must be string constants or otherwise
+ * stay valid for the duration of the program execution.
+ */
+ template <class ModuleType>
+ static void registerModule(CommandLineModuleManager *manager,
+ const char *name, const char *description)
+ {
+ registerModule(manager, name, description, &createModule<ModuleType>);
+ }
+ /*! \brief
+ * Registers a command-line module that runs a given module.
+ *
+ * \tparam ModuleType Trajectory analysis module.
+ * \param manager Manager to register the module to.
+ * \param name Name of the module to register.
+ * \param description One-line description for the module to register.
+ * \param factory Function that creates the module on demand.
+ *
+ * \p name and \p descriptions must be string constants or otherwise
+ * stay valid for the duration of the program execution.
+ *
+ * Implements the template registerModule() method, but can also be
+ * used independently.
+ */
+ static void registerModule(CommandLineModuleManager *manager,
+ const char *name, const char *description,
+ ModuleFactoryMethod factory);
+
/*! \brief
* Create a new runner with the provided module.
*
~TrajectoryAnalysisCommandLineRunner();
/*! \brief
- * Sets whether the runner will print the copyright header.
+ * Sets whether default index groups are initialized.
*
- * \param[in] bPrint Whether to print the copyright header.
- *
- * By default, the copyright header is printed.
- * This is used internally when executing the runner in a context where
- * the copyright has already been printed at a higher level.
+ * This is intended only for internal unit testing purposes to avoid
+ * repeated, unnecessary initialization of the default groups, which
+ * can be expensive under, e.g., valgrind.
*
* Does not throw.
*/
- void setPrintCopyright(bool bPrint);
+ void setUseDefaultGroups(bool bUseDefaults);
/*! \brief
* Sets the default debugging level for selections.
*
+ * \param[in] debuglevel Level of debugging verbosity.
+ *
* This is intended only for use by internal debugging tools.
*
* Does not throw.
* \throws std::bad_alloc if out of memory.
* \throws FileIOError on any I/O error.
*/
- void writeHelp(const HelpWriterContext &context);
+ void writeHelp(const CommandLineHelpContext &context);
private:
+ /*! \brief
+ * Creates a trajectory analysis module of a given type.
+ *
+ * \tparam ModuleType Module to create.
+ */
+ template <class ModuleType>
+ static TrajectoryAnalysisModulePointer createModule()
+ {
+ return TrajectoryAnalysisModulePointer(new ModuleType());
+ }
+
+ //! Implements the template runAsMain() method.
+ static int runAsMain(int argc, char *argv[],
+ ModuleFactoryMethod factory);
+
class Impl;
PrivateImplPointer<Impl> impl_;