1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING.  If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 #  include "config.h"
28 #endif
29 
30 #include <istream>
31 #include <ostream>
32 
33 #include "error.h"
34 #include "oct-iostrm.h"
35 
36 // Position a stream at OFFSET relative to ORIGIN.
37 
38 int
seek(off_t,int)39 octave_base_iostream::seek (off_t, int)
40 {
41   invalid_operation ();
42   return -1;
43 }
44 
45 // Return current stream position.
46 
47 off_t
tell(void)48 octave_base_iostream::tell (void)
49 {
50   invalid_operation ();
51   return -1;
52 }
53 
54 // Return nonzero if EOF has been reached on this stream.
55 
56 bool
eof(void) const57 octave_base_iostream::eof (void) const
58 {
59   invalid_operation ();
60   return false;
61 }
62 
63 void
invalid_operation(void) const64 octave_base_iostream::invalid_operation (void) const
65 {
66   // Note: use ::error to get error from error.h which halts operation.
67   ::error ("%s: invalid operation", stream_type ());
68 }
69 
70 // Return nonzero if EOF has been reached on this stream.
71 
72 bool
eof(void) const73 octave_istream::eof (void) const
74 {
75   return m_istream && m_istream->eof ();
76 }
77 
78 octave::stream
create(std::istream * arg,const std::string & n)79 octave_istream::create (std::istream *arg, const std::string& n)
80 {
81   return octave::stream (new octave_istream (arg, n));
82 }
83 
84 // Return nonzero if EOF has been reached on this stream.
85 
86 bool
eof(void) const87 octave_ostream::eof (void) const
88 {
89   return m_ostream && m_ostream->eof ();
90 }
91 
92 octave::stream
create(std::ostream * arg,const std::string & n)93 octave_ostream::create (std::ostream *arg, const std::string& n)
94 {
95   return octave::stream (new octave_ostream (arg, n));
96 }
97