SYCL: Avoid using no_init read accessor in rocFFT
[alexxy/gromacs.git] / src / gromacs / onlinehelp / helptopic.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2014,2015,2018,2019,2021, 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 helper classes for implementing gmx::IHelpTopic.
38  *
39  * \author Teemu Murtola <teemu.murtola@gmail.com>
40  * \inlibraryapi
41  * \ingroup module_onlinehelp
42  */
43 #ifndef GMX_ONLINEHELP_HELPTOPIC_H
44 #define GMX_ONLINEHELP_HELPTOPIC_H
45
46 #include <memory>
47
48 #include "gromacs/onlinehelp/ihelptopic.h"
49 #include "gromacs/utility/stringutil.h"
50
51 namespace gmx
52 {
53
54 /*! \libinternal \brief
55  * Abstract base class for help topics that have simple text and no subtopics.
56  *
57  * This class implements subtopic-related methods from IHelpTopic such
58  * that there are no subtopics.  writeHelp() is also implemented such that it
59  * uses HelpTopicContext::writeTextBlock() to write out the text returned by a
60  * new virtual method helpText().
61  *
62  * \see SimpleHelpTopic
63  *
64  * \inlibraryapi
65  * \ingroup module_onlinehelp
66  */
67 class AbstractSimpleHelpTopic : public IHelpTopic
68 {
69 public:
70     const char* name() const override  = 0;
71     const char* title() const override = 0;
72
73     bool              hasSubTopics() const override;
74     const IHelpTopic* findSubTopic(const char* name) const override;
75
76     void writeHelp(const HelpWriterContext& context) const override;
77
78 protected:
79     /*! \brief
80      * Returns the help text for this topic.
81      *
82      * writeHelp() calls this method to obtain the actual text to format
83      * for the topic.  Markup substitution etc. is done automatically by
84      * writeHelp().
85      */
86     virtual std::string helpText() const = 0;
87 };
88
89 /*! \libinternal \brief
90  * Abstract base class for help topics that have simple text and subtopics.
91  *
92  * This class implements an internal container for subtopics and provides
93  * public methods for adding subtopics (as IHelpTopic objects).
94  * Subtopic-related methods from IHelpTopic are implemented to access
95  * the internal container.  writeHelp() is also implemented such that it
96  * uses HelpTopicContext::writeTextBlock() to write out the text returned by a
97  * new virtual method helpText(), and a list of subtopics is written after the
98  * actual text.
99  *
100  * \see CompositeHelpTopic
101  *
102  * \inlibraryapi
103  * \ingroup module_onlinehelp
104  */
105 class AbstractCompositeHelpTopic : public IHelpTopic
106 {
107 public:
108     AbstractCompositeHelpTopic();
109     ~AbstractCompositeHelpTopic() override;
110
111     const char* name() const override  = 0;
112     const char* title() const override = 0;
113
114     bool              hasSubTopics() const override;
115     const IHelpTopic* findSubTopic(const char* name) const override;
116
117     void writeHelp(const HelpWriterContext& context) const override;
118
119     /*! \brief
120      * Adds a given topic as a subtopic of this topic.
121      *
122      * \param   topic  Topis to add.
123      * \throws  std::bad_alloc if out of memory.
124      *
125      * This topic takes ownership of the object.
126      *
127      * \see registerSubTopic()
128      */
129     void addSubTopic(HelpTopicPointer topic);
130     /*! \brief
131      * Registers a subtopic of a certain type to this topic.
132      *
133      * \tparam  Topic  Type of topic to register.
134      * \throws  std::bad_alloc if out of memory.
135      *
136      * \p Topic must be default-constructible and implement
137      * IHelpTopic.
138      *
139      * This method is provided as a convenient alternative to addSubTopic()
140      * for cases where each topic is implemented by a different type
141      * (which is a common case outside unit tests).
142      */
143     template<class Topic>
144     void registerSubTopic()
145     {
146         addSubTopic(HelpTopicPointer(new Topic));
147     }
148
149 protected:
150     //! \copydoc gmx::AbstractSimpleHelpTopic::helpText()
151     virtual std::string helpText() const = 0;
152
153     /*! \brief
154      * Writes the list of subtopics.
155      *
156      * \param[in] context Context for writing the help.
157      * \param[in] title  Title for the written list.
158      * \returns   true if anything was printed.
159      * \throws    std::bad_alloc if out of memory.
160      * \throws    FileIOError on any I/O error.
161      *
162      * Subtopics with empty titles are skipped from the list.
163      * If there would be no subtopics in the list, \p title is not printed
164      * either.
165      *
166      * This method is provided for cases where helpText() does not provide
167      * the needed flexibility and the derived class needs to override
168      * writeHelp().  This method can then be called to print the same
169      * subtopic list that is printed by the default writeHelp()
170      * implementation.
171      */
172     bool writeSubTopicList(const HelpWriterContext& context, const std::string& title) const;
173
174 private:
175     class Impl;
176
177     std::unique_ptr<Impl> impl_;
178 };
179
180 /*! \cond libapi */
181 /*! \libinternal \brief
182  * Smart pointer type to manage a AbstractCompositeHelpTopic object.
183  *
184  * \inlibraryapi
185  */
186 typedef std::unique_ptr<AbstractCompositeHelpTopic> CompositeHelpTopicPointer;
187 //! \endcond
188
189 /*! \libinternal \brief
190  * Template for simple implementation of AbstractSimpleHelpTopic.
191  *
192  * \tparam HelpText Struct that defines the data for the topic.
193  *
194  * \p HelpText should have public static members \c "const char name[]",
195  * \c "const char title[]" and \c "const char *const text[]".
196  *
197  * Typical use:
198  * \code
199    struct ExampleHelpText
200    {
201        static const char name[];
202        static const char title[];
203        static const char *const text[];
204    };
205
206    const char ExampleHelpText::name[] = "example";
207    const char ExampleHelpText::title[] =
208        "Example title";
209    const char *const ExampleHelpText::text[] = {
210        "Text for the topic.",
211        "More text for the topic."
212    };
213
214    typedef SimpleHelpTopic<ExampleHelpText> ExampleHelpTopic;
215  * \endcode
216  *
217  * \inlibraryapi
218  * \ingroup module_onlinehelp
219  */
220 template<class HelpText>
221 class SimpleHelpTopic : public AbstractSimpleHelpTopic
222 {
223 public:
224     const char* name() const override { return HelpText::name; }
225     const char* title() const override { return HelpText::title; }
226
227 protected:
228     std::string helpText() const override { return joinStrings(HelpText::text, "\n"); }
229 };
230
231 /*! \libinternal \brief
232  * Template for simple implementation of AbstractCompositeHelpTopic.
233  *
234  * \tparam HelpText Struct that defines the data for the topic.
235  *
236  * Used similarly to SimpleHelpTopic.
237  * \p HelpText should satisfy the same criteria as for SimpleHelpTopic.
238  *
239  * \see SimpleHelpTopic
240  *
241  * \inlibraryapi
242  * \ingroup module_onlinehelp
243  */
244 template<class HelpText>
245 class CompositeHelpTopic : public AbstractCompositeHelpTopic
246 {
247 public:
248     // copydocs are needed with Doxygen 1.8.10, but not 1.8.5...
249     //! \copydoc gmx::AbstractCompositeHelpTopic::name()
250     const char* name() const override { return HelpText::name; }
251     //! \copydoc gmx::AbstractCompositeHelpTopic::title()
252     const char* title() const override { return HelpText::title; }
253
254 protected:
255     //! \copydoc gmx::AbstractCompositeHelpTopic::helpText()
256     std::string helpText() const override { return joinStrings(HelpText::text, "\n"); }
257 };
258
259 } // namespace gmx
260
261 #endif