# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1388329890 18000 # Node ID 284e5c87f27b95876a34c4ffd0f8f58275edd25d # Parent 0b5f669f5b0367048213eec53ed3cff3f6351aa0 Fix saving int8 and uint8 in plain text format (bug #40980) * oct-inttypes.h (operator<<): Specialise this operator's octave_int overloads for T = int8_t and T = uint8_t so that it calls non-char versions of std::operator<< diff -r 0b5f669f5b03 -r 284e5c87f27b liboctave/util/oct-inttypes.h --- a/liboctave/util/oct-inttypes.h Thu Jan 09 21:48:34 2014 +0100 +++ b/liboctave/util/oct-inttypes.h Sun Dec 29 10:11:30 2013 -0500 @@ -1023,6 +1023,50 @@ return is; } +// We need to specialise for char and unsigned char because +// std::operator<< and std::operator>> are overloaded to input and +// output the ASCII character values instead of a representation of +// their numerical value (e.g. os << char(10) outputs a space instead +// of outputting the characters '1' and '0') + +template <> +inline std::ostream& +operator << (std::ostream& os, const octave_int& ival) +{ + os << static_cast (ival.value ()); + return os; +} + +template <> +inline std::ostream& +operator << (std::ostream& os, const octave_int& ival) +{ + os << static_cast (ival.value ()); + return os; +} + + +template <> +inline std::istream& +operator >> (std::istream& is, octave_int& ival) +{ + int tmp = 0; + is >> tmp; + ival = static_cast (tmp); + return is; +} + +template <> +inline std::istream& +operator >> (std::istream& is, octave_int& ival) +{ + unsigned int tmp = 0; + is >> tmp; + ival = static_cast (tmp); + return is; +} + + // Bitwise operations #define OCTAVE_INT_BITCMP_OP(OP) \