3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
33 * Declares gmx::CommandLineModuleManager.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
37 * \ingroup module_commandline
39 #ifndef GMX_COMMANDLINE_CMDLINEMODULEMANAGER_H
40 #define GMX_COMMANDLINE_CMDLINEMODULEMANAGER_H
42 #include "../utility/common.h"
43 #include "../utility/uniqueptr.h"
48 class CommandLineModuleInterface;
50 //! Smart pointer type for managing a CommandLineModuleInterface.
51 typedef gmx_unique_ptr<CommandLineModuleInterface>::type
52 CommandLineModulePointer;
56 class CommandLineHelpModule;
60 * Implements a wrapper command-line interface for multiple modules.
65 main(int argc, char *argv[])
67 CopyRight(stderr, argv[0]);
70 gmx::CommandLineModuleManager manager;
71 // <register all necessary modules>
72 return manager.run(argc, argv);
74 catch (const std::exception &ex)
76 fprintf(stderr, "%s", gmx::formatErrorMessage(ex).c_str());
83 * \ingroup module_commandline
85 class CommandLineModuleManager
88 CommandLineModuleManager();
89 ~CommandLineModuleManager();
92 * Adds a given module to this manager.
94 * \param module Module to add.
95 * \throws std::bad_alloc if out of memory.
97 * The manager takes ownership of the object.
99 * This method is public mostly for testing purposes; for typical uses,
100 * registerModule() is a more convenient way of adding modules.
102 * \see registerModule()
104 void addModule(CommandLineModulePointer module);
106 * Registers a module of a certain type to this manager.
108 * \tparam Module Type of module to register.
109 * \throws std::bad_alloc if out of memory.
111 * \p Module must be default-constructible and implement
112 * CommandLineModuleInterface.
114 * This method is provided as a convenient alternative to addModule()
115 * for cases where each module is implemented by a different type
116 * (which should be the case for typical situations outside unit
119 template <class Module>
120 void registerModule()
122 addModule(CommandLineModulePointer(new Module));
126 * Runs a module based on given command line.
128 * \param[in] argc Number of elements in \p argv.
129 * \param[in] argv Command-line arguments.
130 * \throws unspecified Throws any exception that the selected module
132 * \returns Exit code for the program.
133 * \retval 0 on successful termination.
134 * \retval 2 if no module is specified, or if the module is not found.
136 * Runs the module whose name matches \p argv[1].
138 int run(int argc, char *argv[]);
143 PrivateImplPointer<Impl> impl_;
146 * Needed to access information about registered modules etc.
148 friend class internal::CommandLineHelpModule;