1960
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1960
|
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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1960
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_data_conv_h) |
|
25 #define octave_data_conv_h 1 |
|
26 |
|
27 #include <climits> |
|
28 |
2317
|
29 #include "mach-info.h" |
1960
|
30 |
|
31 // Not all of the following are currently used. |
|
32 |
|
33 #if CHAR_BIT != 8 |
|
34 #error "CHAR_BIT is not 8!" |
|
35 #endif |
|
36 |
|
37 #if SIZEOF_SHORT == 2 |
|
38 #define TWO_BYTE_INT short |
|
39 #elif SIZEOF_INT == 2 |
|
40 #define TWO_BYTE_INT int |
|
41 #else |
|
42 #error "No 2 byte integer type found!" |
|
43 #endif |
|
44 |
|
45 #if SIZEOF_INT == 4 |
|
46 #define FOUR_BYTE_INT int |
|
47 #elif SIZEOF_LONG == 4 |
|
48 #define FOUR_BYTE_INT long |
|
49 #else |
|
50 #error "No 4 byte integer type found!" |
|
51 #endif |
|
52 |
3688
|
53 #if SIZEOF_LONG == 8 |
|
54 #define EIGHT_BYTE_INT long |
|
55 #else |
|
56 #if SIZEOF_LONG_LONG == 8 |
|
57 // if `long long' is not implemented, then SIZEOF_LONG_LONG will be 0 |
|
58 #define EIGHT_BYTE_INT long long |
|
59 // if no 8 byte integer type is found, then EIGHT_BYTE_INT is not defined |
|
60 #endif |
|
61 #endif |
|
62 |
2317
|
63 class |
|
64 oct_data_conv |
|
65 { |
|
66 public: |
|
67 |
|
68 enum data_type |
|
69 { |
4944
|
70 dt_int8 = 0, |
|
71 dt_uint8 = 1, |
|
72 dt_int16 = 2, |
|
73 dt_uint16 = 3, |
|
74 dt_int32 = 4, |
|
75 dt_uint32 = 5, |
|
76 dt_int64 = 6, |
|
77 dt_uint64 = 7, |
|
78 dt_single = 8, |
|
79 dt_double = 9, |
|
80 dt_char = 10, |
|
81 dt_schar = 11, |
|
82 dt_uchar = 12, |
4970
|
83 dt_logical = 13, |
|
84 dt_short = 14, |
|
85 dt_ushort = 15, |
|
86 dt_int = 16, |
|
87 dt_uint = 17, |
|
88 dt_long = 18, |
|
89 dt_ulong = 19, |
|
90 dt_longlong = 20, |
|
91 dt_ulonglong = 21, |
|
92 dt_float = 22, |
|
93 dt_unknown = 23 // Must be last, have largest value! |
2317
|
94 }; |
|
95 |
3504
|
96 static data_type string_to_data_type (const std::string& s); |
4944
|
97 |
|
98 static void string_to_data_type (const std::string& s, int& block_size, |
|
99 data_type& input_type, |
|
100 data_type& output_type); |
|
101 |
|
102 static void string_to_data_type (const std::string& s, int& block_size, |
|
103 data_type& output_type); |
|
104 |
|
105 static std::string data_type_as_string (data_type dt); |
2317
|
106 }; |
|
107 |
3739
|
108 // Add new entries to the end of this enum, otherwise Octave will not |
|
109 // be able to read binary data files stored in Octave's binary data |
|
110 // format that were created with previous versions of Octave. |
|
111 |
1960
|
112 enum save_type |
|
113 { |
3739
|
114 LS_U_CHAR = 0, |
|
115 LS_U_SHORT = 1, |
|
116 LS_U_INT = 2, |
|
117 LS_CHAR = 3, |
|
118 LS_SHORT = 4, |
|
119 LS_INT = 5, |
|
120 LS_FLOAT = 6, |
|
121 LS_DOUBLE = 7, |
|
122 LS_U_LONG = 8, |
|
123 LS_LONG = 9 |
1960
|
124 }; |
|
125 |
|
126 extern void |
4944
|
127 do_double_format_conversion (void *data, int len, |
|
128 oct_mach_info::float_format from_fmt, |
|
129 oct_mach_info::float_format to_fmt |
|
130 = oct_mach_info::native_float_format ()); |
1960
|
131 |
|
132 extern void |
4944
|
133 do_float_format_conversion (void *data, int len, |
|
134 oct_mach_info::float_format from_fmt, |
|
135 oct_mach_info::float_format to_fmt |
|
136 = oct_mach_info::native_float_format ()); |
|
137 |
|
138 extern void |
|
139 do_float_format_conversion (void *data, size_t sz, int len, |
|
140 oct_mach_info::float_format from_fmt, |
|
141 oct_mach_info::float_format to_fmt |
|
142 = oct_mach_info::native_float_format ()); |
1960
|
143 |
|
144 extern void |
3504
|
145 read_doubles (std::istream& is, double *data, save_type type, int len, |
4944
|
146 bool swap, oct_mach_info::float_format fmt); |
1960
|
147 extern void |
3504
|
148 write_doubles (std::ostream& os, const double *data, save_type type, int len); |
1960
|
149 |
|
150 #endif |
|
151 |
|
152 /* |
|
153 ;;; Local Variables: *** |
|
154 ;;; mode: C++ *** |
|
155 ;;; End: *** |
|
156 */ |