GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
data-conv.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2024 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_data_conv_h)
27 #define octave_data_conv_h 1
28 
29 #include "octave-config.h"
30 
31 #include "mach-info.h"
32 #include "oct-inttypes-fwd.h"
33 
34 class
37 {
38 public:
39 
40  enum data_type
41  {
42  dt_int8 = 0,
43  dt_uint8 = 1,
44  dt_int16 = 2,
45  dt_uint16 = 3,
46  dt_int32 = 4,
47  dt_uint32 = 5,
48  dt_int64 = 6,
49  dt_uint64 = 7,
50  dt_single = 8,
51  dt_double = 9,
52  dt_char = 10,
53  dt_schar = 11,
54  dt_uchar = 12,
55  dt_logical = 13,
56  dt_short = 14,
57  dt_ushort = 15,
58  dt_int = 16,
59  dt_uint = 17,
60  dt_long = 18,
61  dt_ulong = 19,
62  dt_longlong = 20,
63  dt_ulonglong = 21,
64  dt_float = 22,
65  dt_unknown = 23 // Must be last, have largest value!
66  };
67 
68  static std::size_t data_type_size (data_type dt);
69 
70  static data_type string_to_data_type (const std::string& s);
71 
72  static void string_to_data_type (const std::string& s, int& block_size,
73  data_type& input_type,
74  data_type& output_type);
75 
76  static void string_to_data_type (const std::string& s, int& block_size,
77  data_type& output_type);
78 
79  static std::string data_type_as_string (data_type dt);
80 };
81 
82 // Add new entries to the end of this enum, otherwise Octave will not
83 // be able to read binary data files stored in Octave's binary data
84 // format that were created with previous versions of Octave.
85 
87 {
88  LS_U_CHAR = 0,
90  LS_U_INT = 2,
91  LS_CHAR = 3,
92  LS_SHORT = 4,
93  LS_INT = 5,
94  LS_FLOAT = 6,
95  LS_DOUBLE = 7,
96  LS_U_LONG = 8,
97  LS_LONG = 9
98 };
99 
100 extern OCTAVE_API void
105 
106 extern OCTAVE_API void
111 
112 extern OCTAVE_API void
113 do_float_format_conversion (void *data, std::size_t sz, octave_idx_type len,
117 
118 extern OCTAVE_API void
119 read_doubles (std::istream& is, double *data, save_type type,
121 
122 extern OCTAVE_API void
123 write_doubles (std::ostream& os, const double *data, save_type type,
125 
126 extern OCTAVE_API void
127 read_floats (std::istream& is, float *data, save_type type,
129 
130 extern OCTAVE_API void
131 write_floats (std::ostream& os, const float *data, save_type type,
133 
134 template <typename T>
135 inline bool
137 {
138  return false;
139 }
140 
141 template <>
142 inline bool
144 {
145  return t == oct_data_conv::dt_int8;
146 }
147 
148 template <>
149 inline bool
151 {
152  return t == oct_data_conv::dt_int16;
153 }
154 
155 template <>
156 inline bool
158 {
159  return t == oct_data_conv::dt_int32;
160 }
161 
162 template <>
163 inline bool
165 {
166  return t == oct_data_conv::dt_int64;
167 }
168 
169 template <>
170 inline bool
172 {
173  return t == oct_data_conv::dt_uint8;
174 }
175 
176 template <>
177 inline bool
179 {
180  return t == oct_data_conv::dt_uint16;
181 }
182 
183 template <>
184 inline bool
186 {
187  return t == oct_data_conv::dt_uint32;
188 }
189 
190 template <>
191 inline bool
193 {
194  return t == oct_data_conv::dt_uint64;
195 }
196 
197 template <>
198 inline bool
200 {
201  return t == oct_data_conv::dt_int8;
202 }
203 
204 template <>
205 inline bool
207 {
208  return t == oct_data_conv::dt_int16;
209 }
210 
211 template <>
212 inline bool
214 {
215  return t == oct_data_conv::dt_int32;
216 }
217 
218 template <>
219 inline bool
221 {
222  return t == oct_data_conv::dt_int64;
223 }
224 
225 template <>
226 inline bool
228 {
229  return t == oct_data_conv::dt_uint8;
230 }
231 
232 template <>
233 inline bool
235 {
236  return t == oct_data_conv::dt_uint16;
237 }
238 
239 template <>
240 inline bool
242 {
243  return t == oct_data_conv::dt_uint32;
244 }
245 
246 template <>
247 inline bool
249 {
250  return t == oct_data_conv::dt_uint64;
251 }
252 
253 template <>
254 inline bool
256 {
257  return t == oct_data_conv::dt_double;
258 }
259 
260 template <>
261 inline bool
263 {
265 }
266 
267 #endif
bool is_equivalent_type< octave_uint8 >(oct_data_conv::data_type t)
Definition: data-conv.h:227
bool is_equivalent_type< float >(oct_data_conv::data_type t)
Definition: data-conv.h:262
bool is_equivalent_type< int16_t >(oct_data_conv::data_type t)
Definition: data-conv.h:150
bool is_equivalent_type< octave_int64 >(oct_data_conv::data_type t)
Definition: data-conv.h:220
bool is_equivalent_type< octave_int8 >(oct_data_conv::data_type t)
Definition: data-conv.h:199
void do_float_format_conversion(void *data, octave_idx_type len, octave::mach_info::float_format from_fmt, octave::mach_info::float_format to_fmt=octave::mach_info::native_float_format())
Definition: data-conv.cc:706
bool is_equivalent_type(oct_data_conv::data_type)
Definition: data-conv.h:136
void do_double_format_conversion(void *data, octave_idx_type len, octave::mach_info::float_format from_fmt, octave::mach_info::float_format to_fmt=octave::mach_info::native_float_format())
Definition: data-conv.cc:659
bool is_equivalent_type< double >(oct_data_conv::data_type t)
Definition: data-conv.h:255
void read_doubles(std::istream &is, double *data, save_type type, octave_idx_type len, bool swap, octave::mach_info::float_format fmt)
Definition: data-conv.cc:776
save_type
Definition: data-conv.h:87
@ LS_U_CHAR
Definition: data-conv.h:88
@ LS_DOUBLE
Definition: data-conv.h:95
@ LS_LONG
Definition: data-conv.h:97
@ LS_U_LONG
Definition: data-conv.h:96
@ LS_U_SHORT
Definition: data-conv.h:89
@ LS_FLOAT
Definition: data-conv.h:94
@ LS_SHORT
Definition: data-conv.h:92
@ LS_CHAR
Definition: data-conv.h:91
@ LS_INT
Definition: data-conv.h:93
@ LS_U_INT
Definition: data-conv.h:90
bool is_equivalent_type< uint16_t >(oct_data_conv::data_type t)
Definition: data-conv.h:178
bool is_equivalent_type< octave_uint32 >(oct_data_conv::data_type t)
Definition: data-conv.h:241
bool is_equivalent_type< octave_int16 >(oct_data_conv::data_type t)
Definition: data-conv.h:206
bool is_equivalent_type< octave_uint64 >(oct_data_conv::data_type t)
Definition: data-conv.h:248
bool is_equivalent_type< octave_int32 >(oct_data_conv::data_type t)
Definition: data-conv.h:213
void write_doubles(std::ostream &os, const double *data, save_type type, octave_idx_type len)
Definition: data-conv.cc:892
void write_floats(std::ostream &os, const float *data, save_type type, octave_idx_type len)
Definition: data-conv.cc:942
bool is_equivalent_type< int64_t >(oct_data_conv::data_type t)
Definition: data-conv.h:164
bool is_equivalent_type< int32_t >(oct_data_conv::data_type t)
Definition: data-conv.h:157
bool is_equivalent_type< octave_uint16 >(oct_data_conv::data_type t)
Definition: data-conv.h:234
bool is_equivalent_type< uint32_t >(oct_data_conv::data_type t)
Definition: data-conv.h:185
bool is_equivalent_type< uint64_t >(oct_data_conv::data_type t)
Definition: data-conv.h:192
void read_floats(std::istream &is, float *data, save_type type, octave_idx_type len, bool swap, octave::mach_info::float_format fmt)
Definition: data-conv.cc:836
bool is_equivalent_type< int8_t >(oct_data_conv::data_type t)
Definition: data-conv.h:143
bool is_equivalent_type< uint8_t >(oct_data_conv::data_type t)
Definition: data-conv.h:171
float_format native_float_format()
Definition: mach-info.cc:67
float_format
Definition: mach-info.h:38
#define OCTAVE_API
Definition: main.cc:55
F77_RET_T len
Definition: xerbla.cc:61