Mercurial > octave
comparison libinterp/corefcn/comment-list.cc @ 17693:efbe746f8fa8
eliminate octave_comment_buffer singleton
* lex.h (octave_base_lexer::comment_buffer): New class adapted from
octave_comment_buffer class. No longer a singleton class.
(octave_base_lexer::comment_buffer::reset): New function.
(octave_base_lexer::reset): Call comment_buf.reset.
(octave_base_lexer::comment_buf): New data member.
(octave_base_lexer::get_comment): New function.
* comment-list.h, comment-list.cc (octave_comment_buffer): Delete.
Change all uses of octave_comment_buffer to use local comment_buf
object instead.
* parse.h (octave_base_parser::make_statement): New member function.
* oct-parse.in.yy (make_statement): Delete.
Change all uses of make_statement to use the member function instead.
(safe_fclose): Don't extract and delete comment list here.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 18 Oct 2013 21:00:33 -0400 |
parents | 68fc671a9339 |
children | d63878346099 |
comparison
equal
deleted
inserted
replaced
17692:38cf56b77274 | 17693:efbe746f8fa8 |
---|---|
23 #ifdef HAVE_CONFIG_H | 23 #ifdef HAVE_CONFIG_H |
24 #include <config.h> | 24 #include <config.h> |
25 #endif | 25 #endif |
26 | 26 |
27 #include "lo-utils.h" | 27 #include "lo-utils.h" |
28 #include "singleton-cleanup.h" | |
29 | 28 |
30 #include "comment-list.h" | 29 #include "comment-list.h" |
31 #include "error.h" | 30 #include "error.h" |
32 | |
33 octave_comment_buffer *octave_comment_buffer::instance = 0; | |
34 | 31 |
35 octave_comment_list * | 32 octave_comment_list * |
36 octave_comment_list::dup (void) const | 33 octave_comment_list::dup (void) const |
37 { | 34 { |
38 octave_comment_list *new_cl = new octave_comment_list (); | 35 octave_comment_list *new_cl = new octave_comment_list (); |
44 new_cl->append (elt); | 41 new_cl->append (elt); |
45 } | 42 } |
46 | 43 |
47 return new_cl; | 44 return new_cl; |
48 } | 45 } |
49 | |
50 bool | |
51 octave_comment_buffer::instance_ok (void) | |
52 { | |
53 bool retval = true; | |
54 | |
55 if (! instance) | |
56 { | |
57 instance = new octave_comment_buffer (); | |
58 | |
59 if (instance) | |
60 singleton_cleanup_list::add (cleanup_instance); | |
61 } | |
62 | |
63 if (! instance) | |
64 { | |
65 ::error ("unable to create comment buffer object"); | |
66 | |
67 retval = false; | |
68 } | |
69 | |
70 return retval; | |
71 } | |
72 | |
73 void | |
74 octave_comment_buffer::append (const std::string& s, | |
75 octave_comment_elt::comment_type t) | |
76 { | |
77 if (instance_ok ()) | |
78 instance->do_append (s, t); | |
79 } | |
80 | |
81 octave_comment_list * | |
82 octave_comment_buffer::get_comment (void) | |
83 { | |
84 return (instance_ok ()) ? instance->do_get_comment () : 0; | |
85 } | |
86 | |
87 void | |
88 octave_comment_buffer::do_append (const std::string& s, | |
89 octave_comment_elt::comment_type t) | |
90 { | |
91 comment_list->append (s, t); | |
92 } | |
93 | |
94 octave_comment_list * | |
95 octave_comment_buffer::do_get_comment (void) | |
96 { | |
97 octave_comment_list *retval = 0; | |
98 | |
99 if (comment_list && comment_list->length () > 0) | |
100 { | |
101 retval = comment_list; | |
102 comment_list = new octave_comment_list (); | |
103 } | |
104 | |
105 return retval; | |
106 } |