GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
comment-list.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2000-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_comment_list_h)
27#define octave_comment_list_h 1
28
29#include "octave-config.h"
30
31#include <list>
32#include <memory>
33#include <string>
34
36
37extern std::string get_comment_text ();
38
39extern char * get_comment_text_c_str ();
40
41extern void save_comment_text (const std::string& text);
42
44{
45public:
46
55
56 comment_elt (const std::string& s = "", comment_type t = unknown, bool uses_hash_char = false)
57 : m_text (s), m_type (t), m_uses_hash_char (uses_hash_char) { }
58
60 : m_text (oc.m_text), m_type (oc.m_type), m_uses_hash_char (oc.m_uses_hash_char)
61 { }
62
63 comment_elt& operator = (const comment_elt& oc)
64 {
65 if (this != &oc)
66 {
67 m_text = oc.m_text;
68 m_type = oc.m_type;
69 m_uses_hash_char = oc.m_uses_hash_char;
70 }
71
72 return *this;
73 }
74
75 bool empty () const { return m_text.empty (); }
76
77 std::string text () const { return m_text; }
78
79 comment_type type () const { return m_type; }
80
81 bool is_block () const { return m_type == block; }
82 bool is_full_line () const { return m_type == full_line; }
83 bool is_end_of_line () const { return m_type == end_of_line; }
84 bool is_copyright () const { return m_type == copyright; }
85 bool uses_hash_char () const { return m_uses_hash_char; }
86
87 void reset ()
88 {
89 m_text = "";
90 m_type = unknown;
91 m_uses_hash_char = false;
92 }
93
94 ~comment_elt () = default;
95
96private:
97
98 // The text of the comment.
99 std::string m_text;
100
101 // The type of comment.
102 comment_type m_type;
103
104 // TRUE means a line comment uses '#' or a block comment used at least
105 // one '#' delimiter.
106 bool m_uses_hash_char;
107};
108
110{
111public:
112
113 OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (comment_list)
114
115 typedef std::list<comment_elt>::reference reference;
117
118 typedef std::list<comment_elt>::iterator iterator;
120
121 void append (const comment_elt& elt)
122 {
123 m_list.push_back (elt);
124 }
125
126 void append (const std::string& s,
128 bool uses_hash_char = false)
129 {
130 m_list.push_back (comment_elt (s, t, uses_hash_char));
131 }
132
133 void clear () { m_list.clear (); }
134
135 bool empty () const { return m_list.empty (); }
136
137 reference front () { return m_list.front (); }
138 reference back () { return m_list.back (); }
139
140 const_reference front () const { return m_list.front (); }
141 const_reference back () const { return m_list.back (); }
142
143 iterator begin () { return m_list.begin (); }
144 iterator end () { return m_list.end (); }
145
146 const_iterator begin () const { return m_list.begin (); }
147 const_iterator end () const { return m_list.end (); }
148
149 comment_list * dup () const;
150
151 // Documentation for functions is typically the first block of
152 // comments that doesn't look like a copyright statement.
154 {
155 for (const auto& elt : m_list)
156 {
157 // FIXME: should we also omit end-of-line comments?
158 if (! elt.is_copyright ())
159 return elt;
160 }
161
162 return comment_elt ();
163 }
164
165 std::string find_doc_string () const
166 {
167 return find_doc_comment().text ();
168 }
169
170private:
171
172 std::list<comment_elt> m_list;
173};
174
175OCTAVE_END_NAMESPACE(octave)
176
177#endif
comment_elt(const comment_elt &oc)
bool is_end_of_line() const
comment_type type() const
bool is_full_line() const
std::string text() const
bool empty() const
bool uses_hash_char() const
comment_elt(const std::string &s="", comment_type t=unknown, bool uses_hash_char=false)
~comment_elt()=default
bool is_block() const
bool is_copyright() const
iterator end()
void append(const std::string &s, comment_elt::comment_type t=comment_elt::unknown, bool uses_hash_char=false)
void append(const comment_elt &elt)
std::list< comment_elt >::const_reference const_reference
const_iterator end() const
const_reference front() const
const_reference back() const
const_iterator begin() const
comment_list * dup() const
reference front()
std::list< comment_elt >::reference reference
reference back()
comment_elt find_doc_comment() const
std::string find_doc_string() const
iterator begin()
std::list< comment_elt >::iterator iterator
std::list< comment_elt >::const_iterator const_iterator
bool empty() const
char * get_comment_text_c_str()
void save_comment_text(const std::string &text)
std::string get_comment_text()
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn