comment-list.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2000-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include "lo-utils.h"
00028 #include "singleton-cleanup.h"
00029 
00030 #include "comment-list.h"
00031 #include "error.h"
00032 
00033 octave_comment_buffer *octave_comment_buffer::instance = 0;
00034 
00035 octave_comment_list *
00036 octave_comment_list::dup (void) const
00037 {
00038   octave_comment_list *new_cl = new octave_comment_list ();
00039 
00040   for (const_iterator p = begin (); p != end (); p++)
00041     {
00042       const octave_comment_elt elt = *p;
00043 
00044       new_cl->append (elt);
00045     }
00046 
00047   return new_cl;
00048 }
00049 
00050 bool
00051 octave_comment_buffer::instance_ok (void)
00052 {
00053   bool retval = true;
00054 
00055   if (! instance)
00056     {
00057       instance = new octave_comment_buffer ();
00058 
00059       if (instance)
00060         singleton_cleanup_list::add (cleanup_instance);
00061     }
00062 
00063   if (! instance)
00064     {
00065       ::error ("unable to create comment buffer object");
00066 
00067       retval = false;
00068     }
00069 
00070   return retval;
00071 }
00072 
00073 void
00074 octave_comment_buffer::append (const std::string& s,
00075                                octave_comment_elt::comment_type t)
00076 {
00077   if (instance_ok ())
00078     instance->do_append (s, t);
00079 }
00080 
00081 octave_comment_list *
00082 octave_comment_buffer::get_comment (void)
00083 {
00084   return (instance_ok ()) ? instance->do_get_comment () : 0;
00085 }
00086 
00087 void
00088 octave_comment_buffer::do_append (const std::string& s,
00089                                   octave_comment_elt::comment_type t)
00090 {
00091   comment_list->append(s, t);
00092 }
00093 
00094 octave_comment_list *
00095 octave_comment_buffer::do_get_comment (void)
00096 {
00097   octave_comment_list *retval = 0;
00098 
00099   if (comment_list && comment_list->length () > 0)
00100     {
00101       retval = comment_list;
00102       comment_list = new octave_comment_list ();
00103     }
00104 
00105   return retval;
00106 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines