GNU Octave  4.2.1
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-stdstrm.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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 #if ! defined (octave_oct_stdstrm_h)
24 #define octave_oct_stdstrm_h 1
25 
26 #include "octave-config.h"
27 
28 #include "oct-stream.h"
29 #include "c-file-ptr-stream.h"
30 
31 template <typename BUF_T, typename STREAM_T, typename FILE_T>
32 class
34 {
35 public:
36 
37  octave_tstdiostream (const std::string& n, FILE_T f = 0, int fid = 0,
38  std::ios::openmode m = std::ios::in | std::ios::out,
41  typename BUF_T::close_fcn cf = BUF_T::file_close)
42  : octave_base_stream (m, ff), nm (n), md (m),
43  s (f ? new STREAM_T (f, cf) : 0), fnum (fid)
44  { }
45 
46  // Position a stream at OFFSET relative to ORIGIN.
47 
48  int seek (off_t offset, int origin)
49  { return s ? s->seek (offset, origin) : -1; }
50 
51  // Return current stream position.
52 
53  off_t tell (void) { return s ? s->tell () : -1; }
54 
55  // Return nonzero if EOF has been reached on this stream.
56 
57  bool eof (void) const { return s ? s->eof () : true; }
58 
59  // The name of the file.
60 
61  std::string name (void) const { return nm; }
62 
63  std::istream *input_stream (void) { return (md & std::ios::in) ? s : 0; }
64 
65  std::ostream *output_stream (void) { return (md & std::ios::out) ? s : 0; }
66 
67  // FIXME: should not have to cast away const here.
68  BUF_T *rdbuf (void) const
69  { return s ? (const_cast<STREAM_T *> (s))->rdbuf () : 0; }
70 
71  int file_number (void) const { return fnum; }
72 
73  bool bad (void) const { return s ? s->bad () : true; }
74 
75  void clear (void) { if (s) s->clear (); }
76 
77  void do_close (void) { if (s) s->stream_close (); }
78 
79 protected:
80 
82 
83  std::ios::openmode md;
84 
86 
87  // The file number associated with this file.
88  int fnum;
89 
90  ~octave_tstdiostream (void) { delete s; }
91 
92 private:
93 
94  // No copying!
95 
97 
98  octave_tstdiostream& operator = (const octave_tstdiostream&);
99 };
100 
101 class
104 {
105 public:
106 
107  octave_stdiostream (const std::string& n, FILE *f = 0,
108  std::ios::openmode m = std::ios::in | std::ios::out,
113  (n, f, f ? fileno (f) : -1, m, ff, cf) { }
114 
115  static octave_stream
116  create (const std::string& n, FILE *f = 0,
117  std::ios::openmode m = std::ios::in | std::ios::out,
121  {
122  return octave_stream (new octave_stdiostream (n, f, m, ff, cf));
123  }
124 
125 protected:
126 
128 
129 private:
130 
131  // No copying!
132 
134 
135  octave_stdiostream& operator = (const octave_stdiostream&);
136 };
137 
138 #if defined (HAVE_ZLIB)
139 
140 class
143 {
144 public:
145 
146  octave_zstdiostream (const std::string& n, gzFile f = 0, int fid = 0,
147  std::ios::openmode m = std::ios::in | std::ios::out,
153  (n, f, fid, m, ff, cf) { }
154 
155  static octave_stream
156  create (const std::string& n, gzFile f = 0, int fid = 0,
157  std::ios::openmode m = std::ios::in | std::ios::out,
161  {
162  return octave_stream (new octave_zstdiostream (n, f, fid, m, ff, cf));
163  }
164 
165 protected:
166 
168 
169 private:
170 
171  // No copying!
172 
174 
175  octave_zstdiostream& operator = (const octave_zstdiostream&);
176 };
177 
178 #endif
179 
180 #endif
static int file_close(gzFile f)
bool eof(void) const
Definition: oct-stdstrm.h:57
octave_zstdiostream(const std::string &n, gzFile f=0, int fid=0, std::ios::openmode m=std::ios::in|std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format(), c_zfile_ptr_buf::close_fcn cf=c_zfile_ptr_buf::file_close)
Definition: oct-stdstrm.h:146
std::string name(void) const
Definition: oct-stdstrm.h:61
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
int seek(off_t offset, int origin)
Definition: oct-stdstrm.h:48
int file_number(void) const
Definition: oct-stdstrm.h:71
off_t tell(void)
Definition: oct-stdstrm.h:53
void clear(void)
Definition: oct-stdstrm.h:75
void do_close(void)
Definition: oct-stdstrm.h:77
std::istream * input_stream(void)
Definition: oct-stdstrm.h:63
s
Definition: file-io.cc:2682
~octave_tstdiostream(void)
Definition: oct-stdstrm.h:90
octave_stdiostream(const std::string &n, FILE *f=0, std::ios::openmode m=std::ios::in|std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format(), c_file_ptr_buf::close_fcn cf=c_file_ptr_buf::file_close)
Definition: oct-stdstrm.h:107
std::ios::openmode md
Definition: oct-stdstrm.h:83
int(* close_fcn)(gzFile)
static void close_fcn(FILE *f)
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
std::ostream * output_stream(void)
Definition: oct-stdstrm.h:65
static octave_stream create(const std::string &n, gzFile f=0, int fid=0, std::ios::openmode m=std::ios::in|std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format(), c_zfile_ptr_buf::close_fcn cf=c_zfile_ptr_buf::file_close)
Definition: oct-stdstrm.h:156
static int file_close(FILE *f)
bool bad(void) const
Definition: oct-stdstrm.h:73
octave_tstdiostream(const std::string &n, FILE_T f=0, int fid=0, std::ios::openmode m=std::ios::in|std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format(), typename BUF_T::close_fcn cf=BUF_T::file_close)
Definition: oct-stdstrm.h:37
static float_format native_float_format(void)
Definition: mach-info.cc:162
std::string nm
Definition: oct-stdstrm.h:81
static octave_stream create(const std::string &n, FILE *f=0, std::ios::openmode m=std::ios::in|std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format(), c_file_ptr_buf::close_fcn cf=c_file_ptr_buf::file_close)
Definition: oct-stdstrm.h:116
int(* close_fcn)(FILE *)
BUF_T * rdbuf(void) const
Definition: oct-stdstrm.h:68
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:854