3665
|
1 /* |
|
2 |
|
3 Copyright (C) 2000 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
3665
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
3665
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "lo-utils.h" |
|
28 |
|
29 #include "comment-list.h" |
|
30 #include "error.h" |
|
31 |
|
32 octave_comment_buffer *octave_comment_buffer::instance = 0; |
|
33 |
5861
|
34 octave_comment_list * |
|
35 octave_comment_list::dup (void) |
|
36 { |
|
37 octave_comment_list *new_cl = new octave_comment_list (); |
|
38 |
|
39 for (iterator p = begin (); p != end (); p++) |
|
40 { |
|
41 octave_comment_elt elt = *p; |
|
42 |
|
43 new_cl->append (elt); |
|
44 } |
|
45 |
|
46 return new_cl; |
|
47 } |
|
48 |
3665
|
49 bool |
|
50 octave_comment_buffer::instance_ok (void) |
|
51 { |
|
52 bool retval = true; |
|
53 |
|
54 if (! instance) |
|
55 instance = new octave_comment_buffer (); |
|
56 |
|
57 if (! instance) |
|
58 { |
|
59 ::error ("unable to create comment buffer object"); |
|
60 |
|
61 retval = false; |
|
62 } |
|
63 |
|
64 return retval; |
|
65 } |
|
66 |
|
67 void |
|
68 octave_comment_buffer::append (const std::string& s, |
|
69 octave_comment_elt::comment_type t) |
|
70 { |
|
71 if (instance_ok ()) |
|
72 instance->do_append (s, t); |
|
73 } |
|
74 |
|
75 octave_comment_list * |
|
76 octave_comment_buffer::get_comment (void) |
|
77 { |
|
78 return (instance_ok ()) ? instance->do_get_comment () : 0; |
|
79 } |
|
80 |
|
81 void |
|
82 octave_comment_buffer::do_append (const std::string& s, |
|
83 octave_comment_elt::comment_type t) |
|
84 { |
|
85 comment_list->append(s, t); |
|
86 } |
|
87 |
|
88 octave_comment_list * |
|
89 octave_comment_buffer::do_get_comment (void) |
|
90 { |
|
91 octave_comment_list *retval = 0; |
|
92 |
|
93 if (comment_list && comment_list->length () > 0) |
|
94 { |
|
95 retval = comment_list; |
|
96 comment_list = new octave_comment_list (); |
|
97 } |
|
98 |
|
99 return retval; |
|
100 } |
|
101 |
|
102 /* |
|
103 ;;; Local Variables: *** |
|
104 ;;; mode: C++ *** |
|
105 ;;; End: *** |
|
106 */ |