comparison libinterp/parse-tree/comment-list.h @ 33292:2e840d58dba7

comment_list: don't inherit from std::list * comment-list.h (class comment_list): Store std::list<comment_elt> as data member instead of using inheritance. Adjust member functions. (comment_list::reference, comment_list::const_reference, comment_list::iterator, comment_list::const_iterator): New typedefs. (comment_list::clear, comment_list::front, comment_list::back, comment_list::begin, comment_list::end, comment_list::empty): New methods.
author John W. Eaton <jwe@octave.org>
date Thu, 28 Mar 2024 13:00:25 -0400
parents 0b5f3219b650
children
comparison
equal deleted inserted replaced
33290:1077e4739169 33292:2e840d58dba7
27 #define octave_comment_list_h 1 27 #define octave_comment_list_h 1
28 28
29 #include "octave-config.h" 29 #include "octave-config.h"
30 30
31 #include <list> 31 #include <list>
32 #include <memory>
32 #include <string> 33 #include <string>
33 34
34 OCTAVE_BEGIN_NAMESPACE(octave) 35 OCTAVE_BEGIN_NAMESPACE(octave)
35 36
36 extern std::string get_comment_text (); 37 extern std::string get_comment_text ();
103 // TRUE means a line comment uses '#' or a block comment used at least 104 // TRUE means a line comment uses '#' or a block comment used at least
104 // one '#' delimiter. 105 // one '#' delimiter.
105 bool m_uses_hash_char; 106 bool m_uses_hash_char;
106 }; 107 };
107 108
108 class comment_list : public std::list<comment_elt> 109 class comment_list
109 { 110 {
110 public: 111 public:
111 112
112 OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (comment_list) 113 OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (comment_list)
113 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
114 void append (const comment_elt& elt) 121 void append (const comment_elt& elt)
115 { 122 {
116 push_back (elt); 123 m_list.push_back (elt);
117 } 124 }
118 125
119 void append (const std::string& s, 126 void append (const std::string& s,
120 comment_elt::comment_type t = comment_elt::unknown, 127 comment_elt::comment_type t = comment_elt::unknown,
121 bool uses_hash_char = false) 128 bool uses_hash_char = false)
122 { 129 {
123 push_back (comment_elt (s, t, uses_hash_char)); 130 m_list.push_back (comment_elt (s, t, uses_hash_char));
124 } 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 (); }
125 148
126 comment_list * dup () const; 149 comment_list * dup () const;
127 150
128 // Documentation for functions is typically the first block of 151 // Documentation for functions is typically the first block of
129 // comments that doesn't look like a copyright statement. 152 // comments that doesn't look like a copyright statement.
130 comment_elt find_doc_comment () const 153 comment_elt find_doc_comment () const
131 { 154 {
132 for (const auto& elt : *this) 155 for (const auto& elt : m_list)
133 { 156 {
134 // FIXME: should we also omit end-of-line comments? 157 // FIXME: should we also omit end-of-line comments?
135 if (! elt.is_copyright ()) 158 if (! elt.is_copyright ())
136 return elt; 159 return elt;
137 } 160 }
141 164
142 std::string find_doc_string () const 165 std::string find_doc_string () const
143 { 166 {
144 return find_doc_comment().text (); 167 return find_doc_comment().text ();
145 } 168 }
169
170 private:
171
172 std::list<comment_elt> m_list;
146 }; 173 };
147 174
148 OCTAVE_END_NAMESPACE(octave) 175 OCTAVE_END_NAMESPACE(octave)
149 176
150 #endif 177 #endif