# HG changeset patch # User jwe # Date 1141849886 0 # Node ID d24b97246b9b1eba0534171f721f09ae54df48ed # Parent 69a4f320d95a24745627f532094249b0e3ad8cee [project @ 2006-03-08 20:31:25 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2006-03-08 John W. Eaton + + * oct-stream.cc (octave_stream::stream_ok): Move definition here, + from oct-stream.h. New arg, warn. If warn is true and stream is + invalid, print warning. + (octave_stream::error): Always avoid warning message from + stream_ok. Return "invalid stream object" if stream is not ok. + 2006-03-08 David Bateman * ov-mapper.cc (SPARSE_MAPPER_LOOP_2): Change nnz to nz to remove diff --git a/src/oct-stream.cc b/src/oct-stream.cc --- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -3754,9 +3754,9 @@ std::string octave_stream::error (bool clear, int& err_num) { - std::string retval; - - if (stream_ok ("ferror", false)) + std::string retval = "invalid stream object"; + + if (stream_ok ("ferror", false, false)) retval = rep->error (clear, err_num); return retval; @@ -3833,6 +3833,27 @@ return retval; } +bool +octave_stream::stream_ok (const std::string& who, bool clear, bool warn) const +{ + bool retval = true; + + if (rep) + { + if (clear) + rep->clear (); + } + else + { + if (warn) + ::warning ("%s: attempt to use invalid I/O stream", who.c_str ()); + + retval = false; + } + + return retval; +} + octave_stream_list *octave_stream_list::instance = 0; bool diff --git a/src/oct-stream.h b/src/oct-stream.h --- a/src/oct-stream.h +++ b/src/oct-stream.h @@ -591,20 +591,8 @@ // The actual representation of this stream. octave_base_stream *rep; - bool stream_ok (const std::string& who, bool clear = true) const - { - bool retval = true; - - if (rep) - { - if (clear) - rep->clear (); - } - else - retval = false; - - return retval; - } + bool stream_ok (const std::string& who, bool clear = true, + bool warn = true) const; void invalid_operation (const std::string& who, const char *rw) {