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