GNU Octave  8.1.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-2023 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 
38 stream
39 fstream::create (const std::string& nm_arg, std::ios::openmode arg_md,
41 {
42  return stream (new fstream (nm_arg, arg_md, ff));
43 }
44 
45 fstream::fstream (const std::string& nm_arg, std::ios::openmode arg_md,
47  : base_stream (arg_md, ff), m_name (nm_arg)
48 {
49  m_fstream.open (m_name.c_str (), arg_md);
50 
51  if (! m_fstream)
52  // Note: error is inherited from base_stream, not ::error.
53  error (std::strerror (errno));
54 }
55 
56 // Position a stream at OFFSET relative to ORIGIN.
57 
58 int
59 fstream::seek (off_t, int)
60 {
61  // Note: error is inherited from base_stream, not ::error.
62  // This error function does not halt execution so "return ..." must exist.
63  error ("fseek: invalid_operation");
64  return -1;
65 }
66 
67 // Return current stream position.
68 
69 off_t
71 {
72  // Note: error is inherited from base_stream, not ::error.
73  // This error function does not halt execution so "return ..." must exist.
74  error ("ftell: invalid_operation");
75  return -1;
76 }
77 
78 // Return nonzero if EOF has been reached on this stream.
79 
80 bool
81 fstream::eof (void) const
82 {
83  return m_fstream.eof ();
84 }
85 
86 void
88 {
89  m_fstream.close ();
90 }
91 
92 std::istream *
94 {
95  std::istream *retval = nullptr;
96 
97  if (mode () & std::ios::in)
98  retval = &m_fstream;
99 
100  return retval;
101 }
102 
103 std::ostream *
105 {
106  std::ostream *retval = nullptr;
107 
108  if (mode () & std::ios::out)
109  retval = &m_fstream;
110 
111  return retval;
112 }
113 
OCTAVE_END_NAMESPACE(octave)
int mode(void) const
Definition: oct-stream.h:183
std::string error(bool clear, int &err_num)
Definition: oct-stream.cc:6115
friend class stream
Definition: oct-stream.h:70
std::istream * input_stream(void)
Definition: oct-fstrm.cc:93
fstream(const std::string &nm_arg, std::ios::openmode arg_md=std::ios::in|std::ios::out, mach_info::float_format flt_fmt=mach_info::native_float_format())
Definition: oct-fstrm.cc:45
std::fstream m_fstream
Definition: oct-fstrm.h:88
void do_close(void)
Definition: oct-fstrm.cc:87
std::string m_name
Definition: oct-fstrm.h:86
off_t tell(void)
Definition: oct-fstrm.cc:70
static stream create(const std::string &nm_arg, std::ios::openmode arg_md=std::ios::in|std::ios::out, mach_info::float_format flt_fmt=mach_info::native_float_format())
Definition: oct-fstrm.cc:39
bool eof(void) const
Definition: oct-fstrm.cc:81
std::ostream * output_stream(void)
Definition: oct-fstrm.cc:104
int seek(off_t offset, int origin)
Definition: oct-fstrm.cc:59
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
float_format
Definition: mach-info.h:38