GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
load-save.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1994-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_load_save_h)
27 #define octave_load_save_h 1
28 
29 #include "octave-config.h"
30 
31 #include <iosfwd>
32 #include <string>
33 
34 #include "mach-info.h"
35 
36 #include "ovl.h"
37 
39 
40 class interpreter;
41 class load_save_format;
42 class symbol_info;
43 
45 {
46 public:
47 
48  // FIXME: maybe MAT5 and MAT7 should be options to MAT_BINARY.
49  // Similarly, save_as_floats may be an option for LS_BINARY,
50  // LS_HDF5 etc.
51 
53  {
61  UNKNOWN
62  };
63 
65  {
66  // MAT_ASCII options (not exclusive)
69  // MAT_BINARY options
72  // zero means no option.
73  NO_OPTION = 0
74  };
75 
76  OCTINTERP_API load_save_system (interpreter& interp);
77 
78  OCTINTERP_API ~load_save_system (void);
79 
81 
83 
84  OCTINTERP_API octave_value
85  crash_dumps_octave_core (const octave_value_list& args, int nargout);
86 
87  bool crash_dumps_octave_core (void) const
88  {
90  }
91 
92  bool crash_dumps_octave_core (bool flag)
93  {
94  return set (m_crash_dumps_octave_core, flag);
95  }
96 
98  int nargout);
99 
100  double octave_core_file_limit (void) const
101  {
103  }
104 
105  double octave_core_file_limit (double limit)
106  {
107  return set (m_octave_core_file_limit, limit);
108  }
109 
110  OCTINTERP_API octave_value
111  octave_core_file_name (const octave_value_list& args, int nargout);
112 
113  std::string octave_core_file_name (void) const
114  {
116  }
117 
118  std::string octave_core_file_name (const std::string& file)
119  {
120  return set (m_octave_core_file_name, file);
121  }
122 
123  OCTINTERP_API octave_value
124  save_default_options (const octave_value_list& args, int nargout);
125 
126  std::string save_default_options (void) const
127  {
128  return m_save_default_options;
129  }
130 
131  std::string save_default_options (const std::string& options)
132  {
133  return set (m_save_default_options, options);
134  }
135 
136  OCTINTERP_API octave_value
137  octave_core_file_options (const octave_value_list& args, int nargout);
138 
139  std::string octave_core_file_options (void) const
140  {
142  }
143 
144  std::string octave_core_file_options (const std::string& options)
145  {
146  return set (m_octave_core_file_options, options);
147  }
148 
149  OCTINTERP_API octave_value
150  save_header_format_string (const octave_value_list& args, int nargout);
151 
152  std::string save_header_format_string (void) const
153  {
155  }
156 
157  std::string save_header_format_string (const std::string& format)
158  {
160  }
161 
162  static OCTINTERP_API load_save_format
163  get_file_format (const std::string& fname, const std::string& orig_fname,
164  bool& use_zlib, bool quiet = false);
165 
166  // FIXME: this is probably not the best public interface for
167  // loading and saving variables, but it is what is currently
168  // needed for the Fload and Fsave functions.
169 
170  OCTINTERP_API octave_value
171  load_vars (std::istream& stream, const std::string& orig_fname,
172  const load_save_format& fmt, mach_info::float_format flt_fmt,
173  bool list_only, bool swap, bool verbose,
174  const string_vector& argv, int argv_idx, int argc, int nargout);
175 
176  static OCTINTERP_API string_vector
178  bool& append, bool& save_as_floats, bool& use_zlib);
179 
180  static OCTINTERP_API string_vector
181  parse_save_options (const std::string& arg, load_save_format& fmt,
182  bool& append, bool& save_as_floats, bool& use_zlib);
183 
184  OCTINTERP_API void
185  save_vars (const string_vector& argv, int argv_idx, int argc,
186  std::ostream& os, const load_save_format& fmt,
187  bool save_as_floats, bool write_header_info);
188 
189  OCTINTERP_API void dump_octave_core (void);
190 
191  OCTINTERP_API octave_value_list
192  load (const octave_value_list& args = octave_value_list (),
193  int nargout = 0);
194 
195  OCTINTERP_API octave_value_list
196  save (const octave_value_list& args = octave_value_list (),
197  int nargout = 0);
198 
199 private:
200 
202 
203  // Write octave-workspace file if Octave crashes or is killed by a
204  // signal.
206 
207  // The maximum amount of memory (in kilobytes) that we will
208  // attempt to write to the Octave core file.
210 
211  // The name of the Octave core file.
213 
214  // The default output format. May be one of "binary", "text",
215  // "mat-binary", or "hdf5".
217 
218  // The output format for Octave core files.
220 
221  // The format string for the comment line at the top of
222  // text-format save files. Passed to strftime. Should begin with
223  // '#' and contain no newline characters.
225 
226  OCTINTERP_API void
227  write_header (std::ostream& os, const load_save_format& fmt);
228 
229  OCTINTERP_API std::size_t
230  save_vars (std::ostream& os, const std::string& pattern,
231  const load_save_format& fmt, bool save_as_floats);
232 
233  OCTINTERP_API void
234  do_save (std::ostream& os, const octave_value& tc, const std::string& name,
235  const std::string& help, bool global, const load_save_format& fmt,
236  bool save_as_floats);
237 
238  OCTINTERP_API void
239  do_save (std::ostream& os, const symbol_info& syminfo,
240  const load_save_format& fmt, bool save_as_floats);
241 
242  OCTINTERP_API std::size_t
243  save_fields (std::ostream& os, const octave_scalar_map& m,
244  const std::string& pattern, const load_save_format& fmt,
245  bool save_as_floats);
246 
247  OCTINTERP_API void
248  dump_octave_core (std::ostream& os, const char *fname,
249  const load_save_format& fmt, bool save_as_floats);
250 
251  OCTINTERP_API void
252  install_loaded_variable (const std::string& name, const octave_value& val,
253  bool global, const std::string& /*doc*/);
254 
255  static OCTINTERP_API std::string init_save_header_format (void);
256 
257  static OCTINTERP_API load_save_format
258  get_file_format (std::istream& file, const std::string& filename);
259 
260  template <typename T>
261  T set (T& var, const T& new_val)
262  {
263  T old_val = var;
264  var = new_val;
265  return old_val;
266  }
267 };
268 
270 {
271 public:
272 
276  { }
277 
279 
280  load_save_system::format_type type (void) const { return m_type; }
281 
283  {
284  m_options |= option;
285  }
286 
287  int options (void) const { return m_options; }
288 
289 private:
290 
293 };
294 
296 
297 OCTAVE_DEPRECATED (7, "use 'load_save_system::dump_octave_core' instead")
298 extern OCTINTERP_API void dump_octave_core (void);
299 
300 #endif
OCTAVE_END_NAMESPACE(octave)
load_save_system::format_type type(void) const
Definition: load-save.h:280
void set_option(load_save_system::format_options option)
Definition: load-save.h:282
load_save_format(load_save_system::format_type type, load_save_system::format_options options=load_save_system::NO_OPTION)
Definition: load-save.h:273
void set_type(load_save_system::format_type type)
Definition: load-save.h:278
int options(void) const
Definition: load-save.h:287
load_save_system::format_type m_type
Definition: load-save.h:291
std::string m_save_header_format_string
Definition: load-save.h:224
double m_octave_core_file_limit
Definition: load-save.h:209
std::string save_header_format_string(void) const
Definition: load-save.h:152
OCTINTERP_API octave_value_list save(const octave_value_list &args=octave_value_list(), int nargout=0)
Definition: load-save.cc:1404
std::string m_octave_core_file_name
Definition: load-save.h:212
OCTINTERP_API void save_vars(const string_vector &argv, int argv_idx, int argc, std::ostream &os, const load_save_format &fmt, bool save_as_floats, bool write_header_info)
Definition: load-save.cc:676
OCTINTERP_API ~load_save_system(void)
Definition: load-save.cc:271
interpreter & m_interpreter
Definition: load-save.h:201
OCTINTERP_API std::size_t save_fields(std::ostream &os, const octave_scalar_map &m, const std::string &pattern, const load_save_format &fmt, bool save_as_floats)
Definition: load-save.cc:1003
OCTINTERP_API void write_header(std::ostream &os, const load_save_format &fmt)
Definition: load-save.cc:828
std::string octave_core_file_name(const std::string &file)
Definition: load-save.h:118
std::string octave_core_file_options(void) const
Definition: load-save.h:139
std::string octave_core_file_name(void) const
Definition: load-save.h:113
OCTINTERP_API octave_value load_vars(std::istream &stream, const std::string &orig_fname, const load_save_format &fmt, mach_info::float_format flt_fmt, bool list_only, bool swap, bool verbose, const string_vector &argv, int argv_idx, int argc, int nargout)
Definition: load-save.cc:381
std::string m_save_default_options
Definition: load-save.h:216
bool crash_dumps_octave_core(void) const
Definition: load-save.h:87
OCTINTERP_API void install_loaded_variable(const std::string &name, const octave_value &val, bool global, const std::string &)
Definition: load-save.cc:1069
bool crash_dumps_octave_core(bool flag)
Definition: load-save.h:92
load_save_system & operator=(const load_save_system &)=delete
OCTINTERP_API octave_value_list load(const octave_value_list &args=octave_value_list(), int nargout=0)
Definition: load-save.cc:1160
static OCTINTERP_API load_save_format get_file_format(const std::string &fname, const std::string &orig_fname, bool &use_zlib, bool quiet=false)
Definition: load-save.cc:327
static OCTINTERP_API std::string init_save_header_format(void)
Definition: load-save.cc:1077
double octave_core_file_limit(double limit)
Definition: load-save.h:105
std::string octave_core_file_options(const std::string &options)
Definition: load-save.h:144
OCTINTERP_API load_save_system(interpreter &interp)
Definition: load-save.cc:257
load_save_system(const load_save_system &)=delete
double octave_core_file_limit(void) const
Definition: load-save.h:100
OCTINTERP_API void do_save(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &help, bool global, const load_save_format &fmt, bool save_as_floats)
Definition: load-save.cc:934
bool m_crash_dumps_octave_core
Definition: load-save.h:205
std::string m_octave_core_file_options
Definition: load-save.h:219
std::string save_header_format_string(const std::string &format)
Definition: load-save.h:157
std::string save_default_options(const std::string &options)
Definition: load-save.h:131
OCTINTERP_API void dump_octave_core(void)
Definition: load-save.cc:735
T set(T &var, const T &new_val)
Definition: load-save.h:261
std::string save_default_options(void) const
Definition: load-save.h:126
static OCTINTERP_API string_vector parse_save_options(const string_vector &argv, load_save_format &fmt, bool &append, bool &save_as_floats, bool &use_zlib)
Definition: load-save.cc:532
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API void dump_octave_core(void)
Definition: load-save.cc:2067
float_format
Definition: mach-info.h:38
T octave_idx_type m
Definition: mx-inlines.cc:773
std::size_t format(std::ostream &os, const char *fmt,...)
Definition: utils.cc:1473