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