GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
comment-list.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2000-2024 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 <string>
32 
33 #include "base-list.h"
34 
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
45 {
46 public:
47 
49  {
54  copyright
55  };
56 
57  comment_elt (const std::string& s = "", comment_type t = unknown, bool uses_hash_char = false)
58  : m_text (s), m_type (t), m_uses_hash_char (uses_hash_char) { }
59 
61  : m_text (oc.m_text), m_type (oc.m_type), m_uses_hash_char (oc.m_uses_hash_char)
62  { }
63 
64  comment_elt& operator = (const comment_elt& oc)
65  {
66  if (this != &oc)
67  {
68  m_text = oc.m_text;
69  m_type = oc.m_type;
70  m_uses_hash_char = oc.m_uses_hash_char;
71  }
72 
73  return *this;
74  }
75 
76  bool empty () const { return m_text.empty (); }
77 
78  std::string text () const { return m_text; }
79 
80  comment_type type () const { return m_type; }
81 
82  bool is_block () const { return m_type == block; }
83  bool is_full_line () const { return m_type == full_line; }
84  bool is_end_of_line () const { return m_type == end_of_line; }
85  bool is_copyright () const { return m_type == copyright; }
86  bool uses_hash_char () const { return m_uses_hash_char; }
87 
88  void reset ()
89  {
90  m_text = "";
91  m_type = unknown;
92  m_uses_hash_char = false;
93  }
94 
95  ~comment_elt () = default;
96 
97 private:
98 
99  // The text of the comment.
100  std::string m_text;
101 
102  // The type of comment.
103  comment_type m_type;
104 
105  // TRUE means a line comment uses '#' or a block comment used at least
106  // one '#' delimiter.
107  bool m_uses_hash_char;
108 };
109 
110 class
112 {
113 public:
114 
115  OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (comment_list)
116 
117  void append (const comment_elt& elt)
119 
120  void append (const std::string& s,
122  bool uses_hash_char = false)
123  { append (comment_elt (s, t, uses_hash_char)); }
124 
125  comment_list * dup () const;
126 
127  // Documentation for functions is typically the first block of
128  // comments that doesn't look like a copyright statement.
130  {
131  for (const auto& elt : *this)
132  {
133  // FIXME: should we also omit end-of-line comments?
134  if (! elt.is_copyright ())
135  return elt;
136  }
137 
138  return comment_elt ();
139  }
140 
141  std::string find_doc_string () const
142  {
143  return find_doc_comment().text ();
144  }
145 };
146 
147 OCTAVE_END_NAMESPACE(octave)
148 
149 #endif
void append(const elt_type &s)
Definition: base-list.h:92
void reset()
Definition: comment-list.h:88
comment_elt(const comment_elt &oc)
Definition: comment-list.h:60
bool is_end_of_line() const
Definition: comment-list.h:84
comment_type type() const
Definition: comment-list.h:80
bool is_full_line() const
Definition: comment-list.h:83
std::string text() const
Definition: comment-list.h:78
bool empty() const
Definition: comment-list.h:76
bool uses_hash_char() const
Definition: comment-list.h:86
comment_elt(const std::string &s="", comment_type t=unknown, bool uses_hash_char=false)
Definition: comment-list.h:57
~comment_elt()=default
bool is_block() const
Definition: comment-list.h:82
bool is_copyright() const
Definition: comment-list.h:85
void append(const std::string &s, comment_elt::comment_type t=comment_elt::unknown, bool uses_hash_char=false)
Definition: comment-list.h:120
comment_elt find_doc_comment() const
Definition: comment-list.h:129
std::string find_doc_string() const
Definition: comment-list.h:141
void save_comment_text(const std::string &text)
char * get_comment_text_c_str()
std::string get_comment_text()
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn