GNU Octave  6.2.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-2021 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 
38 namespace octave
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  load_save_system (interpreter& interp);
77 
78  ~load_save_system (void);
79 
81 
83 
85  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 
111  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 
124  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 
137  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 
150  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 load_save_format get_file_format (const std::string& fname,
163  const std::string& orig_fname,
164  bool& use_zlib,
165  bool quiet = false);
166 
167  // FIXME: this is probably not the best public interface for
168  // loading and saving variables, but it is what is currently
169  // needed for the Fload and Fsave functions.
170 
171  octave_value load_vars (std::istream& stream,
172  const std::string& orig_fname,
173  const load_save_format& fmt,
174  mach_info::float_format flt_fmt,
175  bool list_only, bool swap, bool verbose,
176  const string_vector& argv, int argv_idx,
177  int argc, int nargout);
178 
179  static string_vector
181  bool& append, bool& save_as_floats, bool& use_zlib);
182 
183  static string_vector
184  parse_save_options (const std::string& arg, load_save_format& fmt,
185  bool& append, bool& save_as_floats, bool& use_zlib);
186 
187  void save_vars (const string_vector& argv, int argv_idx, int argc,
188  std::ostream& os, const load_save_format& fmt,
189  bool save_as_floats, bool write_header_info);
190 
191  void dump_octave_core (void);
192 
194  load (const octave_value_list& args = octave_value_list (),
195  int nargout = 0);
196 
198  save (const octave_value_list& args = octave_value_list (),
199  int nargout = 0);
200 
201  private:
202 
204 
205  // Write octave-workspace file if Octave crashes or is killed by a
206  // signal.
208 
209  // The maximum amount of memory (in kilobytes) that we will
210  // attempt to write to the Octave core file.
212 
213  // The name of the Octave core file.
215 
216  // The default output format. May be one of "binary", "text",
217  // "mat-binary", or "hdf5".
219 
220  // The output format for Octave core files.
222 
223  // The format string for the comment line at the top of
224  // text-format save files. Passed to strftime. Should begin with
225  // '#' and contain no newline characters.
227 
228  void write_header (std::ostream& os, const load_save_format& fmt);
229 
230  size_t save_vars (std::ostream& os, const std::string& pattern,
231  const load_save_format& fmt, bool save_as_floats);
232 
233  void do_save (std::ostream& os, const octave_value& tc,
234  const std::string& name, const std::string& help,
235  bool global, const load_save_format& fmt,
236  bool save_as_floats);
237 
238  void do_save (std::ostream& os, const symbol_info& syminfo,
239  const load_save_format& fmt, bool save_as_floats);
240 
241  size_t save_fields (std::ostream& os, const octave_scalar_map& m,
242  const std::string& pattern,
243  const load_save_format& fmt, bool save_as_floats);
244 
245  void dump_octave_core (std::ostream& os, const char *fname,
246  const load_save_format& fmt, bool save_as_floats);
247 
248  void install_loaded_variable (const std::string& name,
249  const octave_value& val,
250  bool global, const std::string& /*doc*/);
251 
252  static std::string init_save_header_format (void);
253 
254  static load_save_format get_file_format (std::istream& file,
255  const std::string& filename);
256 
257  template <typename T>
258  T set (T& var, const T& new_val)
259  {
260  T old_val = var;
261  var = new_val;
262  return old_val;
263  }
264  };
265 
267  {
268  public:
269 
273  { }
274 
276 
277  load_save_system::format_type type (void) const { return m_type; }
278 
280  {
281  m_options |= option;
282  }
283 
284  int options (void) const { return m_options; }
285 
286  private:
287 
290  };
291 }
292 
293 extern void dump_octave_core (void);
294 
295 #endif
load_save_system::format_type type(void) const
Definition: load-save.h:277
load_save_system::format_type m_type
Definition: load-save.h:288
void set_option(load_save_system::format_options option)
Definition: load-save.h:279
void set_type(load_save_system::format_type type)
Definition: load-save.h:275
load_save_format(load_save_system::format_type type, load_save_system::format_options options=load_save_system::NO_OPTION)
Definition: load-save.h:270
int options(void) const
Definition: load-save.h:284
void write_header(std::ostream &os, const load_save_format &fmt)
Definition: load-save.cc:822
std::string m_octave_core_file_name
Definition: load-save.h:214
bool crash_dumps_octave_core(bool flag)
Definition: load-save.h:92
octave_value_list load(const octave_value_list &args=octave_value_list(), int nargout=0)
Definition: load-save.cc:1153
static 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:329
load_save_system(const load_save_system &)=delete
load_save_system & operator=(const load_save_system &)=delete
double octave_core_file_limit(double limit)
Definition: load-save.h:105
std::string save_default_options(void) const
Definition: load-save.h:126
std::string octave_core_file_options(void) const
Definition: load-save.h:139
std::string save_header_format_string(void) const
Definition: load-save.h:152
void dump_octave_core(void)
Definition: load-save.cc:729
std::string octave_core_file_options(const std::string &options)
Definition: load-save.h:144
std::string octave_core_file_name(void) const
Definition: load-save.h:113
std::string octave_core_file_name(const std::string &file)
Definition: load-save.h:118
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:927
std::string save_default_options(const std::string &options)
Definition: load-save.h:131
void install_loaded_variable(const std::string &name, const octave_value &val, bool global, const std::string &)
Definition: load-save.cc:1062
static 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:530
std::string m_save_header_format_string
Definition: load-save.h:226
std::string save_header_format_string(const std::string &format)
Definition: load-save.h:157
double octave_core_file_limit(void) const
Definition: load-save.h:100
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:379
static std::string init_save_header_format(void)
Definition: load-save.cc:1070
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:670
interpreter & m_interpreter
Definition: load-save.h:203
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:996
bool crash_dumps_octave_core(void) const
Definition: load-save.h:87
std::string m_save_default_options
Definition: load-save.h:218
T set(T &var, const T &new_val)
Definition: load-save.h:258
octave_value_list save(const octave_value_list &args=octave_value_list(), int nargout=0)
Definition: load-save.cc:1397
load_save_system(interpreter &interp)
Definition: load-save.cc:259
std::string m_octave_core_file_options
Definition: load-save.h:221
QString name
void dump_octave_core(void)
Definition: load-save.cc:1540
T octave_idx_type m
Definition: mx-inlines.cc:773
size_t format(std::ostream &os, const char *fmt,...)
Definition: utils.cc:1329