Merge branch release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / commandline / cmdlinehelpcontext.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2013, by the GROMACS development team, led by
5  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6  * others, as listed in the AUTHORS file in the top-level source
7  * 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 /*! \libinternal \file
36  * \brief
37  * Declares gmx::CommandLineHelpContext.
38  *
39  * \author Teemu Murtola <teemu.murtola@gmail.com>
40  * \inlibraryapi
41  * \ingroup module_commandline
42  */
43 #ifndef GMX_COMMANDLINE_CMDLINEHELPCONTEXT_H
44 #define GMX_COMMANDLINE_CMDLINEHELPCONTEXT_H
45
46 #include "../onlinehelp/helpwritercontext.h"
47 #include "../utility/common.h"
48
49 namespace gmx
50 {
51
52 /*! \libinternal \brief
53  * Context information for writing out command-line help.
54  *
55  * This class wraps a HelpWriterContext, extending it with information specific
56  * for command-line help export.  This way, code using only the routines in the
57  * onlinehelp module is not exposed to extra features of the command-line help
58  * export.
59  *
60  * \ingroup module_commandline
61  */
62 class CommandLineHelpContext
63 {
64     public:
65         /*! \brief
66          * Creates the context.
67          *
68          * Wraps the constructor of HelpWriterContext.
69          */
70         CommandLineHelpContext(File *file, HelpOutputFormat format);
71         ~CommandLineHelpContext();
72
73         /*! \brief
74          * Sets a display name for the module for which help is being written.
75          *
76          * \throws std::bad_alloc if out of memory.
77          */
78         void setModuleDisplayName(const std::string &name);
79         //! Sets whether hidden options should be shown in help output.
80         void setShowHidden(bool bHidden);
81
82         //! Returns the lower-level context for writing the help.
83         const HelpWriterContext &writerContext() const;
84         /*! \brief
85          * Returns a display name for the module for which help is being written.
86          *
87          * Does not throw.
88          */
89         const char *moduleDisplayName() const;
90         //! Returns whether hidden options should be shown in help output.
91         bool showHidden() const;
92
93     private:
94         class Impl;
95
96         PrivateImplPointer<Impl> impl_;
97 };
98
99 /*! \libinternal \brief
100  * Helper for passing CommandLineHelpContext into parse_common_args().
101  *
102  * This class provides a mechanism to set and retrieve a global
103  * CommandLineHelpContext object.  It is used to pass this object into
104  * parse_common_args() from CommandLineModuleManager::runAsMainCMain() through
105  * the main() function that is not aware of the wrapper binary mechanism.
106  * It is not thread-safe because in this limited use case, it is always called
107  * from a single-threaded context.
108  *
109  * \inlibraryapi
110  * \ingroup module_onlinehelp
111  */
112 class GlobalCommandLineHelpContext
113 {
114     public:
115         //! Returns the global context, or NULL if not set.
116         static const CommandLineHelpContext *get();
117
118         /*! \brief
119          * Sets the global context for the scope.
120          *
121          * The global context is cleared when this object goes out of scope.
122          *
123          * It is an error to have more than one GlobalCommandLineHelpContext
124          * object in existence at the same time.
125          */
126         explicit GlobalCommandLineHelpContext(const CommandLineHelpContext &context);
127         //! Clears the global context.
128         ~GlobalCommandLineHelpContext();
129 };
130
131 } // namespace gmx
132
133 #endif