GNU Octave  6.2.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-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 (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 
35 class
37 {
38 public:
39 
40  octave_base_iostream (const std::string& n = "",
41  std::ios::openmode m = std::ios::in | std::ios::out,
44  : octave::base_stream (m, ff), m_name (n) { }
45 
46  // No copying!
47 
49 
50  octave_base_iostream& operator = (const octave_base_iostream&) = delete;
51 
52 protected:
53 
54  ~octave_base_iostream (void) = default;
55 
56 public:
57 
58  // Position a stream at OFFSET relative to ORIGIN.
59 
60  int seek (off_t offset, int origin);
61 
62  // Return current stream position.
63 
64  off_t tell (void);
65 
66  // Return nonzero if EOF has been reached on this stream.
67 
68  bool eof (void) const;
69 
70  // The name of the file.
71 
72  std::string name (void) const { return m_name; }
73 
74 protected:
75 
76  void invalid_operation (void) const;
77 
78 private:
79 
80  std::string m_name;
81 
82  virtual const char * stream_type (void) const = 0;
83 };
84 
85 class
87 {
88 public:
89 
90  octave_istream (std::istream *arg = nullptr, const std::string& n = "")
91  : octave_base_iostream (n, std::ios::in,
92  octave::mach_info::native_float_format ()),
93  m_istream (arg)
94  { }
95 
96  static octave::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  ~octave_istream (void) = default;
110 
111 private:
112 
113  std::istream *m_istream;
114 
115  const char * stream_type (void) const { return "octave_istream"; }
116 
117  // No copying!
118 
119  octave_istream (const octave_istream&) = delete;
120 
121  octave_istream& operator = (const octave_istream&) = delete;
122 };
123 
124 class
126 {
127 public:
128 
129  octave_ostream (std::ostream *arg, const std::string& n = "")
130  : octave_base_iostream (n, std::ios::out,
131  octave::mach_info::native_float_format ()),
132  m_ostream (arg)
133  { }
134 
135  static octave::stream
136  create (std::ostream *arg, const std::string& n = "");
137 
138  // Return nonzero if EOF has been reached on this stream.
139 
140  bool eof (void) const;
141 
142  std::istream * input_stream (void) { return nullptr; }
143 
144  std::ostream * output_stream (void) { return m_ostream; }
145 
146 protected:
147 
148  ~octave_ostream (void) = default;
149 
150 private:
151 
152  std::ostream *m_ostream;
153 
154  const char * stream_type (void) const { return "octave_ostream"; }
155 
156  // No copying!
157 
158  octave_ostream (const octave_ostream&) = delete;
159 
160  octave_ostream& operator = (const octave_ostream&) = delete;
161 };
162 
163 #endif
octave_base_iostream(const std::string &n="", std::ios::openmode m=std::ios::in|std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format())
Definition: oct-iostrm.h:40
std::string m_name
Definition: oct-iostrm.h:80
virtual const char * stream_type(void) const =0
octave_base_iostream(const octave_base_iostream &)=delete
~octave_base_iostream(void)=default
std::string name(void) const
Definition: oct-iostrm.h:72
std::istream * m_istream
Definition: oct-iostrm.h:113
std::ostream * output_stream(void)
Definition: oct-iostrm.h:105
const char * stream_type(void) const
Definition: oct-iostrm.h:115
~octave_istream(void)=default
std::istream * input_stream(void)
Definition: oct-iostrm.h:103
octave_istream(const octave_istream &)=delete
octave_istream(std::istream *arg=nullptr, const std::string &n="")
Definition: oct-iostrm.h:90
std::ostream * m_ostream
Definition: oct-iostrm.h:152
octave_ostream(const octave_ostream &)=delete
~octave_ostream(void)=default
std::istream * input_stream(void)
Definition: oct-iostrm.h:142
std::ostream * output_stream(void)
Definition: oct-iostrm.h:144
const char * stream_type(void) const
Definition: oct-iostrm.h:154
octave_ostream(std::ostream *arg, const std::string &n="")
Definition: oct-iostrm.h:129
T octave_idx_type m
Definition: mx-inlines.cc:773
octave_idx_type n
Definition: mx-inlines.cc:753
float_format native_float_format(void)
Definition: mach-info.cc:65