40 #if defined HAVE_LONG_LONG_INT
41 #define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \
44 int sz = BITS / std::numeric_limits<unsigned char>::digits; \
45 if (sizeof (TQ char) == sz) \
46 VAL = oct_data_conv::dt_ ## Q ## char; \
47 else if (sizeof (TQ short) == sz) \
48 VAL = oct_data_conv::dt_ ## Q ## short; \
49 else if (sizeof (TQ int) == sz) \
50 VAL = oct_data_conv::dt_ ## Q ## int; \
51 else if (sizeof (TQ long) == sz) \
52 VAL = oct_data_conv::dt_ ## Q ## long; \
53 else if (sizeof (TQ long long) == sz) \
54 VAL = oct_data_conv::dt_ ## Q ## longlong; \
56 VAL = oct_data_conv::dt_unknown; \
60 #define FIND_SIZED_INT_TYPE(VAL, BITS, TQ, Q) \
63 int sz = BITS / std::numeric_limits<unsigned char>::digits; \
64 if (sizeof (TQ char) == sz) \
65 VAL = oct_data_conv::dt_ ## Q ## char; \
66 else if (sizeof (TQ short) == sz) \
67 VAL = oct_data_conv::dt_ ## Q ## short; \
68 else if (sizeof (TQ int) == sz) \
69 VAL = oct_data_conv::dt_ ## Q ## int; \
70 else if (sizeof (TQ long) == sz) \
71 VAL = oct_data_conv::dt_ ## Q ## long; \
73 VAL = oct_data_conv::dt_unknown; \
78 #define FIND_SIZED_FLOAT_TYPE(VAL, BITS) \
81 int sz = BITS / std::numeric_limits<unsigned char>::digits; \
82 if (sizeof (float) == sz) \
83 VAL = oct_data_conv::dt_float; \
84 else if (sizeof (double) == sz) \
85 VAL = oct_data_conv::dt_double; \
87 VAL = oct_data_conv::dt_unknown; \
119 for (
int i = 0; i < 4; i++)
134 size_t n = str.length ();
138 std::string s (n,
' ');
140 for (
size_t i = 0; i < n; i++)
141 if (! isspace (str[i]))
142 s[k++] = tolower (str[i]);
149 #define GET_SIZED_INT_TYPE(T, U) \
152 switch (sizeof (T)) \
155 retval = dt_ ## U ## int8; \
159 retval = dt_ ## U ## int16; \
163 retval = dt_ ## U ## int32; \
167 retval = dt_ ## U ## int64; \
171 retval = dt_unknown; \
185 retval =
sizeof (int8_t);
189 retval =
sizeof (uint8_t);
193 retval =
sizeof (int16_t);
197 retval =
sizeof (uint16_t);
201 retval =
sizeof (int32_t);
205 retval =
sizeof (uint32_t);
209 retval =
sizeof (int64_t);
213 retval =
sizeof (uint64_t);
218 retval =
sizeof (
float);
226 retval =
sizeof (
char);
230 retval =
sizeof (
signed char);
234 retval =
sizeof (
unsigned char);
238 retval =
sizeof (short);
242 retval =
sizeof (
unsigned short);
246 retval =
sizeof (
int);
250 retval =
sizeof (
unsigned int);
254 retval =
sizeof (long);
258 retval =
sizeof (
unsigned long);
262 retval =
sizeof (
long long);
266 retval =
sizeof (
unsigned long long);
270 retval =
sizeof (
bool);
300 if (s ==
"int8" || s ==
"integer*1")
302 else if (s ==
"uint8")
304 else if (s ==
"int16" || s ==
"integer*2")
306 else if (s ==
"uint16")
308 else if (s ==
"int32" || s ==
"integer*4")
310 else if (s ==
"uint32")
312 else if (s ==
"int64" || s ==
"integer*8")
314 else if (s ==
"uint64")
316 else if (s ==
"single" || s ==
"float32" || s ==
"real*4")
318 else if (s ==
"double" || s ==
"float64" || s ==
"real*8")
320 else if (s ==
"char" || s ==
"char*1")
322 else if (s ==
"schar" || s ==
"signedchar")
324 else if (s ==
"uchar" || s ==
"unsignedchar")
326 else if (s ==
"short")
328 else if (s ==
"ushort" || s ==
"unsignedshort")
332 else if (s ==
"uint" || s ==
"unsignedint")
334 else if (s ==
"long")
336 else if (s ==
"ulong" || s ==
"unsignedlong")
338 else if (s ==
"longlong")
340 else if (s ==
"ulonglong" || s ==
"unsignedlonglong")
342 else if (s ==
"float")
344 if (
sizeof (
float) ==
sizeof (
double))
349 else if (s ==
"logical")
355 (*current_liboctave_error_handler)
356 (
"unable to find matching native data type for %s", s.c_str ());
370 bool input_is_output =
false;
377 input_is_output =
true;
380 size_t len = s.length ();
382 while (pos < len && isdigit (s[pos]))
389 block_size = atoi (s.c_str ());
390 s = s.substr (pos+1);
394 (*current_liboctave_error_handler)
395 (
"invalid repeat count in '%s'", str.c_str ());
404 if (pos != std::string::npos)
412 input_is_output =
false;
414 s1 = s.substr (1, pos-1);
416 (*current_liboctave_warning_handler)
417 (
"warning: ignoring leading * in fread precision");
420 s1 = s.substr (0, pos);
427 (
"fread: invalid precision specified");
437 output_type = input_type;
452 size_t len = s.length ();
454 while (pos < len && isdigit (s[pos]))
461 block_size = atoi (s.c_str ());
462 s = s.substr (pos+1);
466 (*current_liboctave_error_handler)
467 (
"invalid repeat count in '%s'", str.c_str ());
528 retval =
"signed char";
532 retval =
"unsigned char";
540 retval =
"unsigned short";
548 retval =
"unsigned int";
556 retval =
"unsigned long";
560 retval =
"long long";
564 retval =
"unsigned long long";
584 #define LS_DO_READ(TYPE, swap, data, size, len, stream) \
589 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \
590 std::streamsize n_bytes = size * len; \
591 stream.read (reinterpret_cast<char *> (ptr), n_bytes); \
593 swap_bytes< size > (ptr, len); \
594 for (octave_idx_type i = 0; i < len; i++) \
603 #define LS_DO_WRITE(TYPE, data, size, len, stream) \
608 char tmp_type = type; \
609 stream.write (&tmp_type, 1); \
610 OCTAVE_LOCAL_BUFFER (TYPE, ptr, len); \
611 for (octave_idx_type i = 0; i < len; i++) \
612 ptr[i] = static_cast <TYPE> (data[i]); \
613 std::streamsize n_bytes = size * len; \
614 stream.write (reinterpret_cast<char *> (ptr), n_bytes); \
624 (*current_liboctave_error_handler)
625 (
"unrecognized floating point format requested");
701 (*current_liboctave_error_handler)
702 (
"impossible state reached in file '%s' at line %d",
748 (*current_liboctave_error_handler)
749 (
"impossible state reached in file '%s' at line %d",
771 (*current_liboctave_error_handler)
772 (
"impossible state reached in file '%s' at line %d",
790 LS_DO_READ (uint16_t, swap, data, 2, len, is);
794 LS_DO_READ (uint32_t, swap, data, 4, len, is);
812 std::streamsize n_bytes = 4 * len;
813 is.read (reinterpret_cast<char *> (ptr), n_bytes);
822 std::streamsize n_bytes = 8 *
static_cast<std::streamsize
> (len);
823 is.read (reinterpret_cast<char *> (data), n_bytes);
826 for (
int i = 0; i < len; i++)
832 is.clear (std::ios::failbit|is.rdstate ());
849 LS_DO_READ (uint16_t, swap, data, 2, len, is);
853 LS_DO_READ (uint32_t, swap, data, 4, len, is);
870 std::streamsize n_bytes = 4 * len;
871 is.read (reinterpret_cast<char *> (data), n_bytes);
879 std::streamsize n_bytes = 8 * len;
880 is.read (reinterpret_cast<char *> (ptr), n_bytes);
888 is.clear (std::ios::failbit|is.rdstate ());
929 char tmp_type =
static_cast<char> (
type);
930 os.write (&tmp_type, 1);
931 std::streamsize n_bytes = 8 *
static_cast<std::streamsize
> (len);
932 os.write (reinterpret_cast <const char *> (data), n_bytes);
937 (*current_liboctave_error_handler)
938 (
"unrecognized data format requested");
975 char tmp_type =
static_cast<char> (
type);
976 os.write (&tmp_type, 1);
977 std::streamsize n_bytes = 4 * len;
978 os.write (reinterpret_cast <const char *> (data), n_bytes);
987 (*current_liboctave_error_handler)
988 (
"unrecognized data format requested");