GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
oct-fstrm.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 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
39fstream::create (const std::string& nm_arg, std::ios::openmode arg_md,
40 mach_info::float_format ff)
41{
42 return stream (new fstream (nm_arg, arg_md, ff));
43}
44
45fstream::fstream (const std::string& nm_arg, std::ios::openmode arg_md,
46 mach_info::float_format ff)
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
58int
59fstream::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
69off_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
80bool
82{
83 return m_fstream.eof ();
84}
85
86void
88{
89 m_fstream.close ();
90}
91
92std::istream *
94{
95 std::istream *retval = nullptr;
96
97 if (mode () & std::ios::in)
98 retval = &m_fstream;
99
100 return retval;
101}
102
103std::ostream *
105{
106 std::ostream *retval = nullptr;
107
108 if (mode () & std::ios::out)
109 retval = &m_fstream;
110
111 return retval;
112}
113
114OCTAVE_END_NAMESPACE(octave)
std::string error(bool clear, int &err_num)
friend class stream
Definition oct-stream.h:68
int mode() const
Definition oct-stream.h:180
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
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
std::istream * input_stream()
Definition oct-fstrm.cc:93
off_t tell()
Definition oct-fstrm.cc:70
bool eof() const
Definition oct-fstrm.cc:81
std::ostream * output_stream()
Definition oct-fstrm.cc:104
int seek(off_t offset, int origin)
Definition oct-fstrm.cc:59
void do_close()
Definition oct-fstrm.cc:87
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn