Mercurial > hg > octave-lyh
comparison liboctave/dMatrix.cc @ 3145:0d640dc625c7
[project @ 1998-02-05 08:44:59 by jwe]
author | jwe |
---|---|
date | Thu, 05 Feb 1998 08:45:07 +0000 |
parents | 02766207b74c |
children | fccab8e7d35f |
comparison
equal
deleted
inserted
replaced
3144:fb9924282a3e | 3145:0d640dc625c7 |
---|---|
2375 | 2375 |
2376 template <class T> | 2376 template <class T> |
2377 static void | 2377 static void |
2378 read_int (istream& is, bool swap_bytes, T& val) | 2378 read_int (istream& is, bool swap_bytes, T& val) |
2379 { | 2379 { |
2380 is.read (static_cast<char *> (&val), sizeof (T)); | 2380 is.read (X_CAST (char *, &val), sizeof (T)); |
2381 | 2381 |
2382 if (swap_bytes) | 2382 if (swap_bytes) |
2383 { | 2383 { |
2384 switch (sizeof (T)) | 2384 switch (sizeof (T)) |
2385 { | 2385 { |
2386 case 1: | 2386 case 1: |
2387 break; | 2387 break; |
2388 | 2388 |
2389 case 2: | 2389 case 2: |
2390 swap_2_bytes (static_cast<char *> (&val)); | 2390 swap_2_bytes (X_CAST (char *, &val)); |
2391 break; | 2391 break; |
2392 | 2392 |
2393 case 4: | 2393 case 4: |
2394 swap_4_bytes (static_cast<char *> (&val)); | 2394 swap_4_bytes (X_CAST (char *, &val)); |
2395 break; | 2395 break; |
2396 | 2396 |
2397 case 8: | 2397 case 8: |
2398 swap_8_bytes (static_cast<char *> (&val)); | 2398 swap_8_bytes (X_CAST (char *, &val)); |
2399 break; | 2399 break; |
2400 | 2400 |
2401 default: | 2401 default: |
2402 (*current_liboctave_error_handler) | 2402 (*current_liboctave_error_handler) |
2403 ("read_int: unrecognized data format!"); | 2403 ("read_int: unrecognized data format!"); |
2498 | 2498 |
2499 case oct_data_conv::dt_float: | 2499 case oct_data_conv::dt_float: |
2500 { | 2500 { |
2501 float f; | 2501 float f; |
2502 | 2502 |
2503 is.read (static_cast<char *> (&f), sizeof (float)); | 2503 is.read (X_CAST (char *, &f), sizeof (float)); |
2504 | 2504 |
2505 if (do_float_conversion) | 2505 if (do_float_conversion) |
2506 do_float_format_conversion (&f, 1, flt_fmt); | 2506 do_float_format_conversion (&f, 1, flt_fmt); |
2507 | 2507 |
2508 val = f; | 2508 val = f; |
2509 } | 2509 } |
2510 break; | 2510 break; |
2511 | 2511 |
2512 case oct_data_conv::dt_double: | 2512 case oct_data_conv::dt_double: |
2513 { | 2513 { |
2514 is.read (static_cast<char *> (&val), sizeof (double)); | 2514 is.read (X_CAST (char *, &val), sizeof (double)); |
2515 | 2515 |
2516 if (do_float_conversion) | 2516 if (do_float_conversion) |
2517 do_double_format_conversion (&val, 1, flt_fmt); | 2517 do_double_format_conversion (&val, 1, flt_fmt); |
2518 } | 2518 } |
2519 break; | 2519 break; |
2689 { | 2689 { |
2690 case 1: | 2690 case 1: |
2691 break; | 2691 break; |
2692 | 2692 |
2693 case 2: | 2693 case 2: |
2694 swap_2_bytes (static_cast<char *> (&val)); | 2694 swap_2_bytes (X_CAST (char *, &val)); |
2695 break; | 2695 break; |
2696 | 2696 |
2697 case 4: | 2697 case 4: |
2698 swap_4_bytes (static_cast<char *> (&val)); | 2698 swap_4_bytes (X_CAST (char *, &val)); |
2699 break; | 2699 break; |
2700 | 2700 |
2701 case 8: | 2701 case 8: |
2702 swap_8_bytes (static_cast<char *> (&val)); | 2702 swap_8_bytes (X_CAST (char *, &val)); |
2703 break; | 2703 break; |
2704 | 2704 |
2705 default: | 2705 default: |
2706 (*current_liboctave_error_handler) | 2706 (*current_liboctave_error_handler) |
2707 ("write_int: unrecognized data format!"); | 2707 ("write_int: unrecognized data format!"); |
2708 } | 2708 } |
2709 } | 2709 } |
2710 | 2710 |
2711 os.write (static_cast<char *> (&val), sizeof (T)); | 2711 os.write (X_CAST (char *, &val), sizeof (T)); |
2712 } | 2712 } |
2713 | 2713 |
2714 template void write_int (ostream&, bool, char); | 2714 template void write_int (ostream&, bool, char); |
2715 template void write_int (ostream&, bool, signed char); | 2715 template void write_int (ostream&, bool, signed char); |
2716 template void write_int (ostream&, bool, unsigned char); | 2716 template void write_int (ostream&, bool, unsigned char); |
2729 bool retval = true; | 2729 bool retval = true; |
2730 | 2730 |
2731 switch (dt) | 2731 switch (dt) |
2732 { | 2732 { |
2733 case oct_data_conv::dt_char: | 2733 case oct_data_conv::dt_char: |
2734 write_int (os, swap_bytes, static_cast<char> (d)); | 2734 write_int (os, swap_bytes, X_CAST (char, d)); |
2735 break; | 2735 break; |
2736 | 2736 |
2737 case oct_data_conv::dt_schar: | 2737 case oct_data_conv::dt_schar: |
2738 write_int (os, swap_bytes, static_cast<signed char> (d)); | 2738 write_int (os, swap_bytes, X_CAST (signed char, d)); |
2739 break; | 2739 break; |
2740 | 2740 |
2741 case oct_data_conv::dt_uchar: | 2741 case oct_data_conv::dt_uchar: |
2742 write_int (os, swap_bytes, static_cast<unsigned char> (d)); | 2742 write_int (os, swap_bytes, X_CAST (unsigned char, d)); |
2743 break; | 2743 break; |
2744 | 2744 |
2745 case oct_data_conv::dt_short: | 2745 case oct_data_conv::dt_short: |
2746 write_int (os, swap_bytes, static_cast<short> (d)); | 2746 write_int (os, swap_bytes, X_CAST (short, d)); |
2747 break; | 2747 break; |
2748 | 2748 |
2749 case oct_data_conv::dt_ushort: | 2749 case oct_data_conv::dt_ushort: |
2750 write_int (os, swap_bytes, static_cast<unsigned short> (d)); | 2750 write_int (os, swap_bytes, X_CAST (unsigned short, d)); |
2751 break; | 2751 break; |
2752 | 2752 |
2753 case oct_data_conv::dt_int: | 2753 case oct_data_conv::dt_int: |
2754 write_int (os, swap_bytes, static_cast<int> (d)); | 2754 write_int (os, swap_bytes, X_CAST (int, d)); |
2755 break; | 2755 break; |
2756 | 2756 |
2757 case oct_data_conv::dt_uint: | 2757 case oct_data_conv::dt_uint: |
2758 write_int (os, swap_bytes, static_cast<unsigned int> (d)); | 2758 write_int (os, swap_bytes, X_CAST (unsigned int, d)); |
2759 break; | 2759 break; |
2760 | 2760 |
2761 case oct_data_conv::dt_long: | 2761 case oct_data_conv::dt_long: |
2762 write_int (os, swap_bytes, static_cast<long> (d)); | 2762 write_int (os, swap_bytes, X_CAST (long, d)); |
2763 break; | 2763 break; |
2764 | 2764 |
2765 case oct_data_conv::dt_ulong: | 2765 case oct_data_conv::dt_ulong: |
2766 write_int (os, swap_bytes, static_cast<unsigned long> (d)); | 2766 write_int (os, swap_bytes, X_CAST (unsigned long, d)); |
2767 break; | 2767 break; |
2768 | 2768 |
2769 case oct_data_conv::dt_float: | 2769 case oct_data_conv::dt_float: |
2770 { | 2770 { |
2771 float f = d; | 2771 float f = d; |
2772 | 2772 |
2773 if (do_float_conversion) | 2773 if (do_float_conversion) |
2774 do_float_format_conversion (&f, 1, flt_fmt); | 2774 do_float_format_conversion (&f, 1, flt_fmt); |
2775 | 2775 |
2776 os.write (static_cast<char *> (&f), sizeof (float)); | 2776 os.write (X_CAST (char *, &f), sizeof (float)); |
2777 } | 2777 } |
2778 break; | 2778 break; |
2779 | 2779 |
2780 case oct_data_conv::dt_double: | 2780 case oct_data_conv::dt_double: |
2781 { | 2781 { |
2782 if (do_float_conversion) | 2782 if (do_float_conversion) |
2783 do_double_format_conversion (&d, 1, flt_fmt); | 2783 do_double_format_conversion (&d, 1, flt_fmt); |
2784 | 2784 |
2785 os.write (static_cast<char *> (&d), sizeof (double)); | 2785 os.write (X_CAST (char *, &d), sizeof (double)); |
2786 } | 2786 } |
2787 break; | 2787 break; |
2788 | 2788 |
2789 default: | 2789 default: |
2790 retval = false; | 2790 retval = false; |