00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_data_conv_h)
00024 #define octave_data_conv_h 1
00025
00026 #include <climits>
00027
00028 #include "mach-info.h"
00029
00030
00031
00032 #if CHAR_BIT != 8
00033 #error "CHAR_BIT is not 8!"
00034 #endif
00035
00036 #if SIZEOF_SHORT == 2
00037 #define TWO_BYTE_INT short
00038 #elif SIZEOF_INT == 2
00039 #define TWO_BYTE_INT int
00040 #else
00041 #error "No 2 byte integer type found!"
00042 #endif
00043
00044 #if SIZEOF_INT == 4
00045 #define FOUR_BYTE_INT int
00046 #elif SIZEOF_LONG == 4
00047 #define FOUR_BYTE_INT long
00048 #else
00049 #error "No 4 byte integer type found!"
00050 #endif
00051
00052 #if SIZEOF_LONG == 8
00053 #define EIGHT_BYTE_INT long
00054 #else
00055 #if SIZEOF_LONG_LONG == 8
00056
00057 #define EIGHT_BYTE_INT long long
00058
00059 #endif
00060 #endif
00061
00062 class
00063 oct_data_conv
00064 {
00065 public:
00066
00067 enum data_type
00068 {
00069 dt_int8 = 0,
00070 dt_uint8 = 1,
00071 dt_int16 = 2,
00072 dt_uint16 = 3,
00073 dt_int32 = 4,
00074 dt_uint32 = 5,
00075 dt_int64 = 6,
00076 dt_uint64 = 7,
00077 dt_single = 8,
00078 dt_double = 9,
00079 dt_char = 10,
00080 dt_schar = 11,
00081 dt_uchar = 12,
00082 dt_logical = 13,
00083 dt_short = 14,
00084 dt_ushort = 15,
00085 dt_int = 16,
00086 dt_uint = 17,
00087 dt_long = 18,
00088 dt_ulong = 19,
00089 dt_longlong = 20,
00090 dt_ulonglong = 21,
00091 dt_float = 22,
00092 dt_unknown = 23
00093 };
00094
00095 static data_type string_to_data_type (const std::string& s);
00096
00097 static void string_to_data_type (const std::string& s, int& block_size,
00098 data_type& input_type,
00099 data_type& output_type);
00100
00101 static void string_to_data_type (const std::string& s, int& block_size,
00102 data_type& output_type);
00103
00104 static std::string data_type_as_string (data_type dt);
00105 };
00106
00107
00108
00109
00110
00111 enum save_type
00112 {
00113 LS_U_CHAR = 0,
00114 LS_U_SHORT = 1,
00115 LS_U_INT = 2,
00116 LS_CHAR = 3,
00117 LS_SHORT = 4,
00118 LS_INT = 5,
00119 LS_FLOAT = 6,
00120 LS_DOUBLE = 7,
00121 LS_U_LONG = 8,
00122 LS_LONG = 9
00123 };
00124
00125 extern void
00126 do_double_format_conversion (void *data, int len,
00127 oct_mach_info::float_format from_fmt,
00128 oct_mach_info::float_format to_fmt
00129 = oct_mach_info::native_float_format ());
00130
00131 extern void
00132 do_float_format_conversion (void *data, int len,
00133 oct_mach_info::float_format from_fmt,
00134 oct_mach_info::float_format to_fmt
00135 = oct_mach_info::native_float_format ());
00136
00137 extern void
00138 do_float_format_conversion (void *data, size_t sz, int len,
00139 oct_mach_info::float_format from_fmt,
00140 oct_mach_info::float_format to_fmt
00141 = oct_mach_info::native_float_format ());
00142
00143 extern void
00144 read_doubles (std::istream& is, double *data, save_type type, int len,
00145 bool swap, oct_mach_info::float_format fmt);
00146 extern void
00147 write_doubles (std::ostream& os, const double *data, save_type type, int len);
00148
00149 #endif
00150
00151
00152
00153
00154
00155