GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-fstrm.cc
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 (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <cerrno>
28 #include <cstring>
29 
30 #include "error.h"
31 #include "oct-fstrm.h"
32 
34 octave_fstream::create (const std::string& nm_arg, std::ios::openmode arg_md,
36 {
37  return octave::stream (new octave_fstream (nm_arg, arg_md, ff));
38 }
39 
41  std::ios::openmode arg_md,
43  : octave::base_stream (arg_md, ff), nm (nm_arg)
44 {
45  fs.open (nm.c_str (), arg_md);
46 
47  if (! fs)
48  // Note: error is inherited from octave::base_stream, not ::error.
49  error (std::strerror (errno));
50 }
51 
52 // Position a stream at OFFSET relative to ORIGIN.
53 
54 int
56 {
57  // Note: error is inherited from octave::base_stream, not ::error.
58  // This error function does not halt execution so "return ..." must exist.
59  error ("fseek: invalid_operation");
60  return -1;
61 }
62 
63 // Return current stream position.
64 
65 off_t
67 {
68  // Note: error is inherited from octave::base_stream, not ::error.
69  // This error function does not halt execution so "return ..." must exist.
70  error ("ftell: invalid_operation");
71  return -1;
72 }
73 
74 // Return nonzero if EOF has been reached on this stream.
75 
76 bool
77 octave_fstream::eof (void) const
78 {
79  return fs.eof ();
80 }
81 
82 void
84 {
85  fs.close ();
86 }
87 
88 std::istream *
90 {
91  std::istream *retval = nullptr;
92 
93  if (mode () & std::ios::in)
94  retval = &fs;
95 
96  return retval;
97 }
98 
99 std::ostream *
101 {
102  std::ostream *retval = nullptr;
103 
104  if (mode () & std::ios::out)
105  retval = &fs;
106 
107  return retval;
108 }
bool eof(void) const
Definition: oct-fstrm.cc:77
std::istream * input_stream(void)
Definition: oct-fstrm.cc:89
std::ostream * output_stream(void)
Definition: oct-fstrm.cc:100
octave_fstream(const std::string &nm_arg, std::ios::openmode arg_md=std::ios::in|std::ios::out, octave::mach_info::float_format flt_fmt=octave::mach_info::native_float_format())
Definition: oct-fstrm.cc:40
static octave::stream create(const std::string &nm_arg, std::ios::openmode arg_md=std::ios::in|std::ios::out, octave::mach_info::float_format flt_fmt=octave::mach_info::native_float_format())
Definition: oct-fstrm.cc:34
std::string error(bool clear, int &err_num)
Definition: oct-stream.cc:5939
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
int seek(off_t offset, int origin)
Definition: oct-fstrm.cc:55
octave_value retval
Definition: data.cc:6246
off_t tell(void)
Definition: oct-fstrm.cc:66
int mode(void) const
Definition: oct-stream.h:151
void do_close(void)
Definition: oct-fstrm.cc:83
std::fstream fs
Definition: oct-fstrm.h:85
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
std::string nm
Definition: oct-fstrm.h:83