GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
cmd-hist.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_cmd_hist_h)
24 #define octave_cmd_hist_h 1
25 
26 #include <string>
27 
28 #include "str-vec.h"
29 
30 class
31 OCTAVE_API
33 {
34 protected:
35 
37  : initialized (false), ignoring_additions (false), history_control (0),
38  lines_in_file (0), lines_this_session (0), xfile (), xsize (-1) { }
39 
40 public:
41 
42  virtual ~command_history (void) { }
43 
44  static void initialize (bool, const std::string&, int, const std::string&);
45 
46  static bool is_initialized (void);
47 
48  static void set_file (const std::string&);
49 
50  static std::string file (void);
51 
52  static void process_histcontrol (const std::string&);
53 
54  static std::string histcontrol (void);
55 
56  static void set_size (int);
57 
58  static int size (void);
59 
60  static void ignore_entries (bool = true);
61 
62  static bool ignoring_entries (void);
63 
64  static bool add (const std::string&);
65 
66  static void remove (int);
67 
68  static void clear (void);
69 
70  static int where (void);
71 
72  static int length (void);
73 
74  static int max_input_history (void);
75 
76  static int base (void);
77 
78  static int current_number (void);
79 
80  static void stifle (int);
81 
82  static int unstifle (void);
83 
84  static int is_stifled (void);
85 
86  static void set_mark (int n);
87 
88  // Gag. This declaration has to match the Function typedef in
89  // readline.h.
90 
91  static int goto_mark (void);
92 
93  static void read (bool = true);
94 
95  static void read (const std::string&, bool = true);
96 
97  static void read_range (int = -1, int = -1, bool = true);
98 
99  static void read_range (const std::string&, int = -1, int = -1,
100  bool = true);
101 
102  static void write (const std::string& = std::string ());
103 
104  static void append (const std::string& = std::string ());
105 
106  static void truncate_file (const std::string& = std::string (), int = -1);
107 
108  static string_vector list (int = -1, bool = false);
109 
110  static std::string get_entry (int);
111 
112  static void replace_entry (int, const std::string&);
113 
114  static void clean_up_and_save (const std::string& = std::string (), int = -1);
115 
116 private:
117 
118  // No copying!
119 
121 
122  command_history& operator = (const command_history&);
123 
124  static bool instance_ok (void);
125 
126  static void make_command_history (void);
127 
128  // The real thing.
130 
131  static void cleanup_instance (void) { delete instance; instance = 0; }
132 
133 protected:
134 
135  // To use something other than the GNU history library, derive a new
136  // class from command_history, overload these functions as
137  // necessary, and make instance point to the new class.
138 
139  virtual void do_set_file (const std::string&);
140 
141  virtual std::string do_file (void);
142 
143  virtual void do_process_histcontrol (const std::string&);
144 
145  virtual std::string do_histcontrol (void) const { return std::string (); }
146 
147  virtual void do_initialize (bool, const std::string&, int,
148  const std::string&);
149 
150  virtual bool do_is_initialized (void) const;
151 
152  virtual void do_set_size (int);
153 
154  virtual int do_size (void) const;
155 
156  virtual void do_ignore_entries (bool);
157 
158  virtual bool do_ignoring_entries (void) const;
159 
160  virtual bool do_add (const std::string&);
161 
162  virtual void do_remove (int);
163 
164  virtual void do_clear (void);
165 
166  virtual int do_where (void) const;
167 
168  virtual int do_length (void) const;
169 
170  virtual int do_max_input_history (void) const;
171 
172  virtual int do_base (void) const;
173 
174  virtual int do_current_number (void) const;
175 
176  virtual void do_stifle (int);
177 
178  virtual int do_unstifle (void);
179 
180  virtual int do_is_stifled (void) const;
181 
182  virtual void do_set_mark (int);
183 
184  virtual int do_goto_mark (void);
185 
186  virtual void do_read (const std::string&, bool);
187 
188  virtual void do_read_range (const std::string&, int, int, bool);
189 
190  virtual void do_write (const std::string&) const;
191 
192  virtual void do_append (const std::string&);
193 
194  virtual void do_truncate_file (const std::string&, int) const;
195 
196  virtual string_vector do_list (int, bool) const;
197 
198  virtual std::string do_get_entry (int) const;
199 
200  virtual void do_replace_entry (int, const std::string&);
201 
202  virtual void do_clean_up_and_save (const std::string&, int);
203 
204  void error (int, const std::string& msg = "") const;
205 
206  void error (const std::string&) const;
207 
208  // TRUE means we have initialized the history file name and number of
209  // lines to save.
211 
212  // TRUE means we are ignoring new additions.
214 
215  // Bitmask for history control options. See oct-rl-hist.h.
217 
218  // The number of history lines we read from the history file.
220 
221  // The number of history lines we've saved so far.
223 
224  // The default history file.
225  std::string xfile;
226 
227  // The number of lines of history to save.
228  int xsize;
229 };
230 
231 #endif
static void clear(octave_shlib &oct_file)
Definition: dynamic-ld.cc:236
std::string xfile
Definition: cmd-hist.h:225
bool ignoring_additions
Definition: cmd-hist.h:213
bool initialized
Definition: cmd-hist.h:210
void error(const char *fmt,...)
Definition: error.cc:476
static void cleanup_instance(void)
Definition: cmd-hist.h:131
int history_control
Definition: cmd-hist.h:216
virtual ~command_history(void)
Definition: cmd-hist.h:42
virtual std::string do_histcontrol(void) const
Definition: cmd-hist.h:145
static command_history * instance
Definition: cmd-hist.h:129
size_t size(T const (&)[z])
Definition: help.cc:103
command_history(void)
Definition: cmd-hist.h:36
int lines_this_session
Definition: cmd-hist.h:222
static void initialize(void)
Definition: mkoctfile.cc:111