Mercurial > octave
changeset 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 | 1077e4739169 |
children | e4450472a9db |
files | libinterp/parse-tree/comment-list.h |
diffstat | 1 files changed, 31 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/comment-list.h Tue Apr 02 12:53:50 2024 -0400 +++ b/libinterp/parse-tree/comment-list.h Thu Mar 28 13:00:25 2024 -0400 @@ -29,6 +29,7 @@ #include "octave-config.h" #include <list> +#include <memory> #include <string> OCTAVE_BEGIN_NAMESPACE(octave) @@ -105,31 +106,53 @@ bool m_uses_hash_char; }; -class comment_list : public std::list<comment_elt> +class comment_list { public: OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (comment_list) + typedef std::list<comment_elt>::reference reference; + typedef std::list<comment_elt>::const_reference const_reference; + + typedef std::list<comment_elt>::iterator iterator; + typedef std::list<comment_elt>::const_iterator const_iterator; + void append (const comment_elt& elt) { - push_back (elt); + m_list.push_back (elt); } void append (const std::string& s, comment_elt::comment_type t = comment_elt::unknown, bool uses_hash_char = false) { - push_back (comment_elt (s, t, uses_hash_char)); + m_list.push_back (comment_elt (s, t, uses_hash_char)); } + void clear () { m_list.clear (); } + + bool empty () const { return m_list.empty (); } + + reference front () { return m_list.front (); } + reference back () { return m_list.back (); } + + const_reference front () const { return m_list.front (); } + const_reference back () const { return m_list.back (); } + + iterator begin () { return m_list.begin (); } + iterator end () { return m_list.end (); } + + const_iterator begin () const { return m_list.begin (); } + const_iterator end () const { return m_list.end (); } + comment_list * dup () const; // Documentation for functions is typically the first block of // comments that doesn't look like a copyright statement. comment_elt find_doc_comment () const { - for (const auto& elt : *this) + for (const auto& elt : m_list) { // FIXME: should we also omit end-of-line comments? if (! elt.is_copyright ()) @@ -143,6 +166,10 @@ { return find_doc_comment().text (); } + +private: + + std::list<comment_elt> m_list; }; OCTAVE_END_NAMESPACE(octave)