GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
ls-hdf5.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2003-2025 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_ls_hdf5_h)
27#define octave_ls_hdf5_h 1
28
29#include "octave-config.h"
30
31#include <iosfwd>
32
33#include "oct-hdf5-types.h"
34#include "ov.h"
35
36// first, we need to define our own dummy stream subclass, since
37// HDF5 needs to do its own file i/o
38
39// hdf5_fstreambase is used for both input and output streams, modeled
40// on the fstreambase class in <fstream.h>
41
42class hdf5_fstreambase : virtual public std::ios
43{
44public:
45
46 // HDF5 uses an "id" to refer to an open file
48
49 // keep track of current item index in the file
51
53
54 OCTAVE_DISABLE_COPY_MOVE (hdf5_fstreambase)
55
57
58 OCTINTERP_API hdf5_fstreambase (const char *name, int mode,
59 int /* prot */ = 0);
60
61 OCTINTERP_API void close ();
62
63 OCTINTERP_API void open (const char *name, int mode, int);
64
65 OCTINTERP_API void open_create (const char *name, int mode);
66};
67
68// input and output streams, subclassing istream and ostream
69// so that we can pass them for stream parameters in the functions below.
70
71class hdf5_ifstream : public hdf5_fstreambase, public std::istream
72{
73public:
74
75 hdf5_ifstream () : hdf5_fstreambase (), std::istream (nullptr) { }
76
77 hdf5_ifstream (const char *name, int mode = std::ios::in | std::ios::binary,
78 int prot = 0)
79 : hdf5_fstreambase (name, mode, prot), std::istream (nullptr) { }
80
81 void open (const char *name, int mode = std::ios::in | std::ios::binary,
82 int prot = 0)
83 { hdf5_fstreambase::open (name, mode, prot); }
84};
85
86class hdf5_ofstream : public hdf5_fstreambase, public std::ostream
87{
88public:
89
90 hdf5_ofstream () : hdf5_fstreambase (), std::ostream (nullptr) { }
91
92 hdf5_ofstream (const char *name, int mode = std::ios::out | std::ios::binary,
93 int prot = 0)
94 : hdf5_fstreambase (name, mode, prot), std::ostream (nullptr) { }
95
96 void open (const char *name, int mode = std::ios::out | std::ios::binary,
97 int prot = 0)
98 { hdf5_fstreambase::open (name, mode, prot); }
99};
100
101// Callback data structure for passing data to hdf5_read_next_data, below.
102
104{
105public:
106
108 : name (), global (false), tc (), doc () { }
109
110 OCTAVE_DEFAULT_COPY_MOVE_DELETE (hdf5_callback_data)
111
112 // the following fields are set by hdf5_read_data on successful return:
113
114 // the name of the variable
115 std::string name;
116
117 // whether it is global
118 bool global;
119
120 // the value of the variable, in Octave form
122
123 // a documentation string (NULL if none)
124 std::string doc;
125};
126
127extern OCTINTERP_API octave_hdf5_id
129
130extern OCTINTERP_API octave_hdf5_id
132
133extern OCTINTERP_API bool
135
136extern OCTINTERP_API octave_hdf5_err
137hdf5_read_next_data (octave_hdf5_id group_id, const char *name, void *dv);
138
139extern OCTINTERP_API octave_hdf5_err
140hdf5_h5g_iterate (octave_hdf5_id loc_id, const char *name, int *idx,
141 void *operator_data);
142
143extern OCTINTERP_API bool
145 const std::string& name, const std::string& doc,
146 bool mark_global, bool save_as_floats);
147
148extern OCTINTERP_API int
149save_hdf5_empty (octave_hdf5_id loc_id, const char *name, const dim_vector& d);
150
151extern OCTINTERP_API int
152load_hdf5_empty (octave_hdf5_id loc_id, const char *name, dim_vector& d);
153
154extern OCTINTERP_API std::string
155read_hdf5_data (std::istream& is, const std::string& filename, bool& global,
156 octave_value& tc, std::string& doc,
157 const string_vector& argv, int argv_idx, int argc);
158
159extern OCTINTERP_API bool
160save_hdf5_data (std::ostream& os, const octave_value& tc,
161 const std::string& name, const std::string& doc,
162 bool mark_global, bool save_as_floats);
163
164extern OCTINTERP_API bool
165hdf5_check_attr (octave_hdf5_id loc_id, const char *attr_name);
166
167extern OCTINTERP_API bool
169 const char *attr_name, void *buf);
170
171extern OCTINTERP_API octave_hdf5_err
172hdf5_add_attr (octave_hdf5_id loc_id, const char *attr_name);
173
174
175extern OCTINTERP_API octave_hdf5_err
177 const char *attr_name, void *buf);
178
179#endif
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:90
void open(const char *name, int mode, int)
Definition ls-hdf5.cc:130
void open_create(const char *name, int mode)
Definition ls-hdf5.cc:148
octave_hdf5_id file_id
Definition ls-hdf5.h:47
void open(const char *name, int mode=std::ios::in|std::ios::binary, int prot=0)
Definition ls-hdf5.h:81
hdf5_ifstream(const char *name, int mode=std::ios::in|std::ios::binary, int prot=0)
Definition ls-hdf5.h:77
void open(const char *name, int mode=std::ios::out|std::ios::binary, int prot=0)
Definition ls-hdf5.h:96
hdf5_ofstream(const char *name, int mode=std::ios::out|std::ios::binary, int prot=0)
Definition ls-hdf5.h:92
save_type
Definition data-conv.h:85
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
bool save_hdf5_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
Definition ls-hdf5.cc:1507
int save_hdf5_empty(octave_hdf5_id loc_id, const char *name, const dim_vector &d)
Definition ls-hdf5.cc:1254
octave_hdf5_err hdf5_add_attr(octave_hdf5_id loc_id, const char *attr_name)
Definition ls-hdf5.cc:1169
bool hdf5_get_scalar_attr(octave_hdf5_id loc_id, octave_hdf5_id type_id, const char *attr_name, void *buf)
Definition ls-hdf5.cc:352
int load_hdf5_empty(octave_hdf5_id loc_id, const char *name, dim_vector &d)
Definition ls-hdf5.cc:1311
std::string read_hdf5_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, std::string &doc, const string_vector &argv, int argv_idx, int argc)
Definition ls-hdf5.cc:1084
octave_hdf5_id save_type_to_hdf5(save_type st)
Definition ls-hdf5.cc:1355
octave_hdf5_id hdf5_make_complex_type(octave_hdf5_id num_type)
Definition ls-hdf5.cc:410
octave_hdf5_err hdf5_read_next_data(octave_hdf5_id group_id, const char *name, void *dv)
Definition ls-hdf5.cc:1050
octave_hdf5_err hdf5_h5g_iterate(octave_hdf5_id loc_id, const char *name, int *idx, void *operator_data)
Definition ls-hdf5.cc:1064
bool hdf5_types_compatible(octave_hdf5_id t1, octave_hdf5_id t2)
Definition ls-hdf5.cc:274
octave_hdf5_err hdf5_add_scalar_attr(octave_hdf5_id loc_id, octave_hdf5_id type_id, const char *attr_name, void *buf)
Definition ls-hdf5.cc:1210
bool add_hdf5_data(octave_hdf5_id loc_id, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
Definition ls-hdf5.cc:1411
bool hdf5_check_attr(octave_hdf5_id loc_id, const char *attr_name)
Definition ls-hdf5.cc:305
int64_t octave_hdf5_id
octave_value tc
Definition ls-hdf5.h:121
std::string name
Definition ls-hdf5.h:115
std::string doc
Definition ls-hdf5.h:124