4634
|
1 /* |
|
2 |
|
3 Copyright (C) 2003 John W. Eaton |
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_ls_hdf5_h) |
|
24 #define octave_ls_hdf5_h 1 |
|
25 |
|
26 // first, we need to define our own dummy stream subclass, since |
|
27 // HDF5 needs to do its own file i/o |
|
28 |
|
29 // hdf5_fstreambase is used for both input and output streams, modeled |
|
30 // on the fstreambase class in <fstream.h> |
|
31 |
|
32 class hdf5_fstreambase : virtual public std::ios |
|
33 { |
|
34 public: |
|
35 |
|
36 // HDF5 uses an "id" to refer to an open file |
|
37 hid_t file_id; |
|
38 |
|
39 // keep track of current item index in the file |
|
40 int current_item; |
|
41 |
|
42 hdf5_fstreambase () { file_id = -1; } |
|
43 |
4663
|
44 hdf5_fstreambase (const char *name, int mode, int /* prot */ = 0) |
4634
|
45 { |
|
46 if (mode == std::ios::in) |
|
47 file_id = H5Fopen (name, H5F_ACC_RDONLY, H5P_DEFAULT); |
|
48 else if (mode == std::ios::out) |
|
49 file_id = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); |
|
50 |
|
51 if (file_id < 0) |
|
52 std::ios::setstate (std::ios::badbit); |
|
53 |
|
54 current_item = 0; |
|
55 } |
|
56 |
|
57 void close () |
|
58 { |
|
59 if (file_id >= 0) |
|
60 { |
|
61 if (H5Fclose (file_id) < 0) |
|
62 std::ios::setstate (std::ios::badbit); |
|
63 file_id = -1; |
|
64 } |
|
65 } |
|
66 |
|
67 void open (const char *name, int mode, int prot = 0) |
|
68 { |
|
69 clear (); |
|
70 |
|
71 if (mode == std::ios::in) |
|
72 file_id = H5Fopen (name, H5F_ACC_RDONLY, H5P_DEFAULT); |
|
73 else if (mode == std::ios::out) |
|
74 file_id = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); |
|
75 |
|
76 if (file_id < 0) |
|
77 std::ios::setstate (std::ios::badbit); |
|
78 |
|
79 current_item = 0; |
|
80 } |
|
81 }; |
|
82 |
|
83 // input and output streams, subclassing istream and ostream |
|
84 // so that we can pass them for stream parameters in the functions below. |
|
85 |
|
86 class hdf5_ifstream : public hdf5_fstreambase, public std::istream |
|
87 { |
|
88 public: |
|
89 |
|
90 hdf5_ifstream () : hdf5_fstreambase (), std::istream (0) { } |
|
91 |
|
92 hdf5_ifstream (const char *name, int mode = std::ios::in, int prot = 0) |
|
93 : hdf5_fstreambase (name, mode, prot), std::istream (0) { } |
|
94 |
|
95 void open (const char *name, int mode = std::ios::in, int prot = 0) |
|
96 { hdf5_fstreambase::open (name, mode, prot); } |
|
97 }; |
|
98 |
|
99 class hdf5_ofstream : public hdf5_fstreambase, public std::ostream |
|
100 { |
|
101 public: |
|
102 |
|
103 hdf5_ofstream () : hdf5_fstreambase (), std::ostream (0) { } |
|
104 |
|
105 hdf5_ofstream (const char *name, int mode = std::ios::out, int prot = 0) |
|
106 : hdf5_fstreambase (name, mode, prot), std::ostream (0) { } |
|
107 |
|
108 void open (const char *name, int mode = std::ios::out, int prot = 0) |
|
109 { hdf5_fstreambase::open (name, mode, prot); } |
|
110 }; |
|
111 |
|
112 extern std::string |
|
113 read_hdf5_data (std::istream& is, |
|
114 const std::string& filename, bool& global, |
|
115 octave_value& tc, std::string& doc, bool import); |
|
116 |
|
117 extern bool |
|
118 save_hdf5_data (std::ostream& os, const octave_value& tc, |
|
119 const std::string& name, const std::string& doc, |
|
120 bool mark_as_global, bool save_as_floats); |
|
121 |
|
122 #endif |
|
123 |
|
124 /* |
|
125 ;;; Local Variables: *** |
|
126 ;;; mode: C++ *** |
|
127 ;;; End: *** |
|
128 */ |