GNU Octave  4.4.1
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-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_oct_iostrm_h)
24 #define octave_oct_iostrm_h 1
25 
26 #include "octave-config.h"
27 
28 #include <iosfwd>
29 
30 #include "oct-stream.h"
31 
32 class
34 {
35 public:
36 
38  std::ios::openmode m = std::ios::in | std::ios::out,
41  : octave::base_stream (m, ff), nm (n) { }
42 
43  // No copying!
44 
46 
47  octave_base_iostream& operator = (const octave_base_iostream&) = delete;
48 
49 protected:
50 
51  ~octave_base_iostream (void) = 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 (void);
62 
63  // Return nonzero if EOF has been reached on this stream.
64 
65  bool eof (void) const;
66 
67  // The name of the file.
68 
69  std::string name (void) const { return nm; }
70 
71 protected:
72 
73  void invalid_operation (void) const;
74 
75 private:
76 
78 
79  virtual const char * stream_type (void) const = 0;
80 };
81 
82 class
84 {
85 public:
86 
87  octave_istream (std::istream *arg = nullptr, const std::string& n = "")
88  : octave_base_iostream (n, std::ios::in,
89  octave::mach_info::native_float_format ()),
90  is (arg)
91  { }
92 
93  static octave::stream
94  create (std::istream *arg = nullptr, const std::string& n = "");
95 
96  // Return nonzero if EOF has been reached on this stream.
97 
98  bool eof (void) const;
99 
100  std::istream * input_stream (void) { return is; }
101 
102  std::ostream * output_stream (void) { return nullptr; }
103 
104 protected:
105 
106  ~octave_istream (void) = default;
107 
108 private:
109 
110  std::istream *is;
111 
112  const char * stream_type (void) const { return "octave_istream"; }
113 
114  // No copying!
115 
116  octave_istream (const octave_istream&) = delete;
117 
118  octave_istream& operator = (const octave_istream&) = delete;
119 };
120 
121 class
123 {
124 public:
125 
126  octave_ostream (std::ostream *arg, const std::string& n = "")
127  : octave_base_iostream (n, std::ios::out,
128  octave::mach_info::native_float_format ()),
129  os (arg)
130  { }
131 
132  static octave::stream
133  create (std::ostream *arg, const std::string& n = "");
134 
135  // Return nonzero if EOF has been reached on this stream.
136 
137  bool eof (void) const;
138 
139  std::istream * input_stream (void) { return nullptr; }
140 
141  std::ostream * output_stream (void) { return os; }
142 
143 protected:
144 
145  ~octave_ostream (void) = default;
146 
147 private:
148 
149  std::ostream *os;
150 
151  const char * stream_type (void) const { return "octave_ostream"; }
152 
153  // No copying!
154 
155  octave_ostream (const octave_ostream&) = delete;
156 
157  octave_ostream& operator = (const octave_ostream&) = delete;
158 };
159 
160 #endif
std::string name(void) const
Definition: oct-iostrm.h:69
std::istream * is
Definition: oct-iostrm.h:110
std::ostream * output_stream(void)
Definition: oct-iostrm.h:141
STL namespace.
octave_istream(std::istream *arg=nullptr, const std::string &n="")
Definition: oct-iostrm.h:87
const char * stream_type(void) const
Definition: oct-iostrm.h:112
octave_value arg
Definition: pr-output.cc:3244
std::string nm
Definition: oct-iostrm.h:77
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
std::istream * input_stream(void)
Definition: oct-iostrm.h:100
float_format native_float_format(void)
Definition: mach-info.cc:62
std::ostream * output_stream(void)
Definition: oct-iostrm.h:102
const char * stream_type(void) const
Definition: oct-iostrm.h:151
std::istream * input_stream(void)
Definition: oct-iostrm.h:139
octave_ostream(std::ostream *arg, const std::string &n="")
Definition: oct-iostrm.h:126
write the output to stdout if nargout is
Definition: load-save.cc:1612
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
octave::stream os
Definition: file-io.cc:627
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:37
std::ostream * os
Definition: oct-iostrm.h:149