f2df6ddb09b1f753f775302c0145aab0065e8b8e
[alexxy/gromacs.git] / src / gromacs / options / options.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2010,2011,2012,2014,2015, 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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \file
36  * \brief
37  * Declares gmx::Options.
38  *
39  * Together with basicoptions.h, this header forms the part of the public
40  * API that most classes will use to provide options.
41  *
42  * \author Teemu Murtola <teemu.murtola@gmail.com>
43  * \inpublicapi
44  * \ingroup module_options
45  */
46 #ifndef GMX_OPTIONS_OPTIONS_H
47 #define GMX_OPTIONS_OPTIONS_H
48
49 #include <string>
50
51 #include "gromacs/options/ioptionscontainer.h"
52 #include "gromacs/utility/classhelpers.h"
53
54 namespace gmx
55 {
56
57 class AbstractOption;
58 class OptionsAssigner;
59 class OptionsIterator;
60
61 namespace internal
62 {
63 class OptionsImpl;
64 }
65
66
67 /*! \brief
68  * Collection of options.
69  *
70  * See \ref module_options for an overview of how the options work.
71  * The IOptionsContainer interface documents how to add options.
72  *
73  * In order to keep the public interface of this class simple, functionality
74  * to assign values to options is provided by a separate OptionsAssigner class.
75  * Similarly, functionality for looping over all options (e.g., for writing out
76  * help) is provided by OptionsIterator.
77  *
78  * \inpublicapi
79  * \ingroup module_options
80  */
81 class Options : public IOptionsContainer
82 {
83     public:
84         /*! \brief
85          * Initializes the name and title of an option collection.
86          *
87          * \param[in] name  Single-word name.
88          * \param[in] title Descriptive title.
89          *
90          * Copies the input strings.
91          */
92         Options(const char *name, const char *title);
93         ~Options();
94
95         //! Returns the short name of the option collection.
96         const std::string &name() const;
97
98
99         /*! \brief
100          * Adds an option collection as a subsection of this collection.
101          *
102          * \param[in] section Subsection to add.
103          *
104          * The name() field of \p section is used as the name of the
105          * subsection.  If an attempt is made to add two different subsections
106          * with the same name, this function asserts.
107          *
108          * \p section should not have any options added at the point this
109          * method is called.
110          *
111          * Only a pointer to the provided object is stored.  The caller is
112          * responsible that the object exists for the lifetime of the
113          * collection.
114          * It is not possible to add the same Options object as a subsection to
115          * several different Options.
116          * If an attempt is made, the function asserts.
117          */
118         void addSubSection(Options *section);
119
120         // From IOptionsContainer
121         virtual OptionInfo *addOption(const AbstractOption &settings);
122         using IOptionsContainer::addOption;
123         void addManager(IOptionManager *manager);
124         IOptionsContainer &addGroup();
125
126         /*! \brief
127          * Notifies the collection that all option values are assigned.
128          *
129          * \throws InvalidInputError if invalid user input is detected.
130          *
131          * This function should be called after no more option values are
132          * to be assigned.  Values in storage variables are guaranteed to be
133          * available only after this call, although in most cases, they are
134          * available already during assignment.
135          *
136          * If invalid option values, e.g., missing required option, is detected
137          * at this point, this function throws.  The thrown exception contains
138          * information on all errors detected during the call.
139          */
140         void finish();
141
142     private:
143         PrivateImplPointer<internal::OptionsImpl> impl_;
144
145         //! Needed for the implementation to access subsections.
146         friend class internal::OptionsImpl;
147         //! Needed to be able to extend the interface of this object.
148         friend class OptionsAssigner;
149         //! Needed to be able to extend the interface of this object.
150         friend class OptionsIterator;
151         //! Needed to be able to extend the interface of this object.
152         friend class OptionsModifyingIterator;
153 };
154
155 } // namespace gmx
156
157 #endif