GNU Octave  6.2.0
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-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 (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <cerrno>
31 #include <cstring>
32 
33 #include "error.h"
34 #include "oct-fstrm.h"
35 
37 octave_fstream::create (const std::string& nm_arg, std::ios::openmode arg_md,
39 {
40  return octave::stream (new octave_fstream (nm_arg, arg_md, ff));
41 }
42 
43 octave_fstream::octave_fstream (const std::string& nm_arg,
44  std::ios::openmode arg_md,
46  : octave::base_stream (arg_md, ff), m_name (nm_arg)
47 {
48  m_fstream.open (m_name.c_str (), arg_md);
49 
50  if (! m_fstream)
51  // Note: error is inherited from octave::base_stream, not ::error.
52  error (std::strerror (errno));
53 }
54 
55 // Position a stream at OFFSET relative to ORIGIN.
56 
57 int
59 {
60  // Note: error is inherited from octave::base_stream, not ::error.
61  // This error function does not halt execution so "return ..." must exist.
62  error ("fseek: invalid_operation");
63  return -1;
64 }
65 
66 // Return current stream position.
67 
68 off_t
70 {
71  // Note: error is inherited from octave::base_stream, not ::error.
72  // This error function does not halt execution so "return ..." must exist.
73  error ("ftell: invalid_operation");
74  return -1;
75 }
76 
77 // Return nonzero if EOF has been reached on this stream.
78 
79 bool
80 octave_fstream::eof (void) const
81 {
82  return m_fstream.eof ();
83 }
84 
85 void
87 {
88  m_fstream.close ();
89 }
90 
91 std::istream *
93 {
94  std::istream *retval = nullptr;
95 
96  if (mode () & std::ios::in)
97  retval = &m_fstream;
98 
99  return retval;
100 }
101 
102 std::ostream *
104 {
105  std::ostream *retval = nullptr;
106 
107  if (mode () & std::ios::out)
108  retval = &m_fstream;
109 
110  return retval;
111 }
std::string error(bool clear, int &err_num)
Definition: oct-stream.cc:6050
int mode(void) const
Definition: oct-stream.h:155
int seek(off_t offset, int origin)
Definition: oct-fstrm.cc:58
void do_close(void)
Definition: oct-fstrm.cc:86
std::ostream * output_stream(void)
Definition: oct-fstrm.cc:103
off_t tell(void)
Definition: oct-fstrm.cc:69
std::istream * input_stream(void)
Definition: oct-fstrm.cc:92
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:37
std::string m_name
Definition: oct-fstrm.h:86
bool eof(void) const
Definition: oct-fstrm.cc:80
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:43
std::fstream m_fstream
Definition: oct-fstrm.h:88
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811