GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-iostrm.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2023 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 
37 class
39 {
40 public:
41 
42  base_iostream (const std::string& n = "",
43  std::ios::openmode m = std::ios::in | std::ios::out,
45  : base_stream (m, ff), m_name (n) { }
46 
47  // No copying!
48 
49  base_iostream (const base_iostream&) = delete;
50 
51  base_iostream& operator = (const base_iostream&) = delete;
52 
53 protected:
54 
55  ~base_iostream (void) = default;
56 
57 public:
58 
59  // Position a stream at OFFSET relative to ORIGIN.
60 
61  int seek (off_t offset, int origin);
62 
63  // Return current stream position.
64 
65  off_t tell (void);
66 
67  // Return nonzero if EOF has been reached on this stream.
68 
69  bool eof (void) const;
70 
71  // The name of the file.
72 
73  std::string name (void) const { return m_name; }
74 
75 protected:
76 
77  void invalid_operation (void) const;
78 
79 private:
80 
81  std::string m_name;
82 
83  virtual const char * stream_type (void) const = 0;
84 };
85 
86 class
87 istream : public base_iostream
88 {
89 public:
90 
91  istream (std::istream *arg = nullptr, const std::string& n = "")
92  : base_iostream (n, std::ios::in, mach_info::native_float_format ()),
93  m_istream (arg)
94  { }
95 
96  static stream
97  create (std::istream *arg = nullptr, const std::string& n = "");
98 
99  // Return nonzero if EOF has been reached on this stream.
100 
101  bool eof (void) const;
102 
103  std::istream * input_stream (void) { return m_istream; }
104 
105  std::ostream * output_stream (void) { return nullptr; }
106 
107 protected:
108 
109  ~istream (void) = default;
110 
111 private:
112 
113  std::istream *m_istream;
114 
115  const char * stream_type (void) const { return "istream"; }
116 
117  // No copying!
118 
119  istream (const istream&) = delete;
120 
121  istream& operator = (const istream&) = delete;
122 };
123 
124 class
125 ostream : public base_iostream
126 {
127 public:
128 
129  ostream (std::ostream *arg, const std::string& n = "")
130  : base_iostream (n, std::ios::out, mach_info::native_float_format ()),
131  m_ostream (arg)
132  { }
133 
134  static stream
135  create (std::ostream *arg, const std::string& n = "");
136 
137  // Return nonzero if EOF has been reached on this stream.
138 
139  bool eof (void) const;
140 
141  std::istream * input_stream (void) { return nullptr; }
142 
143  std::ostream * output_stream (void) { return m_ostream; }
144 
145 protected:
146 
147  ~ostream (void) = default;
148 
149 private:
150 
151  std::ostream *m_ostream;
152 
153  const char * stream_type (void) const { return "ostream"; }
154 
155  // No copying!
156 
157  ostream (const ostream&) = delete;
158 
159  ostream& operator = (const ostream&) = delete;
160 };
161 
163 
164 #if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)
165 
166 OCTAVE_DEPRECATED (7, "use 'octave::base_iostream' instead")
167 typedef octave::base_iostream octave_base_iostream;
168 
169 OCTAVE_DEPRECATED (7, "use 'octave::istream' instead")
170 typedef octave::istream octave_istream;
171 
172 OCTAVE_DEPRECATED (7, "use 'octave::ostream' instead")
173 typedef octave::ostream octave_ostream;
174 
175 #endif
176 
177 #endif
OCTAVE_END_NAMESPACE(octave)
~base_iostream(void)=default
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:42
base_iostream(const base_iostream &)=delete
std::string name(void) const
Definition: oct-iostrm.h:73
virtual const char * stream_type(void) const =0
std::string m_name
Definition: oct-iostrm.h:81
std::ostream * output_stream(void)
Definition: oct-iostrm.h:105
std::istream * m_istream
Definition: oct-iostrm.h:113
istream(std::istream *arg=nullptr, const std::string &n="")
Definition: oct-iostrm.h:91
~istream(void)=default
std::istream * input_stream(void)
Definition: oct-iostrm.h:103
istream(const istream &)=delete
const char * stream_type(void) const
Definition: oct-iostrm.h:115
std::ostream * output_stream(void)
Definition: oct-iostrm.h:143
std::istream * input_stream(void)
Definition: oct-iostrm.h:141
ostream(const ostream &)=delete
ostream(std::ostream *arg, const std::string &n="")
Definition: oct-iostrm.h:129
~ostream(void)=default
const char * stream_type(void) const
Definition: oct-iostrm.h:153
std::ostream * m_ostream
Definition: oct-iostrm.h:151
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
float_format native_float_format(void)
Definition: mach-info.cc:65
float_format
Definition: mach-info.h:38
T octave_idx_type m
Definition: mx-inlines.cc:773
octave_idx_type n
Definition: mx-inlines.cc:753