Mercurial > octave
annotate liboctave/cmd-hist.h @ 13983:7dd7cccf0757
clean up memory allocated for singletons before exit
* singleton-cleanup.h, singleton-cleanup.cc: New files.
* liboctave/Makefile.am (INCS, LIBOCTAVE_CXX_SOURCES):
Add them to the lists.
* toplev.cc (clean_up_and_exit): Call singleton_cleanup_list::cleanup.
* debug.h, debug.cc (bp_table::instance_ok): Move definition to
debug.cc.
* coment-list.h (octave_comment_buffer::~octave_comment_buffer):
Define destructor for class.
* ov-typeinfo.h (octave_value_typeinfo::~octave_value_typeinfo):
Likewise.
* cmd-edit.h (command_editor::cleanup_instance): New function.
* cmd-hist.h (command_history::cleanup_instance): New function.
* file-ops.h (file_ops::cleanup_instance): New function.
* mach-info.h (oct_mach_info::cleanup_instance): New function.
* oct-env.h (octave_env::cleanup_instance): New function.
* oct-fftw.h (octave_fftw_planner::cleanup_instance): New function.
* oct-rand.h (octave_rand::cleanup_instance): New function.
* oct-spparms.h (octave_sparse_params::cleanup_instance):
New function.
* pathsearch.h (static_members::cleanup_instance): New function.
* comment-list.h (octave_comment_buffer::cleanup_instance):
New function.
* debug.h (bp_table::cleanup_instance): New function.
* display.h (display_info::cleanup_instance): New function.
* dynamic-ld.cc (octave_shlib_list::cleanup_instance,
octave_mex_file_list::cleanup_instance): New functions.
* dynamic-ld.h (octave_dynamic_loader::cleanup_instance):
New function.
* load-path.h (load_path::cleanup_instance): New function.
* oct-stream.h (octave_stream_list::cleanup_instance): New function.
* ov-typeinfo.h (octave_value_typeinfo::cleanup_instance):
New function.
* pager.h, pager.cc (octave_pager_stream::instance_ok,
octave_pager_stream::cleanup_instance): New functions.
(octave_diary_stream::instance_ok,
octave_diary_stream::cleanup_instance): New functions.
* sighandlers.h (octave_child_list::cleanup_instance): New function.
* toplev.h (octave_call_stack
* pager.cc (octave_pager_stream::stream, octave_diary_stream::stream):
Use instance_ok to create instance.
* toplev.h (octave_call_stack::cleanup_instance): New function.
* cmd-edit.cc (command_editor::instance_ok):
Register cleanup function.
* cmd-hist.cc (command_history::instance_ok): Likewise.
* file-ops.cc (file_ops::instance_ok): Likewise.
* mach-info.cc (oct_mach_info::instance_ok): Likewise.
* oct-env.cc (octave_env::instance_ok): Likewise.
* oct-fftw.cc (octave_fftw_planner::instance_ok): Likewise.
* oct-rand.cc (octave_rand::instance_ok): Likewise.
* oct-spparms.cc (octave_sparse_params::instance_ok): Likewise.
* pathsearch.cc (dir_path::static_members::instance_ok): Likewise.
* comment-list.cc (comment_list::instance_ok): Likewise.
* debug.cc (bp_table::instance_ok): Likewise.
* display.cc (display_info::instance_ok): Likewise.
* dynamic-ld.cc (octave_shlib_list::instance_ok,
octave_mex_file_list::instance_ok, octave_dynamic_loader): Likewise.
* load-path.cc (load_path::instance_ok): Likewise.
* oct-stream.cc (octave_stream_list::instance_ok): Likewise.
* ov-typeinfo.cc (octave_value_typeinfo::instance_ok): Likewise.
* sighandlers.cc (octave_child_list::instance_ok): Likewise.
* symtab.h, symtab.cc (symbol_table::scope_id::create_instance):
New function.
* symtab.h (symbol_table::scope_id::instance_ok): Call create_instance.
* toplev.h, toplev.cc (octave_call_stack::create_instance):
New function.
* toplev.cc (octave_call_stack::instance_ok): Call create_instance.
* pager.h, pager.cc (octave_pager_stream::set_diary_skip,
octave_pager_stream::flush_current_contents_to_diary): Now static.
octave_pager_stream::do_set_diary_skip,
octave_pager_stream::do_flush_current_contents_to_diary):
New functions.
(octave_pager_stream::stream): Return std::ostream&, not
octave_pager_stream&. If instance creation fails, return std::cout.
(octave_diary_stream::stream): Return std::ostream&, not
octave_diary_stream&. If instance creation fails, return std::cout.
(octave_pager_stream::do_reset, octave_diary_stream::do_reset):
Use instance_ok to create instance.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 03 Dec 2011 04:34:17 -0500 |
parents | 60b6b175f88a |
children | 72c96de7a403 |
rev | line source |
---|---|
1797 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 John W. Eaton |
1797 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1797 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1797 | 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 | |
6108 | 31 OCTAVE_API |
1797 | 32 command_history |
33 { | |
2926 | 34 protected: |
35 | |
36 command_history (void) | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
37 : initialized (false), ignoring_additions (false), history_control (0), |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
38 lines_in_file (0), lines_this_session (0), xfile (), xsize (-1) { } |
2926 | 39 |
1797 | 40 public: |
41 | |
2926 | 42 virtual ~command_history (void) { } |
43 | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
44 static void initialize (bool, const std::string&, int, const std::string&); |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
45 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
46 static bool is_initialized (void); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
47 |
3504 | 48 static void set_file (const std::string&); |
1797 | 49 |
3504 | 50 static std::string file (void); |
1797 | 51 |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
52 static void process_histcontrol (const std::string&); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
53 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
54 static std::string histcontrol (void); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
55 |
2926 | 56 static void set_size (int); |
1797 | 57 |
2926 | 58 static int size (void); |
59 | |
60 static void ignore_entries (bool = true); | |
1797 | 61 |
2926 | 62 static bool ignoring_entries (void); |
1797 | 63 |
3504 | 64 static void add (const std::string&); |
1797 | 65 |
2926 | 66 static void remove (int); |
67 | |
68 static int where (void); | |
1797 | 69 |
2926 | 70 static int length (void); |
1797 | 71 |
2926 | 72 static int max_input_history (void); |
1797 | 73 |
2926 | 74 static int base (void); |
1797 | 75 |
2926 | 76 static int current_number (void); |
1797 | 77 |
2926 | 78 static void stifle (int); |
1797 | 79 |
2926 | 80 static int unstifle (void); |
1797 | 81 |
2926 | 82 static int is_stifled (void); |
1797 | 83 |
2926 | 84 static void set_mark (int n); |
1797 | 85 |
2926 | 86 // Gag. This declaration has to match the Function typedef in |
87 // readline.h. | |
1797 | 88 |
4802 | 89 static int goto_mark (void); |
2926 | 90 |
91 static void read (bool = true); | |
2658 | 92 |
3504 | 93 static void read (const std::string&, bool = true); |
1797 | 94 |
2926 | 95 static void read_range (int = -1, int = -1, bool = true); |
2658 | 96 |
3504 | 97 static void read_range (const std::string&, int = -1, int = -1, |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
98 bool = true); |
1797 | 99 |
3504 | 100 static void write (const std::string& = std::string ()); |
1797 | 101 |
3504 | 102 static void append (const std::string& = std::string ()); |
1797 | 103 |
3504 | 104 static void truncate_file (const std::string& = std::string (), int = -1); |
1797 | 105 |
2926 | 106 static string_vector list (int = -1, bool = false); |
1797 | 107 |
3504 | 108 static std::string get_entry (int); |
1797 | 109 |
3504 | 110 static void replace_entry (int, const std::string&); |
1797 | 111 |
3504 | 112 static void clean_up_and_save (const std::string& = std::string (), int = -1); |
1797 | 113 |
114 private: | |
115 | |
2926 | 116 // No copying! |
117 | |
118 command_history (const command_history&); | |
119 | |
120 command_history& operator = (const command_history&); | |
121 | |
122 static bool instance_ok (void); | |
123 | |
124 static void make_command_history (void); | |
125 | |
126 // The real thing. | |
127 static command_history *instance; | |
128 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12330
diff
changeset
|
129 static void cleanup_instance (void) { delete instance; instance = 0; } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
12330
diff
changeset
|
130 |
2926 | 131 protected: |
132 | |
133 // To use something other than the GNU history library, derive a new | |
134 // class from command_history, overload these functions as | |
135 // necessary, and make instance point to the new class. | |
136 | |
3504 | 137 virtual void do_set_file (const std::string&); |
2926 | 138 |
3504 | 139 virtual std::string do_file (void); |
2926 | 140 |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
141 virtual void do_process_histcontrol (const std::string&); |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
142 |
12330
60b6b175f88a
require readline to provide working history control
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
143 virtual std::string do_histcontrol (void) const { return std::string (); } |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
144 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
145 virtual void do_initialize (bool, const std::string&, int, const std::string&); |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
146 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
147 virtual bool do_is_initialized (void) const; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
148 |
2926 | 149 virtual void do_set_size (int); |
150 | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
151 virtual int do_size (void) const; |
2926 | 152 |
153 virtual void do_ignore_entries (bool); | |
154 | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
155 virtual bool do_ignoring_entries (void) const; |
2926 | 156 |
3504 | 157 virtual void do_add (const std::string&); |
2926 | 158 |
159 virtual void do_remove (int); | |
160 | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
161 virtual int do_where (void) const; |
2926 | 162 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
163 virtual int do_length (void) const; |
2926 | 164 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
165 virtual int do_max_input_history (void) const; |
2926 | 166 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
167 virtual int do_base (void) const; |
2926 | 168 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
169 virtual int do_current_number (void) const; |
2926 | 170 |
171 virtual void do_stifle (int); | |
172 | |
173 virtual int do_unstifle (void); | |
174 | |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
175 virtual int do_is_stifled (void) const; |
2926 | 176 |
177 virtual void do_set_mark (int); | |
178 | |
4802 | 179 virtual int do_goto_mark (void); |
2926 | 180 |
3504 | 181 virtual void do_read (const std::string&, bool); |
2926 | 182 |
3504 | 183 virtual void do_read_range (const std::string&, int, int, bool); |
2926 | 184 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
185 virtual void do_write (const std::string&) const; |
2926 | 186 |
3504 | 187 virtual void do_append (const std::string&); |
2926 | 188 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
189 virtual void do_truncate_file (const std::string&, int) const; |
2926 | 190 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
191 virtual string_vector do_list (int, bool) const; |
2926 | 192 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
193 virtual std::string do_get_entry (int) const; |
2926 | 194 |
3504 | 195 virtual void do_replace_entry (int, const std::string&); |
2926 | 196 |
3504 | 197 virtual void do_clean_up_and_save (const std::string&, int); |
2926 | 198 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
199 void error (int) const; |
2926 | 200 |
11500
7aeb4eb7403f
cmd-hist.h, cmd-hist.cc: sprinkle with const
John W. Eaton <jwe@octave.org>
parents:
11486
diff
changeset
|
201 void error (const std::string&) const; |
1797 | 202 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
203 // TRUE means we have initialized the history file name and number of |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
204 // lines to save. |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
205 bool initialized; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
10312
diff
changeset
|
206 |
1797 | 207 // TRUE means we are ignoring new additions. |
208 bool ignoring_additions; | |
209 | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
210 // Bitmask for history control options. See oct-rl-hist.h. |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
211 int history_control; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
212 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11368
diff
changeset
|
213 // The number of history lines we read from the history file. |
1797 | 214 int lines_in_file; |
215 | |
216 // The number of history lines we've saved so far. | |
217 int lines_this_session; | |
218 | |
219 // The default history file. | |
3504 | 220 std::string xfile; |
1797 | 221 |
222 // The number of lines of history to save. | |
223 int xsize; | |
224 }; | |
225 | |
226 #endif |