comment-list.h

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 #if !defined (octave_comment_list_h)
00024 #define octave_comment_list_h 1
00025 
00026 #include <string>
00027 
00028 #include <base-list.h>
00029 
00030 extern std::string get_comment_text (void);
00031 
00032 extern char *get_comment_text_c_str (void);
00033 
00034 extern void save_comment_text (const std::string& text);
00035 
00036 class
00037 octave_comment_elt
00038 {
00039 public:
00040 
00041   enum comment_type
00042   {
00043     unknown,
00044     block,
00045     end_of_line,
00046     doc_string,
00047     copyright
00048   };
00049 
00050   octave_comment_elt (const std::string& s = std::string (),
00051                       comment_type t = unknown)
00052     : txt (s), typ (t) { }
00053 
00054   octave_comment_elt (const octave_comment_elt& oc)
00055     : txt (oc.txt), typ (oc.typ) { }
00056 
00057   octave_comment_elt& operator = (const octave_comment_elt& oc)
00058     {
00059       if (this != &oc)
00060         {
00061           txt = oc.txt;
00062           typ = oc.typ;
00063         }
00064 
00065       return *this;
00066     }
00067 
00068   std::string text (void) const { return txt; }
00069 
00070   comment_type type (void) const { return typ; }
00071 
00072   ~octave_comment_elt (void) { }
00073 
00074 private:
00075 
00076   // The text of the comment.
00077   std::string txt;
00078 
00079   // The type of comment.
00080   comment_type typ;
00081 };
00082 
00083 class
00084 octave_comment_list : public octave_base_list<octave_comment_elt>
00085 {
00086 public:
00087 
00088   octave_comment_list (void) { }
00089 
00090   void append (const octave_comment_elt& elt)
00091     { octave_base_list<octave_comment_elt>::append (elt); }
00092 
00093   void append (const std::string& s,
00094                octave_comment_elt::comment_type t = octave_comment_elt::unknown)
00095     { append (octave_comment_elt (s, t)); }
00096 
00097   octave_comment_list *dup (void) const;
00098 };
00099 
00100 class
00101 octave_comment_buffer
00102 {
00103 public:
00104 
00105   octave_comment_buffer (void)
00106     : comment_list (new octave_comment_list ()) { }
00107 
00108   ~octave_comment_buffer (void) { delete comment_list; }
00109 
00110   static bool instance_ok (void);
00111 
00112   static void append
00113     (const std::string& s,
00114      octave_comment_elt::comment_type t = octave_comment_elt::unknown);
00115 
00116   static octave_comment_list *get_comment (void);
00117 
00118 private:
00119 
00120   void do_append (const std::string& s, octave_comment_elt::comment_type t);
00121 
00122   octave_comment_list *do_get_comment (void);
00123 
00124   octave_comment_list *comment_list;
00125 
00126   static octave_comment_buffer *instance;
00127 
00128   static void cleanup_instance (void) { delete instance; instance = 0; }
00129 };
00130 
00131 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines