GNU Octave  9.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-2024 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  OCTAVE_DISABLE_COPY_MOVE (command_history)
52 
53  virtual ~command_history () = default;
54 
55  static void initialize (bool, const std::string&, int, const std::string&);
56 
57  static bool is_initialized ();
58 
59  static void set_file (const std::string&);
60 
61  static std::string file ();
62 
63  static void process_histcontrol (const std::string&);
64 
65  static std::string histcontrol ();
66 
67  static void set_size (int);
68 
69  static int size ();
70 
71  static void ignore_entries (bool = true);
72 
73  static bool ignoring_entries ();
74 
75  static bool add (const std::string&);
76 
77  static void remove (int);
78 
79  static void clear ();
80 
81  static int where ();
82 
83  static int length ();
84 
85  static int max_input_history ();
86 
87  static int base ();
88 
89  static int current_number ();
90 
91  static void stifle (int);
92 
93  static int unstifle ();
94 
95  static int is_stifled ();
96 
97  static void set_mark (int n);
98 
99  // Gag. This declaration has to match the Function typedef in
100  // readline.h.
101 
102  static int goto_mark ();
103 
104  static void read (bool = true);
105 
106  static void read (const std::string&, bool = true);
107 
108  static void read_range (int = -1, int = -1, bool = true);
109 
110  static void read_range (const std::string&, int = -1, int = -1,
111  bool = true);
112 
113  static void write (const std::string& = "");
114 
115  static void append (const std::string& = "");
116 
117  static void truncate_file (const std::string& = "", int = -1);
118 
119  static string_vector list (int = -1, bool = false);
120 
121  static std::string get_entry (int);
122 
123  static void replace_entry (int, const std::string&);
124 
125  static void clean_up_and_save (const std::string& = "", int = -1);
126 
127 private:
128 
129  static bool instance_ok ();
130 
131  static void make_command_history ();
132 
133  // The real thing.
134  static command_history *s_instance;
135 
136  static void cleanup_instance ()
137  {
138  delete s_instance;
139  s_instance = nullptr;
140  }
141 
142 protected:
143 
144  // To use something other than the GNU history library, derive a new
145  // class from command_history, overload these functions as
146  // necessary, and make instance point to the new class.
147 
148  virtual void do_set_file (const std::string&);
149 
150  virtual std::string do_file ();
151 
152  virtual void do_process_histcontrol (const std::string&);
153 
154  virtual std::string do_histcontrol () const { return ""; }
155 
156  virtual void do_initialize (bool, const std::string&, int,
157  const std::string&);
158 
159  virtual bool do_is_initialized () const;
160 
161  virtual void do_set_size (int);
162 
163  virtual int do_size () const;
164 
165  virtual void do_ignore_entries (bool);
166 
167  virtual bool do_ignoring_entries () const;
168 
169  virtual bool do_add (const std::string&);
170 
171  virtual void do_remove (int);
172 
173  virtual void do_clear ();
174 
175  virtual int do_where () const;
176 
177  virtual int do_length () const;
178 
179  virtual int do_max_input_history () const;
180 
181  virtual int do_base () const;
182 
183  virtual int do_current_number () const;
184 
185  virtual void do_stifle (int);
186 
187  virtual int do_unstifle ();
188 
189  virtual int do_is_stifled () const;
190 
191  virtual void do_set_mark (int);
192 
193  virtual int do_goto_mark ();
194 
195  virtual void do_read (const std::string&, bool);
196 
197  virtual void do_read_range (const std::string&, int, int, bool);
198 
199  virtual void do_write (const std::string&) const;
200 
201  virtual void do_append (const std::string&);
202 
203  virtual void do_truncate_file (const std::string&, int) const;
204 
205  virtual string_vector do_list (int, bool) const;
206 
207  virtual std::string do_get_entry (int) const;
208 
209  virtual void do_replace_entry (int, const std::string&);
210 
211  virtual void do_clean_up_and_save (const std::string&, int);
212 
213  void error (int, const std::string& msg = "") const;
214 
215  void error (const std::string&) const;
216 
217  // TRUE means we have initialized the history filename and number of
218  // lines to save.
220 
221  // TRUE means we are ignoring new additions.
223 
224  // Bitmask for history control options. See oct-rl-hist.h.
226 
227  // The number of history lines we read from the history file.
229 
230  // The number of history lines we've saved so far.
232 
233  // The default history file.
234  std::string m_file;
235 
236  // The number of lines of history to save.
237  int m_size;
238 };
239 
240 OCTAVE_END_NAMESPACE(octave)
241 
242 #endif
int m_lines_in_file
Definition: cmd-hist.h:228
bool m_ignoring_additions
Definition: cmd-hist.h:222
int m_lines_this_session
Definition: cmd-hist.h:231
bool m_initialized
Definition: cmd-hist.h:219
virtual std::string do_histcontrol() const
Definition: cmd-hist.h:154
std::string m_file
Definition: cmd-hist.h:234
int m_history_control
Definition: cmd-hist.h:225
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void() error(const char *fmt,...)
Definition: error.cc:988
#define OCTAVE_API
Definition: main.cc:55
octave_idx_type n
Definition: mx-inlines.cc:761