GNU Octave  9.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-2024 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  OCTAVE_DISABLE_COPY_MOVE (base_iostream)
48 
49 protected:
50 
51  ~base_iostream () = default;
52 
53 public:
54 
55  // Position a stream at OFFSET relative to ORIGIN.
56 
57  int seek (off_t offset, int origin);
58 
59  // Return current stream position.
60 
61  off_t tell ();
62 
63  // Return nonzero if EOF has been reached on this stream.
64 
65  bool eof () const;
66 
67  // The name of the file.
68 
69  std::string name () const { return m_name; }
70 
71 protected:
72 
73  void invalid_operation () const;
74 
75 private:
76 
77  std::string m_name;
78 
79  virtual const char * stream_type () const = 0;
80 };
81 
82 class
83 istream : public base_iostream
84 {
85 public:
86 
87  istream (std::istream *arg = nullptr, const std::string& n = "")
88  : base_iostream (n, std::ios::in, mach_info::native_float_format ()),
89  m_istream (arg)
90  { }
91 
92  OCTAVE_DISABLE_COPY_MOVE (istream)
93 
94  static stream
95  create (std::istream *arg = nullptr, const std::string& n = "");
96 
97  // Return nonzero if EOF has been reached on this stream.
98 
99  bool eof () const;
100 
101  std::istream * input_stream () { return m_istream; }
102 
103  std::ostream * output_stream () { return nullptr; }
104 
105 protected:
106 
107  ~istream () = default;
108 
109 private:
110 
111  std::istream *m_istream;
112 
113  const char * stream_type () const { return "istream"; }
114 };
115 
116 class
117 ostream : public base_iostream
118 {
119 public:
120 
121  ostream (std::ostream *arg, const std::string& n = "")
122  : base_iostream (n, std::ios::out, mach_info::native_float_format ()),
123  m_ostream (arg)
124  { }
125 
126  OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (ostream)
127 
128  static stream
129  create (std::ostream *arg, const std::string& n = "");
130 
131  // Return nonzero if EOF has been reached on this stream.
132 
133  bool eof () const;
134 
135  std::istream * input_stream () { return nullptr; }
136 
137  std::ostream * output_stream () { return m_ostream; }
138 
139 protected:
140 
141  ~ostream () = default;
142 
143 private:
144 
145  std::ostream *m_ostream;
146 
147  const char * stream_type () const { return "ostream"; }
148 };
149 
150 OCTAVE_END_NAMESPACE(octave)
151 
152 #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:42
std::string name() const
Definition: oct-iostrm.h:69
~base_iostream()=default
istream(std::istream *arg=nullptr, const std::string &n="")
Definition: oct-iostrm.h:87
std::ostream * output_stream()
Definition: oct-iostrm.h:103
std::istream * input_stream()
Definition: oct-iostrm.h:101
~istream()=default
std::istream * input_stream()
Definition: oct-iostrm.h:135
~ostream()=default
std::ostream * output_stream()
Definition: oct-iostrm.h:137
ostream(std::ostream *arg, const std::string &n="")
Definition: oct-iostrm.h:121
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
float_format native_float_format()
Definition: mach-info.cc:67
float_format
Definition: mach-info.h:38
T octave_idx_type m
Definition: mx-inlines.cc:781
octave_idx_type n
Definition: mx-inlines.cc:761