Removed simple.h from nb_kernel_sse4_1_XX
[gromacs.git] / src / gromacs / onlinehelp / helpwritercontext.h
blob95cac6d739a1d347ce540bad92b459c2c97b6faf
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,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.
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::HelpWriterContext.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \inlibraryapi
41 * \ingroup module_onlinehelp
43 #ifndef GMX_ONLINEHELP_HELPWRITERCONTEXT_H
44 #define GMX_ONLINEHELP_HELPWRITERCONTEXT_H
46 #include <string>
47 #include <vector>
49 #include "gromacs/utility/classhelpers.h"
51 namespace gmx
54 class TextLineWrapperSettings;
55 class TextOutputStream;
56 class TextWriter;
58 /*! \cond libapi */
59 //! \libinternal Output format for help writing.
60 enum HelpOutputFormat
62 eHelpOutputFormat_Console, //!< Plain text directly on the console.
63 eHelpOutputFormat_Rst, //!< reStructuredText for online manual and man pages.
64 eHelpOutputFormat_Other, //!< Used for extensions in other modules.
65 eHelpOutputFormat_NR //!< Used for the number of output formats.
67 //! \endcond
69 /*! \libinternal \brief
70 * Hyperlink data for writing out help.
72 * This class is separate from HelpWriterContext to allow constructing the list
73 * of links once and reusing them across multiple help writer contexts.
74 * This is used when exporting all the help from the wrapper binary to avoid
75 * repeatedly constructing the same data structure for each help item.
77 * While the links are in principle independent of the output format, the
78 * constructor takes the output format to be able to preformat the links,
79 * avoiding repeated processing during markup substitution. Could be hidden
80 * behind the scenes in HelpWriterContext, but that would complicate the
81 * implementation.
83 * \ingroup module_onlinehelp
85 class HelpLinks
87 public:
88 /*! \brief
89 * Initializes an empty links collection for the given output format.
91 explicit HelpLinks(HelpOutputFormat format);
92 ~HelpLinks();
94 /*! \brief
95 * Adds a link.
97 * \param[in] linkName Name of the link in input text.
98 * \param[in] targetName Hyperlink target.
99 * \param[in] displayName Text to show as the link.
101 * Any occurrence of \p linkName in the text passed to markup
102 * substitution methods in HelpWriterContext is made into a hyperlink
103 * to \p targetName if the markup format supports that.
105 void addLink(const std::string &linkName,
106 const std::string &targetName,
107 const std::string &displayName);
109 private:
110 class Impl;
112 PrivateImplPointer<Impl> impl_;
114 //! Allows the context to use the links.
115 friend class HelpWriterContext;
118 /*! \libinternal \brief
119 * Context information for writing out help.
121 * The purpose of this class is to pass information about the output format to
122 * methods that write help, and to abstract away most of the details of
123 * different output formats.
125 * The state of a context object (excluding the fact that the output file is
126 * written to) does not change after initial construction of the object.
127 * Copying creates a context objects that share state with the source.
129 * \inlibraryapi
130 * \ingroup module_onlinehelp
132 class HelpWriterContext
134 public:
135 /*! \brief
136 * Initializes a context with the given output stream and format.
138 * \throws std::bad_alloc if out of memory.
140 HelpWriterContext(TextOutputStream *stream, HelpOutputFormat format);
141 /*! \brief
142 * Initializes a context with the given output stream, format and links.
144 * \throws std::bad_alloc if out of memory.
146 * A reference to \p links is stored until the HelpWriterContext
147 * is destructed. The caller is responsible for ensuring that the
148 * links object remains valid long enough.
150 HelpWriterContext(TextOutputStream *stream, HelpOutputFormat format,
151 const HelpLinks *links);
152 //! Creates a copy of the context.
153 HelpWriterContext(const HelpWriterContext &other);
154 ~HelpWriterContext();
156 /*! \brief
157 * Adds a string replacement for markup subsitution.
159 * \param[in] search Text to replace in input.
160 * \param[in] replace Text that each occurrence of \p search is
161 * replaced with.
162 * \throws std::bad_alloc if out of memory.
164 * \todo
165 * Improve semantics if the same \p search item is set multiple
166 * times.
168 void setReplacement(const std::string &search,
169 const std::string &replace);
171 /*! \brief
172 * Returns the active output format.
174 * Does not throw.
176 HelpOutputFormat outputFormat() const;
177 /*! \brief
178 * Returns the raw writer for writing the help.
180 * Using this writer directly should be avoided, as it requires one to
181 * have different code for each output format.
182 * Using other methods in this class should be preferred.
184 * Does not throw.
186 TextWriter &outputFile() const;
188 /*! \brief
189 * Creates a subsection in the output help.
191 * \param[in] title Title for the subsection.
192 * \throws std::bad_alloc if out of memory.
193 * \throws FileIOError on any I/O error.
195 * Writes \p title using writeTitle() and makes any further
196 * writeTitle() calls write headings one level deeper.
198 * Typical use for writing a subsection is to create a copy of the
199 * context for the parent section, and then call enterSubSection() on
200 * the copy.
201 * The whole subsection should be written out using the returned
202 * context before calling any further methods in the parent context.
204 * This method is only necessary if the subsection will contain further
205 * subsections. If there is only one level of subsections, it is
206 * possible to use writeTitle() directly.
208 void enterSubSection(const std::string &title);
210 /*! \brief
211 * Substitutes markup used in help text and wraps lines.
213 * \param[in] settings Line wrapper settings.
214 * \param[in] text Text to substitute.
215 * \returns \p text with markup substituted and wrapped.
216 * \throws std::bad_alloc if out of memory.
218 * \see TextLineWrapper::wrapToString()
220 std::string
221 substituteMarkupAndWrapToString(const TextLineWrapperSettings &settings,
222 const std::string &text) const;
223 /*! \brief
224 * Substitutes markup used in help text and wraps lines.
226 * \param[in] settings Line wrapper settings.
227 * \param[in] text Text to substitute.
228 * \returns \p text with markup substituted and wrapped as a list of
229 * lines.
230 * \throws std::bad_alloc if out of memory.
232 * \see TextLineWrapper::wrapToVector()
234 std::vector<std::string>
235 substituteMarkupAndWrapToVector(const TextLineWrapperSettings &settings,
236 const std::string &text) const;
237 /*! \brief
238 * Writes a title for the current help topic.
240 * \param[in] title Title to write.
241 * \throws std::bad_alloc if out of memory.
242 * \throws FileIOError on any I/O error.
244 void writeTitle(const std::string &title) const;
245 /*! \brief
246 * Writes a formatted text block into the output.
248 * \param[in] text Text to format.
249 * \throws std::bad_alloc if out of memory.
250 * \throws FileIOError on any I/O error.
252 * Convenience function that calls substituteMarkupAndWrapToString()
253 * and writes the result directly to the output file.
255 void writeTextBlock(const std::string &text) const;
256 /*! \brief
257 * Starts writing a list of options.
259 * Prints any necessary headers for a list of options formatted with
260 * writeOptionItem().
262 void writeOptionListStart() const;
263 /*! \brief
264 * Writes an entry for a single option into the output.
266 * \param[in] name Name of the option.
267 * \param[in] value Placeholder for option value.
268 * \param[in] defaultValue Default value for the option.
269 * \param[in] info Additional (brief) info/attributes for the
270 * option.
271 * \param[in] description Full description of the option.
273 void writeOptionItem(
274 const std::string &name, const std::string &value,
275 const std::string &defaultValue, const std::string &info,
276 const std::string &description) const;
277 /*! \brief
278 * Finishes writing a list of options.
280 * Prints any necessary footers for a list of options formatted with
281 * writeOptionItem().
283 void writeOptionListEnd() const;
285 private:
286 class Impl;
288 /*! \brief
289 * Constructs a context object with the given implementation class.
291 * \param[in] impl Implementation object.
293 * Does not throw.
295 explicit HelpWriterContext(Impl *impl);
297 PrivateImplPointer<Impl> impl_;
299 GMX_DISALLOW_ASSIGN(HelpWriterContext);
302 } // namespace gmx
304 #endif