GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
oct-fstrm.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef 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 
40 octave_fstream::octave_fstream (const std::string& nm_arg,
41  std::ios::openmode arg_md,
43  : octave_base_stream (arg_md, ff), nm (nm_arg)
44 {
45 
46 #if CXX_ISO_COMPLIANT_LIBRARY
47 
48  fs.open (nm.c_str (), arg_md);
49 
50 #else
51  // Override default protection of 0664 so that umask will appear to
52  // do the right thing.
53 
54  fs.open (nm.c_str (), arg_md, 0666);
55 
56 #endif
57 
58  if (! fs)
59  error (gnulib::strerror (errno));
60 }
61 
62 // Position a stream at OFFSET relative to ORIGIN.
63 
64 int
66 {
67  error ("fseek: invalid_operation");
68  return -1;
69 }
70 
71 // Return current stream position.
72 
73 off_t
75 {
76  error ("ftell: invalid_operation");
77  return -1;
78 }
79 
80 // Return nonzero if EOF has been reached on this stream.
81 
82 bool
83 octave_fstream::eof (void) const
84 {
85  return fs.eof ();
86 }
87 
88 void
90 {
91  fs.close ();
92 }
93 
94 std::istream *
96 {
97  std::istream *retval = 0;
98 
99  if (mode () & std::ios::in)
100  retval = &fs;
101 
102  return retval;
103 }
104 
105 std::ostream *
107 {
108  std::ostream *retval = 0;
109 
110  if (mode () & std::ios::out)
111  retval = &fs;
112 
113  return retval;
114 }
std::istream * input_stream(void)
Definition: oct-fstrm.cc:95
bool eof(void) const
Definition: oct-fstrm.cc:83
static octave_stream create(const std::string &nm_arg, std::ios::openmode arg_md=std::ios::in|std::ios::out, oct_mach_info::float_format flt_fmt=oct_mach_info::native_float_format())
Definition: oct-fstrm.cc:34
std::ostream * output_stream(void)
Definition: oct-fstrm.cc:106
int seek(off_t offset, int origin)
Definition: oct-fstrm.cc:65
int mode(void) const
Definition: oct-stream.h:412
off_t tell(void)
Definition: oct-fstrm.cc:74
std::string error(bool clear, int &err_num)
Definition: oct-stream.cc:2801
octave_fstream(const std::string &nm_arg, std::ios::openmode arg_md=std::ios::in|std::ios::out, oct_mach_info::float_format flt_fmt=oct_mach_info::native_float_format())
Definition: oct-fstrm.cc:40
void do_close(void)
Definition: oct-fstrm.cc:89
std::fstream fs
Definition: oct-fstrm.h:77
friend class octave_stream
Definition: oct-stream.h:331
std::string nm
Definition: oct-fstrm.h:75