GNU Octave 7.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-2022 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
34class
37{
38public:
39
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{
93 LS_INT = 5,
97 LS_LONG = 9
98};
99
100extern OCTAVE_API void
105
106extern OCTAVE_API void
111
112extern OCTAVE_API void
113do_float_format_conversion (void *data, std::size_t sz, octave_idx_type len,
117
118extern OCTAVE_API void
119read_doubles (std::istream& is, double *data, save_type type,
121
122extern OCTAVE_API void
123write_doubles (std::ostream& os, const double *data, save_type type,
125
126extern OCTAVE_API void
127read_floats (std::istream& is, float *data, save_type type,
129
130extern OCTAVE_API void
131write_floats (std::ostream& os, const float *data, save_type type,
133
134template <typename T>
135inline bool
137{
138 return false;
139}
140
141template <>
142inline bool
144{
145 return t == oct_data_conv::dt_int8;
146}
147
148template <>
149inline bool
151{
152 return t == oct_data_conv::dt_int16;
153}
154
155template <>
156inline bool
158{
159 return t == oct_data_conv::dt_int32;
160}
161
162template <>
163inline bool
165{
166 return t == oct_data_conv::dt_int64;
167}
168
169template <>
170inline bool
172{
173 return t == oct_data_conv::dt_uint8;
174}
175
176template <>
177inline bool
179{
180 return t == oct_data_conv::dt_uint16;
181}
182
183template <>
184inline bool
186{
187 return t == oct_data_conv::dt_uint32;
188}
189
190template <>
191inline bool
193{
194 return t == oct_data_conv::dt_uint64;
195}
196
197template <>
198inline bool
200{
201 return t == oct_data_conv::dt_int8;
202}
203
204template <>
205inline bool
207{
208 return t == oct_data_conv::dt_int16;
209}
210
211template <>
212inline bool
214{
215 return t == oct_data_conv::dt_int32;
216}
217
218template <>
219inline bool
221{
222 return t == oct_data_conv::dt_int64;
223}
224
225template <>
226inline bool
228{
229 return t == oct_data_conv::dt_uint8;
230}
231
232template <>
233inline bool
235{
236 return t == oct_data_conv::dt_uint16;
237}
238
239template <>
240inline bool
242{
243 return t == oct_data_conv::dt_uint32;
244}
245
246template <>
247inline bool
249{
250 return t == oct_data_conv::dt_uint64;
251}
252
253template <>
254inline bool
256{
257 return t == oct_data_conv::dt_double;
258}
259
260template <>
261inline bool
263{
265}
266
267#endif
bool is_equivalent_type< octave_uint8 >(oct_data_conv::data_type t)
Definition: data-conv.h:227
OCTAVE_API void write_floats(std::ostream &os, const float *data, save_type type, octave_idx_type len)
Definition: data-conv.cc:942
OCTAVE_API 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< 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
bool is_equivalent_type(oct_data_conv::data_type)
Definition: data-conv.h:136
OCTAVE_API 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
bool is_equivalent_type< double >(oct_data_conv::data_type t)
Definition: data-conv.h:255
OCTAVE_API 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
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
OCTAVE_API 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< 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
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
OCTAVE_API void write_doubles(std::ostream &os, const double *data, save_type type, octave_idx_type len)
Definition: data-conv.cc:892
#define OCTAVE_API
Definition: main.in.cc:55
float_format native_float_format(void)
Definition: mach-info.cc:65
F77_RET_T len
Definition: xerbla.cc:61