GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
data-conv.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_data_conv_h)
24 #define octave_data_conv_h 1
25 
26 #include "octave-config.h"
27 
28 #include <limits>
29 
30 #include "mach-info.h"
31 #include "oct-inttypes-fwd.h"
32 
33 class
34 OCTAVE_API
36 {
37 public:
38 
39  enum data_type
40  {
41  dt_int8 = 0,
42  dt_uint8 = 1,
43  dt_int16 = 2,
44  dt_uint16 = 3,
45  dt_int32 = 4,
46  dt_uint32 = 5,
47  dt_int64 = 6,
48  dt_uint64 = 7,
49  dt_single = 8,
50  dt_double = 9,
51  dt_char = 10,
52  dt_schar = 11,
53  dt_uchar = 12,
54  dt_logical = 13,
55  dt_short = 14,
56  dt_ushort = 15,
57  dt_int = 16,
58  dt_uint = 17,
59  dt_long = 18,
60  dt_ulong = 19,
61  dt_longlong = 20,
62  dt_ulonglong = 21,
63  dt_float = 22,
64  dt_unknown = 23 // Must be last, have largest value!
65  };
66 
67  static size_t data_type_size (data_type dt);
68 
69  static data_type string_to_data_type (const std::string& s);
70 
71  static void string_to_data_type (const std::string& s, int& block_size,
72  data_type& input_type,
73  data_type& output_type);
74 
75  static void string_to_data_type (const std::string& s, int& block_size,
76  data_type& output_type);
77 
78  static std::string data_type_as_string (data_type dt);
79 };
80 
81 // Add new entries to the end of this enum, otherwise Octave will not
82 // be able to read binary data files stored in Octave's binary data
83 // format that were created with previous versions of Octave.
84 
86 {
87  LS_U_CHAR = 0,
89  LS_U_INT = 2,
90  LS_CHAR = 3,
91  LS_SHORT = 4,
92  LS_INT = 5,
93  LS_FLOAT = 6,
94  LS_DOUBLE = 7,
95  LS_U_LONG = 8,
96  LS_LONG = 9
97 };
98 
99 extern OCTAVE_API void
104 
105 extern OCTAVE_API void
110 
111 extern OCTAVE_API void
112 do_float_format_conversion (void *data, size_t sz, octave_idx_type len,
116 
117 extern OCTAVE_API void
118 read_doubles (std::istream& is, double *data, save_type type,
120 
121 extern OCTAVE_API void
122 write_doubles (std::ostream& os, const double *data, save_type type,
123  octave_idx_type len);
124 
125 extern OCTAVE_API void
126 read_floats (std::istream& is, float *data, save_type type,
128 
129 extern OCTAVE_API void
130 write_floats (std::ostream& os, const float *data, save_type type,
131  octave_idx_type len);
132 
133 template <typename T>
134 inline bool
136 {
137  return false;
138 }
139 
140 template <>
141 inline bool
143 {
144  return t == oct_data_conv::dt_int8;
145 }
146 
147 template <>
148 inline bool
150 {
151  return t == oct_data_conv::dt_int16;
152 }
153 
154 template <>
155 inline bool
157 {
158  return t == oct_data_conv::dt_int32;
159 }
160 
161 template <>
162 inline bool
164 {
165  return t == oct_data_conv::dt_int64;
166 }
167 
168 template <>
169 inline bool
171 {
172  return t == oct_data_conv::dt_uint8;
173 }
174 
175 template <>
176 inline bool
178 {
179  return t == oct_data_conv::dt_uint16;
180 }
181 
182 template <>
183 inline bool
185 {
186  return t == oct_data_conv::dt_uint32;
187 }
188 
189 template <>
190 inline bool
192 {
193  return t == oct_data_conv::dt_uint64;
194 }
195 
196 template <>
197 inline bool
199 {
200  return t == oct_data_conv::dt_int8;
201 }
202 
203 template <>
204 inline bool
206 {
207  return t == oct_data_conv::dt_int16;
208 }
209 
210 template <>
211 inline bool
213 {
214  return t == oct_data_conv::dt_int32;
215 }
216 
217 template <>
218 inline bool
220 {
221  return t == oct_data_conv::dt_int64;
222 }
223 
224 template <>
225 inline bool
227 {
228  return t == oct_data_conv::dt_uint8;
229 }
230 
231 template <>
232 inline bool
234 {
235  return t == oct_data_conv::dt_uint16;
236 }
237 
238 template <>
239 inline bool
241 {
242  return t == oct_data_conv::dt_uint32;
243 }
244 
245 template <>
246 inline bool
248 {
249  return t == oct_data_conv::dt_uint64;
250 }
251 
252 template <>
253 inline bool
255 {
256  return t == oct_data_conv::dt_double;
257 }
258 
259 template <>
260 inline bool
262 {
264 }
265 
266 #endif
save_type
Definition: data-conv.h:85
bool is_equivalent_type< int64_t >(oct_data_conv::data_type t)
Definition: data-conv.h:163
bool is_equivalent_type(oct_data_conv::data_type)
Definition: data-conv.h:135
bool is_equivalent_type< octave_int32 >(oct_data_conv::data_type t)
Definition: data-conv.h:212
bool is_equivalent_type< int8_t >(oct_data_conv::data_type t)
Definition: data-conv.h:142
bool is_equivalent_type< octave_int16 >(oct_data_conv::data_type t)
Definition: data-conv.h:205
bool is_equivalent_type< int16_t >(oct_data_conv::data_type t)
Definition: data-conv.h:149
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:935
s
Definition: file-io.cc:2682
OCTAVE_API void write_floats(std::ostream &os, const float *data, save_type type, octave_idx_type len)
Definition: data-conv.cc:936
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:701
bool is_equivalent_type< uint8_t >(oct_data_conv::data_type t)
Definition: data-conv.h:170
bool swap
Definition: load-save.cc:725
bool is_equivalent_type< octave_uint32 >(oct_data_conv::data_type t)
Definition: data-conv.h:240
bool is_equivalent_type< float >(oct_data_conv::data_type t)
Definition: data-conv.h:261
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:771
bool is_equivalent_type< uint64_t >(oct_data_conv::data_type t)
Definition: data-conv.h:191
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:654
bool is_equivalent_type< int32_t >(oct_data_conv::data_type t)
Definition: data-conv.h:156
bool is_equivalent_type< octave_int8 >(oct_data_conv::data_type t)
Definition: data-conv.h:198
idx type
Definition: ov.cc:3129
sz
Definition: data.cc:5342
bool is_equivalent_type< octave_int64 >(oct_data_conv::data_type t)
Definition: data-conv.h:219
OCTAVE_API void write_doubles(std::ostream &os, const double *data, save_type type, octave_idx_type len)
Definition: data-conv.cc:886
static float_format native_float_format(void)
Definition: mach-info.cc:162
bool is_equivalent_type< octave_uint64 >(oct_data_conv::data_type t)
Definition: data-conv.h:247
bool is_equivalent_type< double >(oct_data_conv::data_type t)
Definition: data-conv.h:254
bool is_equivalent_type< uint16_t >(oct_data_conv::data_type t)
Definition: data-conv.h:177
write the output to stdout if nargout is
Definition: load-save.cc:1576
bool is_equivalent_type< octave_uint16 >(oct_data_conv::data_type t)
Definition: data-conv.h:233
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:830
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
bool is_equivalent_type< octave_uint8 >(oct_data_conv::data_type t)
Definition: data-conv.h:226
bool is_equivalent_type< uint32_t >(oct_data_conv::data_type t)
Definition: data-conv.h:184