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
35
OCTAVE_BEGIN_NAMESPACE
(octave)
36
37
extern std::
string
get_comment_text
();
38
39
extern
char
*
get_comment_text_c_str
();
40
41
extern
void
save_comment_text
(const std::
string
& text);
42
43
class
comment_elt
44
{
45
public
:
46
47
enum
comment_type
48
{
49
unknown
,
50
block
,
51
full_line
,
52
end_of_line
,
53
copyright
54
};
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
59
comment_elt
(
const
comment_elt
& oc)
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
96
private
:
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
109
class
comment_list
110
{
111
public
:
112
113
OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (
comment_list
)
114
115
typedef std::list<
comment_elt
>::
reference
reference
;
116
typedef std::list<
comment_elt
>::
const_reference
const_reference
;
117
118
typedef std::list<
comment_elt
>::
iterator
iterator
;
119
typedef std::list<
comment_elt
>::
const_iterator
const_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,
127
comment_elt::comment_type
t =
comment_elt::unknown
,
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.
153
comment_elt
find_doc_comment
()
const
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
170
private
:
171
172
std::list<comment_elt> m_list;
173
};
174
175
OCTAVE_END_NAMESPACE(octave)
176
177
#endif
comment_elt
Definition
comment-list.h:44
comment_elt::reset
void reset()
Definition
comment-list.h:87
comment_elt::comment_elt
comment_elt(const comment_elt &oc)
Definition
comment-list.h:59
comment_elt::is_end_of_line
bool is_end_of_line() const
Definition
comment-list.h:83
comment_elt::comment_type
comment_type
Definition
comment-list.h:48
comment_elt::unknown
@ unknown
Definition
comment-list.h:49
comment_elt::block
@ block
Definition
comment-list.h:50
comment_elt::full_line
@ full_line
Definition
comment-list.h:51
comment_elt::end_of_line
@ end_of_line
Definition
comment-list.h:52
comment_elt::type
comment_type type() const
Definition
comment-list.h:79
comment_elt::is_full_line
bool is_full_line() const
Definition
comment-list.h:82
comment_elt::text
std::string text() const
Definition
comment-list.h:77
comment_elt::empty
bool empty() const
Definition
comment-list.h:75
comment_elt::uses_hash_char
bool uses_hash_char() const
Definition
comment-list.h:85
comment_elt::comment_elt
comment_elt(const std::string &s="", comment_type t=unknown, bool uses_hash_char=false)
Definition
comment-list.h:56
comment_elt::~comment_elt
~comment_elt()=default
comment_elt::is_block
bool is_block() const
Definition
comment-list.h:81
comment_elt::is_copyright
bool is_copyright() const
Definition
comment-list.h:84
comment_list
Definition
comment-list.h:110
comment_list::end
iterator end()
Definition
comment-list.h:144
comment_list::append
void append(const std::string &s, comment_elt::comment_type t=comment_elt::unknown, bool uses_hash_char=false)
Definition
comment-list.h:126
comment_list::clear
void clear()
Definition
comment-list.h:133
comment_list::append
void append(const comment_elt &elt)
Definition
comment-list.h:121
comment_list::const_reference
std::list< comment_elt >::const_reference const_reference
Definition
comment-list.h:116
comment_list::end
const_iterator end() const
Definition
comment-list.h:147
comment_list::front
const_reference front() const
Definition
comment-list.h:140
comment_list::back
const_reference back() const
Definition
comment-list.h:141
comment_list::begin
const_iterator begin() const
Definition
comment-list.h:146
comment_list::dup
comment_list * dup() const
Definition
comment-list.cc:38
comment_list::front
reference front()
Definition
comment-list.h:137
comment_list::reference
std::list< comment_elt >::reference reference
Definition
comment-list.h:115
comment_list::back
reference back()
Definition
comment-list.h:138
comment_list::find_doc_comment
comment_elt find_doc_comment() const
Definition
comment-list.h:153
comment_list::find_doc_string
std::string find_doc_string() const
Definition
comment-list.h:165
comment_list::begin
iterator begin()
Definition
comment-list.h:143
comment_list::iterator
std::list< comment_elt >::iterator iterator
Definition
comment-list.h:118
comment_list::const_iterator
std::list< comment_elt >::const_iterator const_iterator
Definition
comment-list.h:119
comment_list::empty
bool empty() const
Definition
comment-list.h:135
get_comment_text_c_str
char * get_comment_text_c_str()
save_comment_text
void save_comment_text(const std::string &text)
get_comment_text
std::string get_comment_text()
OCTAVE_BEGIN_NAMESPACE
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
libinterp
parse-tree
comment-list.h
Generated on Sat Aug 2 2025 06:52:12 for GNU Octave by
1.9.8