Sort all includes in src/gromacs
[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,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.
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 "gromacs/onlinehelp/helpwritercontext.h"
47 #include "gromacs/utility/common.h"
48
49 namespace gmx
50 {
51
52 class ShellCompletionWriter;
53
54 /*! \libinternal \brief
55  * Context information for writing out command-line help.
56  *
57  * This class wraps a HelpWriterContext, extending it with information specific
58  * for command-line help export.  This way, code using only the routines in the
59  * onlinehelp module is not exposed to extra features of the command-line help
60  * export.
61  *
62  * Copying a context works like with HelpWriterContext: the output file and
63  * most state is shared.  However, setModuleDisplayName() and setShowHidden()
64  * can be set independently for the child context.  Defaults for these options
65  * are inherited from the parent.
66  *
67  * \ingroup module_commandline
68  */
69 class CommandLineHelpContext
70 {
71     public:
72         /*! \brief
73          * Creates a context for help export.
74          *
75          * Wraps the constructor of HelpWriterContext.
76          */
77         CommandLineHelpContext(File *file, HelpOutputFormat format,
78                                const HelpLinks *links);
79         //! Creates a context for a particular HelpWriterContext.
80         explicit CommandLineHelpContext(const HelpWriterContext &writerContext);
81         /*! \brief
82          * Creates a context for shell completion.
83          */
84         explicit CommandLineHelpContext(ShellCompletionWriter *writer);
85         //! Creates a copy of the context.
86         explicit CommandLineHelpContext(const CommandLineHelpContext &other);
87         ~CommandLineHelpContext();
88
89         /*! \brief
90          * Sets a display name for the module for which help is being written.
91          *
92          * \throws std::bad_alloc if out of memory.
93          */
94         void setModuleDisplayName(const std::string &name);
95         //! Sets whether hidden options should be shown in help output.
96         void setShowHidden(bool bHidden);
97
98         //! Returns the lower-level context for writing the help.
99         const HelpWriterContext &writerContext() const;
100         /*! \brief
101          * Returns a display name for the module for which help is being written.
102          *
103          * Does not throw.
104          */
105         const char *moduleDisplayName() const;
106         //! Returns whether hidden options should be shown in help output.
107         bool showHidden() const;
108         //! Returns whether this context is for exporting shell completions.
109         bool isCompletionExport() const;
110         /*! \brief
111          * Returns the shell completion writer for this context.
112          *
113          * Can only be called if isCompletionExport() returns `true`.
114          */
115         ShellCompletionWriter &shellCompletionWriter() const;
116
117     private:
118         class Impl;
119
120         PrivateImplPointer<Impl> impl_;
121
122         GMX_DISALLOW_ASSIGN(CommandLineHelpContext);
123 };
124
125 /*! \libinternal \brief
126  * Helper for passing CommandLineHelpContext into parse_common_args().
127  *
128  * This class provides a mechanism to set and retrieve a global
129  * CommandLineHelpContext object.  It is used to pass this object into
130  * parse_common_args() from CommandLineModuleManager::runAsMainCMain() through
131  * the main() function that is not aware of the wrapper binary mechanism.
132  * It is not thread-safe because in this limited use case, it is always called
133  * from a single-threaded context.
134  *
135  * \inlibraryapi
136  * \ingroup module_onlinehelp
137  */
138 class GlobalCommandLineHelpContext
139 {
140     public:
141         //! Returns the global context, or NULL if not set.
142         static const CommandLineHelpContext *get();
143
144         /*! \brief
145          * Sets the global context for the scope.
146          *
147          * The global context is cleared when this object goes out of scope.
148          *
149          * It is an error to have more than one GlobalCommandLineHelpContext
150          * object in existence at the same time.
151          */
152         explicit GlobalCommandLineHelpContext(const CommandLineHelpContext &context);
153         //! Clears the global context.
154         ~GlobalCommandLineHelpContext();
155 };
156
157 } // namespace gmx
158
159 #endif