pager.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1993-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_pager_h)
00024 #define octave_pager_h 1
00025 
00026 #include <iosfwd>
00027 #include <sstream>
00028 #include <string>
00029 
00030 #include <sys/types.h>
00031 
00032 class
00033 OCTINTERP_API
00034 octave_pager_buf : public std::stringbuf
00035 {
00036 public:
00037 
00038   octave_pager_buf (void) : std::stringbuf (), diary_skip (0) { }
00039 
00040   void flush_current_contents_to_diary (void);
00041 
00042   void set_diary_skip (void);
00043 
00044 protected:
00045 
00046   int sync (void);
00047 
00048 private:
00049 
00050   size_t diary_skip;
00051 };
00052 
00053 class
00054 OCTINTERP_API
00055 octave_pager_stream : public std::ostream
00056 {
00057 protected:
00058 
00059   octave_pager_stream (void);
00060 
00061 public:
00062 
00063   ~octave_pager_stream (void);
00064 
00065   static void flush_current_contents_to_diary (void);
00066 
00067   static void set_diary_skip (void);
00068 
00069   static std::ostream& stream (void);
00070 
00071   static void reset (void);
00072 
00073 private:
00074 
00075   void do_flush_current_contents_to_diary (void);
00076 
00077   void do_set_diary_skip (void);
00078 
00079   void do_reset (void);
00080 
00081   static octave_pager_stream *instance;
00082 
00083   static bool instance_ok (void);
00084 
00085   static void cleanup_instance (void) { delete instance; instance = 0; }
00086 
00087   octave_pager_buf *pb;
00088 
00089   // No copying!
00090 
00091   octave_pager_stream (const octave_pager_stream&);
00092 
00093   octave_pager_stream& operator = (const octave_pager_stream&);
00094 };
00095 
00096 class
00097 OCTINTERP_API
00098 octave_diary_buf : public std::stringbuf
00099 {
00100 public:
00101 
00102   octave_diary_buf (void) : std::stringbuf () { }
00103 
00104 protected:
00105 
00106   int sync (void);
00107 };
00108 
00109 class
00110 OCTINTERP_API
00111 octave_diary_stream : public std::ostream
00112 {
00113 protected:
00114 
00115   octave_diary_stream (void);
00116 
00117 public:
00118 
00119   ~octave_diary_stream (void);
00120 
00121   static std::ostream& stream (void);
00122 
00123   static void reset (void);
00124 
00125 private:
00126 
00127   void do_reset (void);
00128 
00129   static octave_diary_stream *instance;
00130 
00131   static bool instance_ok (void);
00132 
00133   static void cleanup_instance (void) { delete instance; instance = 0; }
00134 
00135   octave_diary_buf *db;
00136 
00137   // No copying!
00138 
00139   octave_diary_stream (const octave_diary_stream&);
00140 
00141   octave_diary_stream& operator = (const octave_diary_stream&);
00142 };
00143 
00144 #define octave_stdout (octave_pager_stream::stream ())
00145 
00146 #define octave_diary (octave_diary_stream::stream ())
00147 
00148 extern OCTINTERP_API void flush_octave_stdout (void);
00149 
00150 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines