Introduce SimulatorBuilder
[gromacs.git] / src / gromacs / onlinehelp / rstparser.h
blob3bf1b3c734c9878e25054a5d055ac6edcccd1127
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2015,2018, 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 /*! \internal \file
36 * \brief
37 * Declares classes for (partial) parsing of reStructuredText.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_onlinehelp
42 #ifndef GMX_ONLINEHELP_RSTPARSER_H
43 #define GMX_ONLINEHELP_RSTPARSER_H
45 #include <string>
47 #include "gromacs/utility/classhelpers.h"
49 namespace gmx
52 class TextLineWrapperSettings;
54 /*! \internal
55 * \brief
56 * Iterator over reStructuredText paragraphs.
58 * After initialization, nextParagraph() needs to be called to access the first
59 * paragraph. Subsequence paragraphs can be accessed by repeated calls to
60 * nextParagraph(). After the last paragraph, nextParagraph() returns `false`.
62 * After each call to nextParagraph(), other methods can be called to query
63 * details of the current paragraph.
65 * \ingroup module_onlinehelp
67 class RstParagraphIterator
69 public:
70 /*! \brief
71 * Initializes an iterator for given input text.
73 * Does not throw.
75 explicit RstParagraphIterator(const std::string &text);
77 /*! \brief
78 * Advances the iterator to the next paragraph.
80 * \returns `false` if there were no more paragraphs.
82 * Does not throw (except std::bad_alloc if std::string::compare()
83 * throws).
85 bool nextParagraph();
87 //! Returns the indentation for first line of this paragraph.
88 int firstLineIndent() const { return firstLineIndent_; }
89 //! Returns the indentation for subsequent lines of this paragraph.
90 int indent() const { return indent_; }
91 /*! \brief
92 * Returns the text
94 * \param[out] result Variable to receive the paragraph text.
95 * \throws std::bad_alloc if out of memory.
97 * Indentation and internal line breaks have been stripped from the
98 * paragraph text (except for literal blocks etc.). For literal
99 * blocks, the common indentation has been stripped and is returned in
100 * indent() instead.
102 * Leading newlines are returned to indicate necessary separation from
103 * the preceding paragraph.
105 void getParagraphText(std::string *result) const;
107 private:
108 enum ParagraphType
110 eParagraphType_Normal,
111 eParagraphType_Literal,
112 eParagraphType_Title
115 //! The text to iterate over.
116 const std::string &text_; //NOLINT(google-runtime-member-string-references)
118 //! Start of the current paragraph.
119 size_t begin_;
120 //! End of the current paragraph (C++-style iterator).
121 size_t end_;
122 //! Type of the current paragraph.
123 ParagraphType type_;
124 //! Number of newlines to print before the current paragraph.
125 int breakSize_;
126 //! Indentation of the first line of this paragraph.
127 int firstLineIndent_;
128 //! (Minimum) indentation of other lines in this paragraph.
129 int indent_;
131 //! Start of the next paragrah.
132 size_t nextBegin_;
133 //! Number of newlines to print after the current paragraph.
134 int nextBreakSize_;
135 /*! \brief
136 * Indentation of the preceding paragraph that contained `::`.
138 * If the next paragraph is not a literal block, the value is `-1`.
140 int literalIndent_;
142 GMX_DISALLOW_COPY_AND_ASSIGN(RstParagraphIterator);
145 } // namespace gmx
147 #endif