annotate libinterp/corefcn/oct-stream.h @ 20267:a9574e3c6e9e

Deprecate Array::length() and Sparse::length() in favour of ::numel(). * liboctave/array/Array.h (Array::length): deprecate for ::numel. * liboctave/array/Sparse.h (Sparse::length): deprecate for ::numel. * libgui/graphics/QtHandlesUtils.cc, libgui/src/octave-qt-link.cc, libinterp/corefcn/Cell.cc, libinterp/corefcn/__contourc__.cc, libinterp/corefcn/__pchip_deriv__.cc, libinterp/corefcn/__qp__.cc, libinterp/corefcn/cellfun.cc, libinterp/corefcn/daspk.cc, libinterp/corefcn/dasrt.cc, libinterp/corefcn/dassl.cc, libinterp/corefcn/data.cc, libinterp/corefcn/filter.cc, libinterp/corefcn/find.cc, libinterp/corefcn/gl-render.cc, libinterp/corefcn/gl-render.h, libinterp/corefcn/graphics.cc, libinterp/corefcn/graphics.in.h, libinterp/corefcn/help.cc, libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc, libinterp/corefcn/load-path.cc, libinterp/corefcn/load-save.cc, libinterp/corefcn/ls-oct-ascii.h, libinterp/corefcn/lsode.cc, libinterp/corefcn/matrix_type.cc, libinterp/corefcn/oct-hist.cc, libinterp/corefcn/oct-map.cc, libinterp/corefcn/oct-map.h, libinterp/corefcn/oct-obj.h, libinterp/corefcn/oct-stream.cc, libinterp/corefcn/oct-stream.h, libinterp/corefcn/pr-output.cc, libinterp/corefcn/quadcc.cc, libinterp/corefcn/rand.cc, libinterp/corefcn/regexp.cc, libinterp/corefcn/strfns.cc, libinterp/corefcn/sub2ind.cc, libinterp/corefcn/symtab.h, libinterp/corefcn/syscalls.cc, libinterp/corefcn/tsearch.cc, libinterp/corefcn/urlwrite.cc, libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc, libinterp/corefcn/xdiv.cc, libinterp/corefcn/xpow.cc, libinterp/dldfcn/__glpk__.cc, libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/__magick_read__.cc, libinterp/dldfcn/audiodevinfo.cc, libinterp/dldfcn/ccolamd.cc, libinterp/dldfcn/colamd.cc, libinterp/octave-value/ov-cell.cc, libinterp/octave-value/ov-class.cc, libinterp/octave-value/ov-class.h, libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-java.cc, libinterp/octave-value/ov-perm.cc, libinterp/octave-value/ov-struct.cc, libinterp/octave-value/ov-typeinfo.cc, libinterp/octave-value/ov.cc, libinterp/operators/op-int.h, libinterp/parse-tree/pt-pr-code.cc, liboctave/array/Array-util.cc, liboctave/array/Array.cc, liboctave/array/CColVector.cc, liboctave/array/CDiagMatrix.cc, liboctave/array/CMatrix.cc, liboctave/array/CRowVector.cc, liboctave/array/DiagArray2.cc, liboctave/array/DiagArray2.h, liboctave/array/MArray.cc, liboctave/array/PermMatrix.cc, liboctave/array/PermMatrix.h, liboctave/array/Sparse.cc, liboctave/array/boolMatrix.cc, liboctave/array/chMatrix.cc, liboctave/array/chNDArray.cc, liboctave/array/dColVector.cc, liboctave/array/dDiagMatrix.cc, liboctave/array/dMatrix.cc, liboctave/array/dRowVector.cc, liboctave/array/fCColVector.cc, liboctave/array/fCDiagMatrix.cc, liboctave/array/fCMatrix.cc, liboctave/array/fCRowVector.cc, liboctave/array/fColVector.cc, liboctave/array/fDiagMatrix.cc, liboctave/array/fMatrix.cc, liboctave/array/fRowVector.cc, liboctave/array/idx-vector.cc, liboctave/array/intNDArray.cc, liboctave/numeric/CmplxCHOL.cc, liboctave/numeric/CmplxLU.cc, liboctave/numeric/CmplxQR.cc, liboctave/numeric/DASPK.cc, liboctave/numeric/DASRT.cc, liboctave/numeric/DASSL.cc, liboctave/numeric/LSODE.cc, liboctave/numeric/ODES.cc, liboctave/numeric/ODES.h, liboctave/numeric/base-dae.h, liboctave/numeric/base-lu.cc, liboctave/numeric/dbleCHOL.cc, liboctave/numeric/dbleLU.cc, liboctave/numeric/dbleQR.cc, liboctave/numeric/eigs-base.cc, liboctave/numeric/fCmplxCHOL.cc, liboctave/numeric/fCmplxLU.cc, liboctave/numeric/fCmplxQR.cc, liboctave/numeric/floatCHOL.cc, liboctave/numeric/floatLU.cc, liboctave/numeric/floatQR.cc, liboctave/numeric/lo-specfun.cc, liboctave/numeric/oct-rand.cc, liboctave/numeric/oct-spparms.cc, liboctave/numeric/sparse-base-chol.cc, liboctave/operators/mx-inlines.cc, liboctave/system/file-ops.cc, liboctave/util/glob-match.h, liboctave/util/kpse.cc, liboctave/util/lo-regexp.cc, liboctave/util/oct-glob.cc, liboctave/util/pathsearch.cc, liboctave/util/str-vec.cc, liboctave/util/str-vec.h, liboctave/util/url-transfer.cc: replace all usage of Array::length() and Sparse::length() with ::numel().
author Carnë Draug <carandraug@octave.org>
date Sat, 30 May 2015 03:14:07 +0100
parents 17a7e9f26e50
children 44eb1102f8a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
1 /*
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
2
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19303
diff changeset
3 Copyright (C) 1996-2015 John W. Eaton
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
4
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
6
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6757
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6757
diff changeset
10 option) any later version.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
11
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
15 for more details.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
16
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6757
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6757
diff changeset
19 <http://www.gnu.org/licenses/>.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
20
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
21 */
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
22
17822
ebb3ef964372 maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents: 17787
diff changeset
23 #if !defined (octave_oct_stream_h)
ebb3ef964372 maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents: 17787
diff changeset
24 #define octave_oct_stream_h 1
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
25
2877
5c1b9e545dd1 [project @ 1997-04-24 09:07:39 by jwe]
jwe
parents: 2847
diff changeset
26 class Matrix;
5c1b9e545dd1 [project @ 1997-04-24 09:07:39 by jwe]
jwe
parents: 2847
diff changeset
27 class string_vector;
5c1b9e545dd1 [project @ 1997-04-24 09:07:39 by jwe]
jwe
parents: 2847
diff changeset
28 class octave_value;
5c1b9e545dd1 [project @ 1997-04-24 09:07:39 by jwe]
jwe
parents: 2847
diff changeset
29 class octave_value_list;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
30
8950
d865363208d6 include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
31 #include <iosfwd>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5659
diff changeset
32 #include <sstream>
2877
5c1b9e545dd1 [project @ 1997-04-24 09:07:39 by jwe]
jwe
parents: 2847
diff changeset
33 #include <string>
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
34 #include <list>
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6296
diff changeset
35 #include <map>
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
36
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
37 #include "Array.h"
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2225
diff changeset
38 #include "data-conv.h"
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
39 #include "lo-utils.h"
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2225
diff changeset
40 #include "mach-info.h"
13985
43cc49c7abd1 Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13983
diff changeset
41 #include "oct-refcount.h"
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
42
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
43 class
6109
c68896f193e3 [project @ 2006-10-27 02:16:18 by jwe]
jwe
parents: 5765
diff changeset
44 OCTINTERP_API
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
45 scanf_format_elt
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
46 {
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
47 public:
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
48
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3341
diff changeset
49 enum special_conversion
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
50 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
51 whitespace_conversion = 1,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
52 literal_conversion = 2
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
53 };
3483
1bb6e519a4a2 [project @ 2000-01-26 23:37:10 by jwe]
jwe
parents: 3341
diff changeset
54
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2148
diff changeset
55 scanf_format_elt (const char *txt = 0, int w = 0, bool d = false,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
56 char typ = '\0', char mod = '\0',
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
57 const std::string& ch_class = std::string ())
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
58 : text (strsave (txt)), width (w), discard (d), type (typ),
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
59 modifier (mod), char_class (ch_class) { }
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
60
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
61 scanf_format_elt (const scanf_format_elt& e)
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
62 : text (strsave (e.text)), width (e.width), discard (e.discard),
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
63 type (e.type), modifier (e.modifier), char_class (e.char_class) { }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
64
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
65 scanf_format_elt& operator = (const scanf_format_elt& e)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
66 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
67 if (this != &e)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
68 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
69 text = strsave (e.text);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
70 width = e.width;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
71 discard = e.discard;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
72 type = e.type;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
73 modifier = e.modifier;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
74 char_class = e.char_class;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
75 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
76
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
77 return *this;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
78 }
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
79
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
80 ~scanf_format_elt (void) { delete [] text; }
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
81
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
82 // The C-style format string.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
83 const char *text;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
84
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
85 // The maximum field width.
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2148
diff changeset
86 int width;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
87
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
88 // TRUE if we are not storing the result of this conversion.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
89 bool discard;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
90
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
91 // Type of conversion -- 'd', 'i', 'o', 'u', 'x', 'e', 'f', 'g',
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
92 // 'c', 's', 'p', '%', or '['.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
93 char type;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
94
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
95 // A length modifier -- 'h', 'l', or 'L'.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
96 char modifier;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
97
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
98 // The class of characters in a '[' format.
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
99 std::string char_class;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
100 };
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
101
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
102 class
6109
c68896f193e3 [project @ 2006-10-27 02:16:18 by jwe]
jwe
parents: 5765
diff changeset
103 OCTINTERP_API
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
104 scanf_format_list
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
105 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
106 public:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
107
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
108 scanf_format_list (const std::string& fmt = std::string ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
109
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
110 ~scanf_format_list (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
111
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
112 octave_idx_type num_conversions (void) { return nconv; }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
113
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2148
diff changeset
114 // The length can be different than the number of conversions.
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2148
diff changeset
115 // For example, "x %d y %d z" has 2 conversions but the length of
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2148
diff changeset
116 // the list is 3 because of the characters that appear after the
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2148
diff changeset
117 // last conversion.
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2148
diff changeset
118
20267
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19763
diff changeset
119 octave_idx_type length (void) { return list.numel (); }
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2148
diff changeset
120
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
121 const scanf_format_elt *first (void)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
122 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
123 curr_idx = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
124 return current ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
125 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
126
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
127 const scanf_format_elt *current (void) const
20267
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19763
diff changeset
128 { return list.numel () > 0 ? list.elem (curr_idx) : 0; }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
129
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
130 const scanf_format_elt *next (bool cycle = true)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
131 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
132 curr_idx++;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
133
20267
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19763
diff changeset
134 if (curr_idx >= list.numel ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
135 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
136 if (cycle)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
137 curr_idx = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
138 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
139 return 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
140 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
141 return current ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
142 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
143
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
144 void printme (void) const;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
145
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
146 bool ok (void) const { return (nconv >= 0); }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
147
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 2926
diff changeset
148 operator bool () const { return ok (); }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
149
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
150 bool all_character_conversions (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
151
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
152 bool all_numeric_conversions (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
153
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
154 private:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
155
3642
3843aa0767c8 [project @ 2000-03-24 10:48:48 by jwe]
jwe
parents: 3640
diff changeset
156 // Number of conversions specified by this format string, or -1 if
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
157 // invalid conversions have been found.
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
158 octave_idx_type nconv;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
159
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
160 // Index to current element;
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
161 octave_idx_type curr_idx;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
162
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
163 // FIXME: maybe LIST should be a std::list object?
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
164 // List of format elements.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
165 Array<scanf_format_elt*> list;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
166
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
167 // Temporary buffer.
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5659
diff changeset
168 std::ostringstream *buf;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
169
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2148
diff changeset
170 void add_elt_to_list (int width, bool discard, char type, char modifier,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
171 octave_idx_type& num_elts,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11584
diff changeset
172 const std::string& char_class = std::string ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
173
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
174 void process_conversion (const std::string& s, size_t& i, size_t n,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
175 int& width, bool& discard, char& type,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
176 char& modifier, octave_idx_type& num_elts);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
177
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
178 int finish_conversion (const std::string& s, size_t& i, size_t n,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
179 int& width, bool discard, char& type,
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
180 char modifier, octave_idx_type& num_elts);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
181 // No copying!
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
182
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
183 scanf_format_list (const scanf_format_list&);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
184
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
185 scanf_format_list& operator = (const scanf_format_list&);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
186 };
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
187
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
188 class
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
189 printf_format_elt
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
190 {
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
191 public:
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
192
19763
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
193 printf_format_elt (const char *txt = 0, int n = 0, int w = -1,
17a7e9f26e50 improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
194 int p = -1, const std::string& f = std::string (),
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
195 char typ = '\0', char mod = '\0')
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
196 : text (strsave (txt)), args (n), fw (w), prec (p), flags (f),
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
197 type (typ), modifier (mod) { }
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
198
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
199 printf_format_elt (const printf_format_elt& e)
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
200 : text (strsave (e.text)), args (e.args), fw (e.fw), prec (e.prec),
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
201 flags (e.flags), type (e.type), modifier (e.modifier) { }
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
202
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
203 printf_format_elt& operator = (const printf_format_elt& e)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
204 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
205 if (this != &e)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
206 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
207 text = strsave (e.text);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
208 args = e.args;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
209 fw = e.fw;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
210 prec = e.prec;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
211 flags = e.flags;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
212 type = e.type;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
213 modifier = e.modifier;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
214 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
215
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
216 return *this;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
217 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
218
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
219 ~printf_format_elt (void) { delete [] text; }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11584
diff changeset
220
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
221 // The C-style format string.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
222 const char *text;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
223
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
224 // How many args do we expect to consume?
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
225 int args;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
226
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
227 // Field width.
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
228 int fw;
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
229
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
230 // Precision.
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
231 int prec;
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
232
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
233 // Flags -- '-', '+', ' ', '0', or '#'.
3642
3843aa0767c8 [project @ 2000-03-24 10:48:48 by jwe]
jwe
parents: 3640
diff changeset
234 std::string flags;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
235
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
236 // Type of conversion -- 'd', 'i', 'o', 'x', 'X', 'u', 'c', 's',
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
237 // 'f', 'e', 'E', 'g', 'G', 'p', or '%'
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
238 char type;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
239
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
240 // A length modifier -- 'h', 'l', or 'L'.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
241 char modifier;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
242 };
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
243
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
244 class
6109
c68896f193e3 [project @ 2006-10-27 02:16:18 by jwe]
jwe
parents: 5765
diff changeset
245 OCTINTERP_API
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
246 printf_format_list
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
247 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
248 public:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
249
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
250 printf_format_list (const std::string& fmt = std::string ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
251
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
252 ~printf_format_list (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
253
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
254 octave_idx_type num_conversions (void) { return nconv; }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
255
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
256 const printf_format_elt *first (void)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
257 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
258 curr_idx = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
259 return current ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
260 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
261
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
262 const printf_format_elt *current (void) const
20267
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19763
diff changeset
263 { return list.numel () > 0 ? list.elem (curr_idx) : 0; }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
264
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
265 const printf_format_elt *next (bool cycle = true)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
266 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
267 curr_idx++;
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
268
20267
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19763
diff changeset
269 if (curr_idx >= list.numel ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
270 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
271 if (cycle)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
272 curr_idx = 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
273 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
274 return 0;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
275 }
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
276
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
277 return current ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
278 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
279
20267
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19763
diff changeset
280 bool last_elt_p (void) { return (curr_idx + 1 == list.numel ()); }
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
281
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
282 void printme (void) const;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
283
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
284 bool ok (void) const { return (nconv >= 0); }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
285
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 2926
diff changeset
286 operator bool () const { return ok (); }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
287
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
288 private:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
289
3642
3843aa0767c8 [project @ 2000-03-24 10:48:48 by jwe]
jwe
parents: 3640
diff changeset
290 // Number of conversions specified by this format string, or -1 if
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
291 // invalid conversions have been found.
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
292 octave_idx_type nconv;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
293
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
294 // Index to current element;
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
295 octave_idx_type curr_idx;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
296
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
297 // FIXME: maybe LIST should be a std::list object?
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
298 // List of format elements.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
299 Array<printf_format_elt*> list;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
300
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
301 // Temporary buffer.
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5659
diff changeset
302 std::ostringstream *buf;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
303
3640
d3b0ff09dda7 [project @ 2000-03-24 10:28:19 by jwe]
jwe
parents: 3546
diff changeset
304 void add_elt_to_list (int args, const std::string& flags, int fw,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
305 int prec, char type, char modifier,
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
306 octave_idx_type& num_elts);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11584
diff changeset
307
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
308 void process_conversion (const std::string& s, size_t& i, size_t n,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
309 int& args, std::string& flags, int& fw,
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
310 int& prec, char& modifier, char& type,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11584
diff changeset
311 octave_idx_type& num_elts);
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11584
diff changeset
312
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
313 void finish_conversion (const std::string& s, size_t& i, int args,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
314 const std::string& flags, int fw, int prec,
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
315 char modifier, char& type,
10187
a44d15813a39 don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
316 octave_idx_type& num_elts);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
317
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
318 // No copying!
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
319
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
320 printf_format_list (const printf_format_list&);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
321
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
322 printf_format_list& operator = (const printf_format_list&);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
323 };
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
324
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
325 // Provide an interface for Octave streams.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
326
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
327 class
6109
c68896f193e3 [project @ 2006-10-27 02:16:18 by jwe]
jwe
parents: 5765
diff changeset
328 OCTINTERP_API
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
329 octave_base_stream
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
330 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
331 friend class octave_stream;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
332
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
333 public:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
334
3544
71bd2d124119 [project @ 2000-02-02 21:02:31 by jwe]
jwe
parents: 3523
diff changeset
335 octave_base_stream (std::ios::openmode arg_md = std::ios::in|std::ios::out,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
336 oct_mach_info::float_format ff
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
337 = oct_mach_info::native_float_format ())
11584
cda4aa780d58 Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11570
diff changeset
338 : count (0), md (arg_md), flt_fmt (ff), fail (false), open_state (true),
cda4aa780d58 Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11570
diff changeset
339 errmsg ()
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
340 { }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
341
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
342 virtual ~octave_base_stream (void) { }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
343
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
344 // The remaining functions are not specific to input or output only,
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
345 // and must be provided by the derived classes.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
346
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
347 // Position a stream at OFFSET relative to ORIGIN.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
348
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
349 virtual int seek (off_t offset, int origin) = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
350
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
351 // Return current stream position.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
352
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
353 virtual off_t tell (void) = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
354
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
355 // Return TRUE if EOF has been reached on this stream.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
356
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
357 virtual bool eof (void) const = 0;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
358
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
359 // The name of the file.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
360
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
361 virtual std::string name (void) const = 0;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
362
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
363 // If the derived class provides this function and it returns a
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
364 // pointer to a valid istream, scanf(), read(), getl(), and gets()
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
365 // will automatically work for this stream.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
366
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
367 virtual std::istream *input_stream (void) { return 0; }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
368
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
369 // If the derived class provides this function and it returns a
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
370 // pointer to a valid ostream, flush(), write(), and printf() will
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
371 // automatically work for this stream.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
372
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
373 virtual std::ostream *output_stream (void) { return 0; }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
374
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
375 // Return TRUE if this stream is open.
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
376
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
377 bool is_open (void) const { return open_state; }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
378
3652
25e84fcef38a [project @ 2000-03-31 08:50:48 by jwe]
jwe
parents: 3642
diff changeset
379 virtual void do_close (void) { }
25e84fcef38a [project @ 2000-03-31 08:50:48 by jwe]
jwe
parents: 3642
diff changeset
380
25e84fcef38a [project @ 2000-03-31 08:50:48 by jwe]
jwe
parents: 3642
diff changeset
381 void close (void)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
382 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
383 if (is_open ())
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
384 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
385 open_state = false;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
386 do_close ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
387 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
388 }
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
389
11007
ffe58182db89 src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents: 11004
diff changeset
390 virtual int file_number (void) const
ffe58182db89 src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents: 11004
diff changeset
391 {
ffe58182db89 src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents: 11004
diff changeset
392 // Kluge alert!
ffe58182db89 src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents: 11004
diff changeset
393
ffe58182db89 src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents: 11004
diff changeset
394 if (name () == "stdin")
ffe58182db89 src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents: 11004
diff changeset
395 return 0;
ffe58182db89 src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents: 11004
diff changeset
396 else if (name () == "stdout")
ffe58182db89 src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents: 11004
diff changeset
397 return 1;
ffe58182db89 src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents: 11004
diff changeset
398 else if (name () == "stderr")
ffe58182db89 src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents: 11004
diff changeset
399 return 2;
ffe58182db89 src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents: 11004
diff changeset
400 else
ffe58182db89 src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents: 11004
diff changeset
401 return -1;
ffe58182db89 src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents: 11004
diff changeset
402 }
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 2926
diff changeset
403
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
404 bool ok (void) const { return ! fail; }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
405
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
406 // Return current error message for this stream.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
407
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
408 std::string error (bool clear, int& err_num);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
409
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
410 protected:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
411
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
412 int mode (void) const { return md; }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
413
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
414 oct_mach_info::float_format float_format (void) const { return flt_fmt; }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
415
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
416 // Set current error state and set fail to TRUE.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
417
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
418 void error (const std::string& msg);
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
419 void error (const std::string& who, const std::string& msg);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
420
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
421 // Clear any error message and set fail to FALSE.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
422
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
423 void clear (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
424
4889
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4799
diff changeset
425 // Clear stream state.
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4799
diff changeset
426
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4799
diff changeset
427 void clearerr (void);
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4799
diff changeset
428
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
429 private:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
430
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
431 // A reference count.
13985
43cc49c7abd1 Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13983
diff changeset
432 octave_refcount<octave_idx_type> count;
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
433
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
434 // The permission bits for the file. Should be some combination of
3544
71bd2d124119 [project @ 2000-02-02 21:02:31 by jwe]
jwe
parents: 3523
diff changeset
435 // std::ios::open_mode bits.
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
436 int md;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
437
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
438 // Data format.
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2225
diff changeset
439 oct_mach_info::float_format flt_fmt;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
440
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
441 // TRUE if an error has occurred.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
442 bool fail;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
443
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
444 // TRUE if this stream is open.
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
445 bool open_state;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
446
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
447 // Should contain error message if fail is TRUE.
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
448 std::string errmsg;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
449
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
450 // Functions that are defined for all input streams (input streams
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
451 // are those that define is).
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
452
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5015
diff changeset
453 std::string do_gets (octave_idx_type max_len, bool& err, bool strip_newline,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
454 const std::string& who /* = "gets" */);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
455
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
456 std::string getl (octave_idx_type max_len, bool& err,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
457 const std::string& who /* = "getl" */);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
458 std::string gets (octave_idx_type max_len, bool& err,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
459 const std::string& who /* = "gets" */);
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
460 off_t skipl (off_t count, bool& err, const std::string& who /* = "skipl" */);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
461
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
462 octave_value do_scanf (scanf_format_list& fmt_list, octave_idx_type nr,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
463 octave_idx_type nc,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
464 bool one_elt_size_spec, octave_idx_type& count,
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
465 const std::string& who /* = "scanf" */);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
466
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
467 octave_value scanf (const std::string& fmt, const Array<double>& size,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
468 octave_idx_type& count, const std::string& who /* = "scanf" */);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
469
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
470 bool do_oscanf (const scanf_format_elt *elt, octave_value&,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
471 const std::string& who /* = "scanf" */);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
472
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
473 octave_value_list oscanf (const std::string& fmt,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
474 const std::string& who /* = "scanf" */);
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2148
diff changeset
475
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
476 // Functions that are defined for all output streams (output streams
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
477 // are those that define os).
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
478
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
479 int flush (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
480
18684
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
481 int do_numeric_printf_conv (std::ostream& os, const printf_format_elt *elt,
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
482 int nsa, int sa_1, int sa_2,
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
483 const octave_value& val,
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
484 const std::string& who);
491b0adfec95 compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents: 17822
diff changeset
485
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
486 int do_printf (printf_format_list& fmt_list, const octave_value_list& args,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
487 const std::string& who /* = "printf" */);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
488
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
489 int printf (const std::string& fmt, const octave_value_list& args,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
490 const std::string& who /* = "printf" */);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
491
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
492 int puts (const std::string& s, const std::string& who /* = "puts" */);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
493
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
494 // We can always do this in terms of seek(), so the derived class
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
495 // only has to provide that.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
496
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
497 void invalid_operation (const std::string& who, const char *rw);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
498
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
499 // No copying!
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
500
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
501 octave_base_stream (const octave_base_stream&);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
502
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
503 octave_base_stream& operator = (const octave_base_stream&);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
504 };
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
505
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
506 class
6109
c68896f193e3 [project @ 2006-10-27 02:16:18 by jwe]
jwe
parents: 5765
diff changeset
507 OCTINTERP_API
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
508 octave_stream
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
509 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
510 public:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
511
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
512 octave_stream (octave_base_stream *bs = 0);
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
513
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
514 ~octave_stream (void);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
515
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
516 octave_stream (const octave_stream&);
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
517
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
518 octave_stream& operator = (const octave_stream&);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
519
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
520 int flush (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
521
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
522 std::string getl (octave_idx_type max_len, bool& err,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
523 const std::string& who /* = "getl" */);
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
524 std::string getl (const octave_value& max_len, bool& err,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
525 const std::string& who /* = "getl" */);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
526
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
527 std::string gets (octave_idx_type max_len, bool& err,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
528 const std::string& who /* = "gets" */);
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
529 std::string gets (const octave_value& max_len, bool& err,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
530 const std::string& who /* = "gets" */);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
531
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
532 off_t skipl (off_t count, bool& err, const std::string& who /* = "skipl" */);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
533 off_t skipl (const octave_value& count, bool& err,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
534 const std::string& who /* = "skipl" */);
9701
531280b07625 implement fskipl
Jaroslav Hajek <highegg@gmail.com>
parents: 8950
diff changeset
535
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
536 int seek (off_t offset, int origin);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
537 int seek (const octave_value& offset, const octave_value& origin);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
538
16011
8122286c69a9 initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
539 off_t tell (void);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
540
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
541 int rewind (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
542
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
543 bool is_open (void) const;
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
544
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
545 void close (void);
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
546
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5015
diff changeset
547 octave_value read (const Array<double>& size, octave_idx_type block_size,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
548 oct_data_conv::data_type input_type,
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
549 oct_data_conv::data_type output_type,
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
550 octave_idx_type skip, oct_mach_info::float_format flt_fmt,
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
551 octave_idx_type& count);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
552
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5015
diff changeset
553 octave_idx_type write (const octave_value& data, octave_idx_type block_size,
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 16892
diff changeset
554 oct_data_conv::data_type output_type,
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 16892
diff changeset
555 octave_idx_type skip,
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 16892
diff changeset
556 oct_mach_info::float_format flt_fmt);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 16892
diff changeset
557
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 16892
diff changeset
558 bool write_bytes (const void *data, size_t n_elts);
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 16892
diff changeset
559
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 16892
diff changeset
560 bool skip_bytes (size_t n_elts);
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4889
diff changeset
561
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4889
diff changeset
562 template <class T>
17416
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 16892
diff changeset
563 octave_idx_type write (const Array<T>& data, octave_idx_type block_size,
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 16892
diff changeset
564 oct_data_conv::data_type output_type,
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 16892
diff changeset
565 octave_idx_type skip,
6690dba6078a improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents: 16892
diff changeset
566 oct_mach_info::float_format flt_fmt);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
567
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
568 octave_value scanf (const std::string& fmt, const Array<double>& size,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
569 octave_idx_type& count, const std::string& who /* = "scanf" */);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
570
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
571 octave_value scanf (const octave_value& fmt, const Array<double>& size,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
572 octave_idx_type& count, const std::string& who /* = "scanf" */);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
573
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
574 octave_value_list oscanf (const std::string& fmt,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
575 const std::string& who /* = "scanf" */);
2215
ab0e1fd337f5 [project @ 1996-05-16 15:56:40 by jwe]
jwe
parents: 2148
diff changeset
576
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
577 octave_value_list oscanf (const octave_value& fmt,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
578 const std::string& who /* = "scanf" */);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
579
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
580 int printf (const std::string& fmt, const octave_value_list& args,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
581 const std::string& who /* = "printf" */);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
582
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
583 int printf (const octave_value& fmt, const octave_value_list& args,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
584 const std::string& who /* = "printf" */);
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5275
diff changeset
585
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
586 int puts (const std::string& s, const std::string& who /* = "puts" */);
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
587 int puts (const octave_value& s, const std::string& who /* = "puts" */);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
588
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
589 bool eof (void) const;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
590
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
591 std::string error (bool clear, int& err_num);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
592
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
593 std::string error (bool clear = false)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
594 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
595 int err_num;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
596 return error (clear, err_num);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
597 }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
598
4799
e2d7d1ef5e55 [project @ 2004-02-24 19:47:18 by jwe]
jwe
parents: 4797
diff changeset
599 // Set the error message and state.
e2d7d1ef5e55 [project @ 2004-02-24 19:47:18 by jwe]
jwe
parents: 4797
diff changeset
600
e2d7d1ef5e55 [project @ 2004-02-24 19:47:18 by jwe]
jwe
parents: 4797
diff changeset
601 void error (const std::string& msg)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
602 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
603 if (rep)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
604 rep->error (msg);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
605 }
4799
e2d7d1ef5e55 [project @ 2004-02-24 19:47:18 by jwe]
jwe
parents: 4797
diff changeset
606
e2d7d1ef5e55 [project @ 2004-02-24 19:47:18 by jwe]
jwe
parents: 4797
diff changeset
607 void error (const char *msg) { error (std::string (msg)); }
e2d7d1ef5e55 [project @ 2004-02-24 19:47:18 by jwe]
jwe
parents: 4797
diff changeset
608
3148
8cdcb8945695 [project @ 1998-02-06 21:25:11 by jwe]
jwe
parents: 3145
diff changeset
609 int file_number (void) { return rep ? rep->file_number () : -1; }
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 2926
diff changeset
610
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
611 bool is_valid (void) const { return (rep != 0); }
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
612
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
613 bool ok (void) const { return rep && rep->ok (); }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
614
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 2926
diff changeset
615 operator bool () const { return ok (); }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
616
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
617 std::string name (void) const;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
618
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
619 int mode (void) const;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
620
3340
585a8809fd9b [project @ 1999-11-05 07:02:30 by jwe]
jwe
parents: 3268
diff changeset
621 oct_mach_info::float_format float_format (void) const;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
622
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
623 static std::string mode_as_string (int mode);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
624
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6296
diff changeset
625 std::istream *input_stream (void)
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6296
diff changeset
626 {
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6296
diff changeset
627 return rep ? rep->input_stream () : 0;
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6296
diff changeset
628 }
2902
c5b7a019b9ed [project @ 1997-04-30 03:46:53 by jwe]
jwe
parents: 2877
diff changeset
629
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6296
diff changeset
630 std::ostream *output_stream (void)
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6296
diff changeset
631 {
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6296
diff changeset
632 return rep ? rep->output_stream () : 0;
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6296
diff changeset
633 }
16099
4b6c44096862 Backout changeset 238e499c5fea (locale support in scanf)
Rik <rik@octave.org>
parents: 16011
diff changeset
634
4889
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4799
diff changeset
635 void clearerr (void) { if (rep) rep->clearerr (); }
658aad1c1b05 [project @ 2004-04-30 22:38:30 by jwe]
jwe
parents: 4799
diff changeset
636
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
637 private:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
638
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
639 // The actual representation of this stream.
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
640 octave_base_stream *rep;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
641
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
642 bool stream_ok (bool clear = true) const
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
643 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
644 bool retval = true;
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
645
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
646 if (rep)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
647 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
648 if (clear)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
649 rep->clear ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
650 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
651 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
652 retval = false;
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5649
diff changeset
653
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
654 return retval;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
655 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4889
diff changeset
656
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4889
diff changeset
657 void invalid_operation (const std::string& who, const char *rw)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
658 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
659 if (rep)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
660 rep->invalid_operation (who, rw);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
661 }
17453
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
662
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
663 octave_value
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
664 finalize_read (std::list<void *>& input_buf_list,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
665 octave_idx_type input_buf_elts,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
666 octave_idx_type elts_read,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
667 octave_idx_type nr, octave_idx_type nc,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
668 oct_data_conv::data_type input_type,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
669 oct_data_conv::data_type output_type,
669ad11f282d improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents: 17416
diff changeset
670 oct_mach_info::float_format ffmt);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
671 };
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
672
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
673 class
6109
c68896f193e3 [project @ 2006-10-27 02:16:18 by jwe]
jwe
parents: 5765
diff changeset
674 OCTINTERP_API
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
675 octave_stream_list
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
676 {
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
677 protected:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
678
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
679 octave_stream_list (void) : list (), lookup_cache (list.end ()) { }
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
680
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
681 public:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
682
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
683 ~octave_stream_list (void) { }
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
684
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2902
diff changeset
685 static bool instance_ok (void);
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2902
diff changeset
686
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6296
diff changeset
687 static int insert (octave_stream& os);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
688
4468
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
689 static octave_stream
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
690 lookup (int fid, const std::string& who = std::string ());
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
691
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
692 static octave_stream
efb6301dae80 [project @ 2003-07-15 19:18:20 by jwe]
jwe
parents: 4051
diff changeset
693 lookup (const octave_value& fid, const std::string& who = std::string ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
694
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
695 static int remove (int fid, const std::string& who = std::string ());
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
696 static int remove (const octave_value& fid,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
697 const std::string& who = std::string ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
698
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
699 static void clear (bool flush = true);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
700
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
701 static string_vector get_info (int fid);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
702 static string_vector get_info (const octave_value& fid);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
703
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
704 static std::string list_open_files (void);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
705
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
706 static octave_value open_file_numbers (void);
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
707
2609
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2435
diff changeset
708 static int get_file_number (const octave_value& fid);
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2435
diff changeset
709
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
710 private:
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
711
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6296
diff changeset
712 typedef std::map<int, octave_stream> ostrl_map;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
713
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6296
diff changeset
714 ostrl_map list;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
715
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
716 mutable ostrl_map::const_iterator lookup_cache;
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
717
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
718 static octave_stream_list *instance;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
719
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
720 static void cleanup_instance (void) { delete instance; instance = 0; }
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
721
6757
c3cd7d14fc5e [project @ 2007-06-25 19:06:42 by jwe]
jwe
parents: 6296
diff changeset
722 int do_insert (octave_stream& os);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
723
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
724 octave_stream do_lookup (int fid,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
725 const std::string& who = std::string ()) const;
3341
14cfc9475fe4 [project @ 1999-11-05 08:11:58 by jwe]
jwe
parents: 3340
diff changeset
726 octave_stream do_lookup (const octave_value& fid,
10313
f3b65e1ae355 untabify src header files
John W. Eaton <jwe@octave.org>
parents: 10187
diff changeset
727 const std::string& who = std::string ()) const;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
728
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
729 int do_remove (int fid, const std::string& who = std::string ());
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
730 int do_remove (const octave_value& fid,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
731 const std::string& who = std::string ());
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
732
8902
5d5db7a347c6 erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
733 void do_clear (bool flush = true);
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
734
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
735 string_vector do_get_info (int fid) const;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
736 string_vector do_get_info (const octave_value& fid) const;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
737
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
738 std::string do_list_open_files (void) const;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
739
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
740 octave_value do_open_file_numbers (void) const;
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
741
2609
12bc9d0a50b5 [project @ 1997-01-18 00:17:36 by jwe]
jwe
parents: 2435
diff changeset
742 int do_get_file_number (const octave_value& fid) const;
2117
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
743 };
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
744
b240b2fce8ed [project @ 1996-05-10 07:20:36 by jwe]
jwe
parents:
diff changeset
745 #endif