Don't use PME ranks with GPUs and -npme=-1
[gromacs/AngularHB.git] / src / testutils / cmdlinetest.h
blobd29e75be5bdad4a3ae112aa056136b76a21b5d2b
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \libinternal \file
36 * \brief
37 * Declares gmx::test::CommandLine.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \inlibraryapi
41 * \ingroup module_testutils
43 #ifndef GMX_TESTUTILS_CMDLINETEST_H
44 #define GMX_TESTUTILS_CMDLINETEST_H
46 #include <string>
48 // arrayref.h is not strictly necessary for this header, but nearly all
49 // callers will need it to use the constructor that takes ConstArrayRef.
50 #include "gromacs/utility/arrayref.h"
51 #include "gromacs/utility/common.h"
53 namespace gmx
55 namespace test
58 /*! \libinternal \brief
59 * Helper class for tests that check command-line handling.
61 * This class helps in writing tests for command-line handling.
62 * The constructor method takes an array of const char pointers, specifying the
63 * command-line arguments, each as one array element. It is also possible to
64 * construct the command line by adding individual arguments with append() and
65 * addOption().
66 * The argc() and argv() methods can then be used to obtain `argc` and `argv`
67 * (non-const char pointers) arrays for passing into methods that expect these.
69 * Note that although the interface allows passing the argc and argv pointers
70 * to methods that modify them (typically as \p f(&argc(), argv())), currently
71 * the CommandLine object is not in a consistent state internally if the
72 * parameters are actually modified. Reading the command line is possible
73 * afterwards, but modification is not.
75 * All constructors and methods that modify this class may throw an
76 * std::bad_alloc. Const methods and accessors do not throw.
78 * \inlibraryapi
79 * \ingroup module_testutils
81 class CommandLine
83 public:
84 //! Initializes an empty command-line object.
85 CommandLine();
86 /*! \brief
87 * Initializes a command-line object from an array.
89 * \param[in] cmdline Array of command-line arguments.
91 * \p cmdline should include the binary name as the first element if
92 * that is desired in the output.
94 * This constructor is not explicit to make it possible to create a
95 * CommandLine object directly from a C array.
97 CommandLine(const ConstArrayRef<const char *> &cmdline);
98 //! Creates a deep copy of a command-line object.
99 CommandLine(const CommandLine &other);
100 ~CommandLine();
102 /*! \brief
103 * Initializes a command-line object in-place from an array.
105 * \param[in] cmdline Array of command-line arguments.
107 * \p cmdline should include the binary name as the first element if
108 * that is desired in the output.
110 * This function does the same as the constructor that takes a
111 * ConstArrayRef. Any earlier contents of the object are discarded.
113 * Strong exception safety.
115 void initFromArray(const ConstArrayRef<const char *> &cmdline);
117 /*! \brief
118 * Append an argument to the command line.
120 * \param[in] arg Argument to append.
122 * Strong exception safety.
124 void append(const char *arg);
125 //! Convenience overload taking a std::string.
126 void append(const std::string &arg) { append(arg.c_str()); }
127 /*! \brief
128 * Add an option-value pair to the command line.
130 * \param[in] name Name of the option to append, which
131 * should start with "-".
132 * \param[in] value Value of the argument to append.
134 void addOption(const char *name, const char *value);
135 //! Convenience overload taking a std::string.
136 void addOption(const char *name, const std::string &value);
137 //! Overload taking an int.
138 void addOption(const char *name, int value);
139 //! Overload taking a double.
140 void addOption(const char *name, double value);
141 //! Returns argc for passing into C-style command-line handling.
142 int &argc();
143 //! Returns argv for passing into C-style command-line handling.
144 char **argv();
145 //! Returns argc for passing into C-style command-line handling.
146 int argc() const;
147 //! Returns argv for passing into C-style command-line handling.
148 const char *const *argv() const;
149 //! Returns a single argument.
150 const char *arg(int i) const;
152 //! Returns the command line formatted as a single string.
153 std::string toString() const;
155 private:
156 class Impl;
158 PrivateImplPointer<Impl> impl_;
161 } // namespace test
162 } // namespace gmx
164 #endif