GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
oct-iostrm.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 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 (octave_oct_iostrm_h)
27#define octave_oct_iostrm_h 1
28
29#include "octave-config.h"
30
31#include <iosfwd>
32
33#include "oct-stream.h"
34
36
38{
39public:
40
41 base_iostream (const std::string& n = "",
42 std::ios::openmode m = std::ios::in | std::ios::out,
43 mach_info::float_format ff = mach_info::native_float_format ())
44 : base_stream (m, ff), m_name (n) { }
45
46 OCTAVE_DISABLE_COPY_MOVE (base_iostream)
47
48protected:
49
50 ~base_iostream () = default;
51
52public:
53
54 // Position a stream at OFFSET relative to ORIGIN.
55
56 int seek (off_t offset, int origin);
57
58 // Return current stream position.
59
60 off_t tell ();
61
62 // Return nonzero if EOF has been reached on this stream.
63
64 bool eof () const;
65
66 // The name of the file.
67
68 std::string name () const { return m_name; }
69
70protected:
71
72 void invalid_operation () const;
73
74private:
75
76 std::string m_name;
77
78 virtual const char * stream_type () const = 0;
79};
80
81class istream : public base_iostream
82{
83public:
84
85 istream (std::istream *arg = nullptr, const std::string& n = "")
86 : base_iostream (n, std::ios::in, mach_info::native_float_format ()),
87 m_istream (arg)
88 { }
89
90 OCTAVE_DISABLE_COPY_MOVE (istream)
91
92 static stream
93 create (std::istream *arg = nullptr, const std::string& n = "");
94
95 // Return nonzero if EOF has been reached on this stream.
96
97 bool eof () const;
98
99 std::istream * input_stream () { return m_istream; }
100
101 std::ostream * output_stream () { return nullptr; }
102
103protected:
104
105 ~istream () = default;
106
107private:
108
109 std::istream *m_istream;
110
111 const char * stream_type () const { return "istream"; }
112};
113
114class ostream : public base_iostream
115{
116public:
117
118 ostream (std::ostream *arg, const std::string& n = "")
119 : base_iostream (n, std::ios::out, mach_info::native_float_format ()),
120 m_ostream (arg)
121 { }
122
123 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (ostream)
124
125 static stream
126 create (std::ostream *arg, const std::string& n = "");
127
128 // Return nonzero if EOF has been reached on this stream.
129
130 bool eof () const;
131
132 std::istream * input_stream () { return nullptr; }
133
134 std::ostream * output_stream () { return m_ostream; }
135
136protected:
137
138 ~ostream () = default;
139
140private:
141
142 std::ostream *m_ostream;
143
144 const char * stream_type () const { return "ostream"; }
145};
146
147OCTAVE_END_NAMESPACE(octave)
148
149#endif
base_iostream(const std::string &n="", std::ios::openmode m=std::ios::in|std::ios::out, mach_info::float_format ff=mach_info::native_float_format())
Definition oct-iostrm.h:41
std::string name() const
Definition oct-iostrm.h:68
~base_iostream()=default
std::ostream * output_stream()
Definition oct-iostrm.h:101
istream(std::istream *arg=nullptr, const std::string &n="")
Definition oct-iostrm.h:85
std::istream * input_stream()
Definition oct-iostrm.h:99
bool eof() const
Definition oct-iostrm.cc:75
static stream create(std::istream *arg=nullptr, const std::string &n="")
Definition oct-iostrm.cc:81
~istream()=default
~ostream()=default
std::ostream * output_stream()
Definition oct-iostrm.h:134
static stream create(std::ostream *arg, const std::string &n="")
Definition oct-iostrm.cc:95
ostream(std::ostream *arg, const std::string &n="")
Definition oct-iostrm.h:118
bool eof() const
Definition oct-iostrm.cc:89
std::istream * input_stream()
Definition oct-iostrm.h:132
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
float_format native_float_format()
Definition mach-info.cc:67