cmd-hist.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-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_cmd_hist_h)
00024 #define octave_cmd_hist_h 1
00025 
00026 #include <string>
00027 
00028 #include "str-vec.h"
00029 
00030 class
00031 OCTAVE_API
00032 command_history
00033 {
00034 protected:
00035 
00036   command_history (void)
00037     : initialized (false), ignoring_additions (false), history_control (0),
00038       lines_in_file (0), lines_this_session (0), xfile (), xsize (-1) { }
00039 
00040 public:
00041 
00042   virtual ~command_history (void) { }
00043 
00044   static void initialize (bool, const std::string&, int, const std::string&);
00045 
00046   static bool is_initialized (void);
00047 
00048   static void set_file (const std::string&);
00049 
00050   static std::string file (void);
00051 
00052   static void process_histcontrol (const std::string&);
00053 
00054   static std::string histcontrol (void);
00055 
00056   static void set_size (int);
00057 
00058   static int size (void);
00059 
00060   static void ignore_entries (bool = true);
00061 
00062   static bool ignoring_entries (void);
00063 
00064   static void add (const std::string&);
00065 
00066   static void remove (int);
00067 
00068   static int where (void);
00069 
00070   static int length (void);
00071 
00072   static int max_input_history (void);
00073 
00074   static int base (void);
00075 
00076   static int current_number (void);
00077 
00078   static void stifle (int);
00079 
00080   static int unstifle (void);
00081 
00082   static int is_stifled (void);
00083 
00084   static void set_mark (int n);
00085 
00086   // Gag.  This declaration has to match the Function typedef in
00087   // readline.h.
00088 
00089   static int goto_mark (void);
00090 
00091   static void read (bool = true);
00092 
00093   static void read (const std::string&, bool = true);
00094 
00095   static void read_range (int = -1, int = -1, bool = true);
00096 
00097   static void read_range (const std::string&, int = -1, int = -1,
00098                           bool = true);
00099 
00100   static void write (const std::string& = std::string ());
00101 
00102   static void append (const std::string& = std::string ());
00103 
00104   static void truncate_file (const std::string& = std::string (), int = -1);
00105 
00106   static string_vector list (int = -1, bool = false);
00107 
00108   static std::string get_entry (int);
00109 
00110   static void replace_entry (int, const std::string&);
00111 
00112   static void clean_up_and_save (const std::string& = std::string (), int = -1);
00113 
00114 private:
00115 
00116   // No copying!
00117 
00118   command_history (const command_history&);
00119 
00120   command_history& operator = (const command_history&);
00121 
00122   static bool instance_ok (void);
00123 
00124   static void make_command_history (void);
00125 
00126   // The real thing.
00127   static command_history *instance;
00128 
00129   static void cleanup_instance (void) { delete instance; instance = 0; }
00130 
00131 protected:
00132 
00133   // To use something other than the GNU history library, derive a new
00134   // class from command_history, overload these functions as
00135   // necessary, and make instance point to the new class.
00136 
00137   virtual void do_set_file (const std::string&);
00138 
00139   virtual std::string do_file (void);
00140 
00141   virtual void do_process_histcontrol (const std::string&);
00142 
00143   virtual std::string do_histcontrol (void) const { return std::string (); }
00144 
00145   virtual void do_initialize (bool, const std::string&, int, const std::string&);
00146 
00147   virtual bool do_is_initialized (void) const;
00148 
00149   virtual void do_set_size (int);
00150 
00151   virtual int do_size (void) const;
00152 
00153   virtual void do_ignore_entries (bool);
00154 
00155   virtual bool do_ignoring_entries (void) const;
00156 
00157   virtual void do_add (const std::string&);
00158 
00159   virtual void do_remove (int);
00160 
00161   virtual int do_where (void) const;
00162 
00163   virtual int do_length (void) const;
00164 
00165   virtual int do_max_input_history (void) const;
00166 
00167   virtual int do_base (void) const;
00168 
00169   virtual int do_current_number (void) const;
00170 
00171   virtual void do_stifle (int);
00172 
00173   virtual int do_unstifle (void);
00174 
00175   virtual int do_is_stifled (void) const;
00176 
00177   virtual void do_set_mark (int);
00178 
00179   virtual int do_goto_mark (void);
00180 
00181   virtual void do_read (const std::string&, bool);
00182 
00183   virtual void do_read_range (const std::string&, int, int, bool);
00184 
00185   virtual void do_write (const std::string&) const;
00186 
00187   virtual void do_append (const std::string&);
00188 
00189   virtual void do_truncate_file (const std::string&, int) const;
00190 
00191   virtual string_vector do_list (int, bool) const;
00192 
00193   virtual std::string do_get_entry (int) const;
00194 
00195   virtual void do_replace_entry (int, const std::string&);
00196 
00197   virtual void do_clean_up_and_save (const std::string&, int);
00198 
00199   void error (int) const;
00200 
00201   void error (const std::string&) const;
00202 
00203   // TRUE means we have initialized the history file name and number of
00204   // lines to save.
00205   bool initialized;
00206 
00207   // TRUE means we are ignoring new additions.
00208   bool ignoring_additions;
00209 
00210   // Bitmask for history control options.  See oct-rl-hist.h.
00211   int history_control;
00212 
00213   // The number of history lines we read from the history file.
00214   int lines_in_file;
00215 
00216   // The number of history lines we've saved so far.
00217   int lines_this_session;
00218 
00219   // The default history file.
00220   std::string xfile;
00221 
00222   // The number of lines of history to save.
00223   int xsize;
00224 };
00225 
00226 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines