This patch moves the nrama.[ch] to the gmxana dir.
[gromacs/AngularHB.git] / src / testutils / cmdlinetest.h
blob97548b3ba3e05831440c5235b509a9c4f1c90f7b
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, 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 #include "gromacs/utility/common.h"
50 namespace gmx
52 namespace test
55 /*! \libinternal \brief
56 * Helper class for tests that check command-line handling.
58 * This class helps in writing tests for command-line handling.
59 * The create() method takes an array of const char pointers, specifying the
60 * command-line arguments, each as one array element.
61 * The argc() and argv() methods can then be used to obtain the argc and argv
62 * (non-const char pointers) arrays for passing into methods that expect these.
64 * Note that although the interface allows passing the argc and argv pointers
65 * to methods that modify them (typically as \p f(&argc(), argv())), currently
66 * the CommandLine object is not in a consistent state internally if the
67 * parameters are actually modified. Reading the command line is possible
68 * afterwards, but modification is not.
70 * All constructors and methods that modify this class may throw an
71 * std::bad_alloc. Const methods and accessors do not throw.
73 * \inlibraryapi
74 * \ingroup module_testutils
76 class CommandLine
78 public:
79 /*! \brief
80 * Initializes a command-line object from a const C array.
82 * \param[in] cmdline Array of command-line arguments.
83 * \tparam count Deduced number of elements in \p cmdline.
85 * \p cmdline should include the binary name as the first element if
86 * that is desired in the output.
88 * This is not a constructor, because template constructors are not
89 * possible with a private implementation class.
91 template <size_t count> static
92 CommandLine create(const char *const (&cmdline)[count])
94 return CommandLine(cmdline, count);
97 //! Initializes an empty command-line object.
98 CommandLine();
99 /*! \brief
100 * Initializes a command-line object.
102 * \param[in] cmdline Array of command-line arguments.
103 * \param[in] count Number of elements in \p cmdline.
105 * \p cmdline should include the binary name as the first element if
106 * that is desired in the output.
108 CommandLine(const char *const cmdline[], size_t count);
109 //! Creates a deep copy of a command-line object.
110 CommandLine(const CommandLine &other);
111 ~CommandLine();
113 /*! \brief
114 * Append an argument to the command line.
116 * \param[in] arg Argument to append.
118 * Strong exception safety.
120 void append(const char *arg);
121 //! Convenience overload taking a std::string.
122 void append(const std::string &arg) { append(arg.c_str()); }
123 /*! \brief
124 * Add an option-value pair to the command line.
126 * \param[in] name Name of the option to append, which
127 * should start with "-".
128 * \param[in] value Value of the argument to append.
130 void addOption(const char *name, const char *value);
131 //! Convenience overload taking a std::string.
132 void addOption(const char *name, const std::string &value);
133 //! Overload taking an int.
134 void addOption(const char *name, int value);
135 //! Overload taking a double.
136 void addOption(const char *name, double value);
137 //! Returns argc for passing into C-style command-line handling.
138 int &argc();
139 //! Returns argv for passing into C-style command-line handling.
140 char **argv();
141 //! Returns argc for passing into C-style command-line handling.
142 int argc() const;
143 //! Returns argv for passing into C-style command-line handling.
144 const char *const *argv() const;
145 //! Returns a single argument.
146 const char *arg(int i) const;
148 //! Returns the command line formatted as a single string.
149 std::string toString() const;
151 private:
152 class Impl;
154 PrivateImplPointer<Impl> impl_;
157 } // namespace test
158 } // namespace gmx
160 #endif