GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
cmd-hist.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_cmd_hist_h)
27 #define octave_cmd_hist_h 1
28 
29 #include "octave-config.h"
30 
31 #include <string>
32 
33 #include "str-vec.h"
34 
36 
37 class
40 {
41 protected:
42 
44  : m_initialized (false), m_ignoring_additions (false),
45  m_history_control (0), m_lines_in_file (0),
46  m_lines_this_session (0), m_file (), m_size (-1)
47  { }
48 
49 public:
50 
51  // No copying!
52 
53  command_history (const command_history&) = delete;
54 
55  command_history& operator = (const command_history&) = delete;
56 
57  virtual ~command_history (void) = default;
58 
59  static void initialize (bool, const std::string&, int, const std::string&);
60 
61  static bool is_initialized (void);
62 
63  static void set_file (const std::string&);
64 
65  static std::string file (void);
66 
67  static void process_histcontrol (const std::string&);
68 
69  static std::string histcontrol (void);
70 
71  static void set_size (int);
72 
73  static int size (void);
74 
75  static void ignore_entries (bool = true);
76 
77  static bool ignoring_entries (void);
78 
79  static bool add (const std::string&);
80 
81  static void remove (int);
82 
83  static void clear (void);
84 
85  static int where (void);
86 
87  static int length (void);
88 
89  static int max_input_history (void);
90 
91  static int base (void);
92 
93  static int current_number (void);
94 
95  static void stifle (int);
96 
97  static int unstifle (void);
98 
99  static int is_stifled (void);
100 
101  static void set_mark (int n);
102 
103  // Gag. This declaration has to match the Function typedef in
104  // readline.h.
105 
106  static int goto_mark (void);
107 
108  static void read (bool = true);
109 
110  static void read (const std::string&, bool = true);
111 
112  static void read_range (int = -1, int = -1, bool = true);
113 
114  static void read_range (const std::string&, int = -1, int = -1,
115  bool = true);
116 
117  static void write (const std::string& = "");
118 
119  static void append (const std::string& = "");
120 
121  static void truncate_file (const std::string& = "", int = -1);
122 
123  static string_vector list (int = -1, bool = false);
124 
125  static std::string get_entry (int);
126 
127  static void replace_entry (int, const std::string&);
128 
129  static void clean_up_and_save (const std::string& = "", int = -1);
130 
131 private:
132 
133  static bool instance_ok (void);
134 
135  static void make_command_history (void);
136 
137  // The real thing.
139 
140  static void cleanup_instance (void)
141  {
142  delete s_instance;
143  s_instance = nullptr;
144  }
145 
146 protected:
147 
148  // To use something other than the GNU history library, derive a new
149  // class from command_history, overload these functions as
150  // necessary, and make instance point to the new class.
151 
152  virtual void do_set_file (const std::string&);
153 
154  virtual std::string do_file (void);
155 
156  virtual void do_process_histcontrol (const std::string&);
157 
158  virtual std::string do_histcontrol (void) const { return ""; }
159 
160  virtual void do_initialize (bool, const std::string&, int,
161  const std::string&);
162 
163  virtual bool do_is_initialized (void) const;
164 
165  virtual void do_set_size (int);
166 
167  virtual int do_size (void) const;
168 
169  virtual void do_ignore_entries (bool);
170 
171  virtual bool do_ignoring_entries (void) const;
172 
173  virtual bool do_add (const std::string&);
174 
175  virtual void do_remove (int);
176 
177  virtual void do_clear (void);
178 
179  virtual int do_where (void) const;
180 
181  virtual int do_length (void) const;
182 
183  virtual int do_max_input_history (void) const;
184 
185  virtual int do_base (void) const;
186 
187  virtual int do_current_number (void) const;
188 
189  virtual void do_stifle (int);
190 
191  virtual int do_unstifle (void);
192 
193  virtual int do_is_stifled (void) const;
194 
195  virtual void do_set_mark (int);
196 
197  virtual int do_goto_mark (void);
198 
199  virtual void do_read (const std::string&, bool);
200 
201  virtual void do_read_range (const std::string&, int, int, bool);
202 
203  virtual void do_write (const std::string&) const;
204 
205  virtual void do_append (const std::string&);
206 
207  virtual void do_truncate_file (const std::string&, int) const;
208 
209  virtual string_vector do_list (int, bool) const;
210 
211  virtual std::string do_get_entry (int) const;
212 
213  virtual void do_replace_entry (int, const std::string&);
214 
215  virtual void do_clean_up_and_save (const std::string&, int);
216 
217  void error (int, const std::string& msg = "") const;
218 
219  void error (const std::string&) const;
220 
221  // TRUE means we have initialized the history filename and number of
222  // lines to save.
224 
225  // TRUE means we are ignoring new additions.
227 
228  // Bitmask for history control options. See oct-rl-hist.h.
230 
231  // The number of history lines we read from the history file.
233 
234  // The number of history lines we've saved so far.
236 
237  // The default history file.
238  std::string m_file;
239 
240  // The number of lines of history to save.
241  int m_size;
242 };
243 
245 
246 #endif
OCTAVE_END_NAMESPACE(octave)
int m_lines_in_file
Definition: cmd-hist.h:232
bool m_ignoring_additions
Definition: cmd-hist.h:226
static command_history * s_instance
Definition: cmd-hist.h:138
static void cleanup_instance(void)
Definition: cmd-hist.h:140
virtual ~command_history(void)=default
virtual std::string do_histcontrol(void) const
Definition: cmd-hist.h:158
int m_lines_this_session
Definition: cmd-hist.h:235
bool m_initialized
Definition: cmd-hist.h:223
command_history(void)
Definition: cmd-hist.h:43
std::string m_file
Definition: cmd-hist.h:238
command_history(const command_history &)=delete
int m_history_control
Definition: cmd-hist.h:229
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition: error.cc:979
#define OCTAVE_API
Definition: main.in.cc:55
octave_idx_type n
Definition: mx-inlines.cc:753
static void initialize(void)