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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
3665
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "lo-utils.h" |
|
29 |
|
30 #include "comment-list.h" |
|
31 #include "error.h" |
|
32 |
|
33 octave_comment_buffer *octave_comment_buffer::instance = 0; |
|
34 |
5861
|
35 octave_comment_list * |
|
36 octave_comment_list::dup (void) |
|
37 { |
|
38 octave_comment_list *new_cl = new octave_comment_list (); |
|
39 |
|
40 for (iterator p = begin (); p != end (); p++) |
|
41 { |
|
42 octave_comment_elt elt = *p; |
|
43 |
|
44 new_cl->append (elt); |
|
45 } |
|
46 |
|
47 return new_cl; |
|
48 } |
|
49 |
3665
|
50 bool |
|
51 octave_comment_buffer::instance_ok (void) |
|
52 { |
|
53 bool retval = true; |
|
54 |
|
55 if (! instance) |
|
56 instance = new octave_comment_buffer (); |
|
57 |
|
58 if (! instance) |
|
59 { |
|
60 ::error ("unable to create comment buffer object"); |
|
61 |
|
62 retval = false; |
|
63 } |
|
64 |
|
65 return retval; |
|
66 } |
|
67 |
|
68 void |
|
69 octave_comment_buffer::append (const std::string& s, |
|
70 octave_comment_elt::comment_type t) |
|
71 { |
|
72 if (instance_ok ()) |
|
73 instance->do_append (s, t); |
|
74 } |
|
75 |
|
76 octave_comment_list * |
|
77 octave_comment_buffer::get_comment (void) |
|
78 { |
|
79 return (instance_ok ()) ? instance->do_get_comment () : 0; |
|
80 } |
|
81 |
|
82 void |
|
83 octave_comment_buffer::do_append (const std::string& s, |
|
84 octave_comment_elt::comment_type t) |
|
85 { |
|
86 comment_list->append(s, t); |
|
87 } |
|
88 |
|
89 octave_comment_list * |
|
90 octave_comment_buffer::do_get_comment (void) |
|
91 { |
|
92 octave_comment_list *retval = 0; |
|
93 |
|
94 if (comment_list && comment_list->length () > 0) |
|
95 { |
|
96 retval = comment_list; |
|
97 comment_list = new octave_comment_list (); |
|
98 } |
|
99 |
|
100 return retval; |
|
101 } |
|
102 |
|
103 /* |
|
104 ;;; Local Variables: *** |
|
105 ;;; mode: C++ *** |
|
106 ;;; End: *** |
|
107 */ |