Mercurial > octave
annotate libinterp/corefcn/oct-stream.h @ 21502:7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
* file-io.cc (Ftextscan): Move here.
* textxcan.cc: From here.
* oct-stream.h, oct-stream.cc (delimited_stream, textscan_format_elt,
textscan_format_list, textscan): Move here.
* textscan.h, textscan.cc: From here.
* textscan.h, textscan.cc: Delete.
* libinterp/corefcn/module.mk: Update.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 19 Mar 2016 11:21:45 -0400 |
parents | 4fc04d04dd9c |
children | 20bf0ec536e2 |
rev | line source |
---|---|
2117 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2117 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2117 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2117 | 20 |
21 */ | |
22 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20465
diff
changeset
|
23 #if ! defined (octave_oct_stream_h) |
17822
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 | 25 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
27 |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
28 #include <iosfwd> |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
29 #include <list> |
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
30 #include <map> |
2877 | 31 #include <string> |
2117 | 32 |
21477
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
33 // These are only needed as arguments to private functions, so they |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
34 // are also treated as private. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
35 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
36 class scanf_format_elt; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
37 class scanf_format_list; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
38 |
21477
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
39 class printf_format_elt; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
40 class printf_format_list; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
41 |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
42 class delimited_stream; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
43 class textscan_format_elt; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
44 class textscan_format_list; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
45 |
21477
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
46 // These only appear as reference arguments or return values. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
47 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
48 template <typename T> class Array; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
49 class octave_value_list; |
21477
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
50 class string_vector; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
51 |
2317 | 52 #include "data-conv.h" |
53 #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
|
54 #include "oct-refcount.h" |
2117 | 55 |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
56 #include "Cell.h" |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
57 #include "ov.h" |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
58 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
59 // Main class to implement textscan. Read data and parse it |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
60 // according to a format. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
61 // |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
62 // The calling sequence is |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
63 // |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
64 // textscan scanner (); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
65 // scanner.scan (...); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
66 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
67 class |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
68 OCTINTERP_API |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
69 textscan |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
70 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
71 public: |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
72 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
73 textscan (void); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
74 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
75 ~textscan (void) { } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
76 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
77 octave_value scan (std::istream& isp, const octave_value_list& args); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
78 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
79 octave_value scan (std::istream& isp, const octave_value_list& args, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
80 octave_idx_type& count); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
81 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
82 private: |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
83 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
84 friend class textscan_format_list; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
85 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
86 std::string buf; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
87 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
88 // Three cases for delim_table and delim_list |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
89 // 1. delim_table empty, delim_list empty: whitespace delimiters |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
90 // 2. delim_table = look-up table of delim chars, delim_list empty. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
91 // 3. delim_table non-empty, delim_list = Cell array of delim strings |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
92 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
93 std::string whitespace_table; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
94 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
95 // delim_table[i] == '\0' if i is not a delimiter. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
96 std::string delim_table; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
97 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
98 // String of delimiter characters. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
99 std::string delims; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
100 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
101 Cell comment_style; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
102 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
103 // How far ahead to look to detect an open comment. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
104 int comment_len; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
105 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
106 // First character of open comment. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
107 int comment_char; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
108 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
109 octave_idx_type buffer_size; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
110 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
111 std::string date_locale; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
112 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
113 // 'inf' and 'nan' for formatted_double. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
114 Cell inf_nan; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
115 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
116 // Array of strings of delimiters. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
117 Cell delim_list; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
118 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
119 // Longest delimiter. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
120 int delim_len; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
121 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
122 octave_value empty_value; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
123 std::string exp_chars; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
124 int header_lines; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
125 Cell treat_as_empty; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
126 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
127 // Longest string to treat as "N/A". |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
128 int treat_as_empty_len; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
129 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
130 std::string whitespace; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
131 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
132 short eol1; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
133 short eol2; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
134 short return_on_error; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
135 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
136 bool collect_output; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
137 bool multiple_delims_as_one; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
138 bool default_exp; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
139 bool numeric_delim; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
140 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
141 octave_idx_type lines; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
142 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
143 octave_value do_scan (std::istream& isp, textscan_format_list& fmt_list, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
144 octave_idx_type ntimes); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
145 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
146 void parse_options (const octave_value_list& args, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
147 textscan_format_list& fmt_list); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
148 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
149 int read_format_once (delimited_stream& isp, textscan_format_list& fmt_list, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
150 std::list<octave_value>& retval, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
151 Array<octave_idx_type> row, int& done_after); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
152 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
153 void scan_one (delimited_stream& is, const textscan_format_elt& fmt, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
154 octave_value& ov, Array<octave_idx_type> row); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
155 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
156 // Methods to process a particular conversion specifier. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
157 double read_double (delimited_stream& is, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
158 const textscan_format_elt& fmt) const; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
159 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
160 void scan_complex (delimited_stream& is, const textscan_format_elt& fmt, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
161 Complex& val) const; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
162 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
163 int scan_bracket (delimited_stream& is, const std::string& pattern, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
164 std::string& val) const; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
165 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
166 int scan_caret (delimited_stream& is, const std::string& pattern, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
167 std::string& val) const; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
168 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
169 void scan_string (delimited_stream& is, const textscan_format_elt& fmt, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
170 std::string& val) const; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
171 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
172 void scan_cstring (delimited_stream& is, const textscan_format_elt& fmt, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
173 std::string& val) const; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
174 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
175 void scan_qstring (delimited_stream& is, const textscan_format_elt& fmt, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
176 std::string& val); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
177 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
178 // Helper methods. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
179 std::string read_until (delimited_stream& is, const Cell& delimiters, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
180 const std::string& ends) const; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
181 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
182 int lookahead (delimited_stream& is, const Cell& targets, int max_len, |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
183 bool case_sensitive = true) const; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
184 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
185 bool match_literal (delimited_stream& isp, const textscan_format_elt& elem); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
186 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
187 int skip_whitespace (delimited_stream& is, bool EOLstop = false); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
188 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
189 int skip_delim (delimited_stream& is); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
190 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
191 bool is_delim (unsigned char ch) const |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
192 { |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
193 return ((delim_table.empty () && (isspace (ch) || ch == eol1 || ch == eol2)) |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
194 || delim_table[ch] != '\0'); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
195 } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
196 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
197 bool isspace (unsigned int ch) const { return whitespace_table[ch & 0xff]; } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
198 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
199 // True if the only delimiter is whitespace. |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
200 bool whitespace_delim (void) const { return delim_table.empty (); } |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
201 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
202 // No copying! |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
203 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
204 textscan (const textscan&); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
205 |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
206 textscan& operator = (const textscan&); |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
207 }; |
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
208 |
2117 | 209 // Provide an interface for Octave streams. |
210 | |
211 class | |
6109 | 212 OCTINTERP_API |
2117 | 213 octave_base_stream |
214 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
215 friend class octave_stream; |
2117 | 216 |
217 public: | |
218 | |
3544 | 219 octave_base_stream (std::ios::openmode arg_md = std::ios::in|std::ios::out, |
10313 | 220 oct_mach_info::float_format ff |
221 = 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
|
222 : 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
|
223 errmsg () |
3340 | 224 { } |
2117 | 225 |
226 virtual ~octave_base_stream (void) { } | |
227 | |
228 // The remaining functions are not specific to input or output only, | |
229 // and must be provided by the derived classes. | |
230 | |
231 // Position a stream at OFFSET relative to ORIGIN. | |
232 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
233 virtual int seek (off_t offset, int origin) = 0; |
2117 | 234 |
235 // Return current stream position. | |
236 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
237 virtual off_t tell (void) = 0; |
2117 | 238 |
3340 | 239 // Return TRUE if EOF has been reached on this stream. |
2117 | 240 |
241 virtual bool eof (void) const = 0; | |
242 | |
243 // The name of the file. | |
244 | |
3523 | 245 virtual std::string name (void) const = 0; |
2117 | 246 |
247 // If the derived class provides this function and it returns a | |
248 // pointer to a valid istream, scanf(), read(), getl(), and gets() | |
249 // will automatically work for this stream. | |
250 | |
3523 | 251 virtual std::istream *input_stream (void) { return 0; } |
2117 | 252 |
253 // If the derived class provides this function and it returns a | |
254 // pointer to a valid ostream, flush(), write(), and printf() will | |
255 // automatically work for this stream. | |
256 | |
3523 | 257 virtual std::ostream *output_stream (void) { return 0; } |
2117 | 258 |
3340 | 259 // Return TRUE if this stream is open. |
260 | |
261 bool is_open (void) const { return open_state; } | |
262 | |
3652 | 263 virtual void do_close (void) { } |
264 | |
265 void close (void) | |
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 if (is_open ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
268 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
269 open_state = false; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
270 do_close (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
271 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
272 } |
3340 | 273 |
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
|
274 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
|
275 { |
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
|
276 // 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
|
277 |
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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 } |
3145 | 287 |
2117 | 288 bool ok (void) const { return ! fail; } |
289 | |
290 // Return current error message for this stream. | |
291 | |
3523 | 292 std::string error (bool clear, int& err_num); |
2117 | 293 |
294 protected: | |
295 | |
3340 | 296 int mode (void) const { return md; } |
2117 | 297 |
3340 | 298 oct_mach_info::float_format float_format (void) const { return flt_fmt; } |
2117 | 299 |
300 // Set current error state and set fail to TRUE. | |
301 | |
3523 | 302 void error (const std::string& msg); |
4468 | 303 void error (const std::string& who, const std::string& msg); |
2117 | 304 |
305 // Clear any error message and set fail to FALSE. | |
306 | |
307 void clear (void); | |
308 | |
4889 | 309 // Clear stream state. |
310 | |
311 void clearerr (void); | |
312 | |
2117 | 313 private: |
314 | |
3340 | 315 // A reference count. |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13983
diff
changeset
|
316 octave_refcount<octave_idx_type> count; |
3340 | 317 |
2117 | 318 // The permission bits for the file. Should be some combination of |
3544 | 319 // std::ios::open_mode bits. |
2117 | 320 int md; |
321 | |
322 // Data format. | |
2317 | 323 oct_mach_info::float_format flt_fmt; |
2117 | 324 |
325 // TRUE if an error has occurred. | |
326 bool fail; | |
327 | |
3340 | 328 // TRUE if this stream is open. |
329 bool open_state; | |
330 | |
2117 | 331 // Should contain error message if fail is TRUE. |
3523 | 332 std::string errmsg; |
2117 | 333 |
334 // Functions that are defined for all input streams (input streams | |
335 // are those that define is). | |
336 | |
5275 | 337 std::string do_gets (octave_idx_type max_len, bool& err, bool strip_newline, |
10313 | 338 const std::string& who /* = "gets" */); |
2117 | 339 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
340 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
|
341 const std::string& who /* = "getl" */); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
342 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
|
343 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
|
344 off_t skipl (off_t count, bool& err, const std::string& who /* = "skipl" */); |
2117 | 345 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
346 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
|
347 octave_idx_type nc, |
10313 | 348 bool one_elt_size_spec, octave_idx_type& count, |
349 const std::string& who /* = "scanf" */); | |
2117 | 350 |
4468 | 351 octave_value scanf (const std::string& fmt, const Array<double>& size, |
10313 | 352 octave_idx_type& count, const std::string& who /* = "scanf" */); |
2117 | 353 |
4468 | 354 bool do_oscanf (const scanf_format_elt *elt, octave_value&, |
10313 | 355 const std::string& who /* = "scanf" */); |
2117 | 356 |
4468 | 357 octave_value_list oscanf (const std::string& fmt, |
10313 | 358 const std::string& who /* = "scanf" */); |
2215 | 359 |
2117 | 360 // Functions that are defined for all output streams (output streams |
361 // are those that define os). | |
362 | |
363 int flush (void); | |
364 | |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
365 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
|
366 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
|
367 const octave_value& val, |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
368 const std::string& who); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
369 |
4468 | 370 int do_printf (printf_format_list& fmt_list, const octave_value_list& args, |
10313 | 371 const std::string& who /* = "printf" */); |
2117 | 372 |
4468 | 373 int printf (const std::string& fmt, const octave_value_list& args, |
10313 | 374 const std::string& who /* = "printf" */); |
2117 | 375 |
4468 | 376 int puts (const std::string& s, const std::string& who /* = "puts" */); |
2117 | 377 |
378 // We can always do this in terms of seek(), so the derived class | |
379 // only has to provide that. | |
380 | |
4468 | 381 void invalid_operation (const std::string& who, const char *rw); |
2117 | 382 |
383 // No copying! | |
384 | |
385 octave_base_stream (const octave_base_stream&); | |
386 | |
387 octave_base_stream& operator = (const octave_base_stream&); | |
388 }; | |
389 | |
390 class | |
6109 | 391 OCTINTERP_API |
2117 | 392 octave_stream |
393 { | |
394 public: | |
395 | |
3340 | 396 octave_stream (octave_base_stream *bs = 0); |
397 | |
398 ~octave_stream (void); | |
2117 | 399 |
3340 | 400 octave_stream (const octave_stream&); |
401 | |
402 octave_stream& operator = (const octave_stream&); | |
2117 | 403 |
404 int flush (void); | |
405 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
406 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
|
407 const std::string& who /* = "getl" */); |
4468 | 408 std::string getl (const octave_value& max_len, bool& err, |
10313 | 409 const std::string& who /* = "getl" */); |
2117 | 410 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
411 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
|
412 const std::string& who /* = "gets" */); |
4468 | 413 std::string gets (const octave_value& max_len, bool& err, |
10313 | 414 const std::string& who /* = "gets" */); |
2117 | 415 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
416 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
|
417 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
|
418 const std::string& who /* = "skipl" */); |
9701 | 419 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
420 int seek (off_t offset, int origin); |
2117 | 421 int seek (const octave_value& offset, const octave_value& origin); |
422 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
423 off_t tell (void); |
2117 | 424 |
425 int rewind (void); | |
426 | |
3340 | 427 bool is_open (void) const; |
428 | |
429 void close (void); | |
430 | |
5275 | 431 octave_value read (const Array<double>& size, octave_idx_type block_size, |
10313 | 432 oct_data_conv::data_type input_type, |
433 oct_data_conv::data_type output_type, | |
434 octave_idx_type skip, oct_mach_info::float_format flt_fmt, | |
435 octave_idx_type& count); | |
2117 | 436 |
5275 | 437 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
|
438 oct_data_conv::data_type output_type, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
439 octave_idx_type skip, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
440 oct_mach_info::float_format flt_fmt); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
441 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
442 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
|
443 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
444 bool skip_bytes (size_t n_elts); |
4944 | 445 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
446 template <typename T> |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
447 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
|
448 oct_data_conv::data_type output_type, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
449 octave_idx_type skip, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
450 oct_mach_info::float_format flt_fmt); |
2117 | 451 |
4468 | 452 octave_value scanf (const std::string& fmt, const Array<double>& size, |
10313 | 453 octave_idx_type& count, const std::string& who /* = "scanf" */); |
2117 | 454 |
5279 | 455 octave_value scanf (const octave_value& fmt, const Array<double>& size, |
10313 | 456 octave_idx_type& count, const std::string& who /* = "scanf" */); |
5279 | 457 |
4468 | 458 octave_value_list oscanf (const std::string& fmt, |
10313 | 459 const std::string& who /* = "scanf" */); |
2215 | 460 |
5279 | 461 octave_value_list oscanf (const octave_value& fmt, |
10313 | 462 const std::string& who /* = "scanf" */); |
5279 | 463 |
4468 | 464 int printf (const std::string& fmt, const octave_value_list& args, |
10313 | 465 const std::string& who /* = "printf" */); |
2117 | 466 |
5279 | 467 int printf (const octave_value& fmt, const octave_value_list& args, |
10313 | 468 const std::string& who /* = "printf" */); |
5279 | 469 |
4468 | 470 int puts (const std::string& s, const std::string& who /* = "puts" */); |
471 int puts (const octave_value& s, const std::string& who /* = "puts" */); | |
2117 | 472 |
473 bool eof (void) const; | |
474 | |
3523 | 475 std::string error (bool clear, int& err_num); |
2117 | 476 |
3523 | 477 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
|
478 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
479 int err_num; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
480 return error (clear, err_num); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
481 } |
2117 | 482 |
4799 | 483 // Set the error message and state. |
484 | |
485 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
|
486 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
487 if (rep) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
488 rep->error (msg); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
489 } |
4799 | 490 |
491 void error (const char *msg) { error (std::string (msg)); } | |
492 | |
3148 | 493 int file_number (void) { return rep ? rep->file_number () : -1; } |
3145 | 494 |
3340 | 495 bool is_valid (void) const { return (rep != 0); } |
496 | |
2117 | 497 bool ok (void) const { return rep && rep->ok (); } |
498 | |
3145 | 499 operator bool () const { return ok (); } |
2117 | 500 |
3523 | 501 std::string name (void) const; |
2117 | 502 |
3340 | 503 int mode (void) const; |
2117 | 504 |
3340 | 505 oct_mach_info::float_format float_format (void) const; |
2117 | 506 |
3523 | 507 static std::string mode_as_string (int mode); |
2117 | 508 |
6757 | 509 std::istream *input_stream (void) |
510 { | |
511 return rep ? rep->input_stream () : 0; | |
512 } | |
2902 | 513 |
6757 | 514 std::ostream *output_stream (void) |
515 { | |
516 return rep ? rep->output_stream () : 0; | |
517 } | |
16099
4b6c44096862
Backout changeset 238e499c5fea (locale support in scanf)
Rik <rik@octave.org>
parents:
16011
diff
changeset
|
518 |
4889 | 519 void clearerr (void) { if (rep) rep->clearerr (); } |
520 | |
2117 | 521 private: |
522 | |
523 // The actual representation of this stream. | |
524 octave_base_stream *rep; | |
525 | |
5659 | 526 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
|
527 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
528 bool retval = true; |
5659 | 529 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
530 if (rep) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
531 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
532 if (clear) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
533 rep->clear (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
534 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
535 else |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
536 retval = false; |
5659 | 537 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
538 return retval; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
539 } |
4944 | 540 |
541 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
|
542 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
543 if (rep) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
544 rep->invalid_operation (who, rw); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
545 } |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
546 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
547 octave_value |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
548 finalize_read (std::list<void *>& input_buf_list, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
549 octave_idx_type input_buf_elts, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
550 octave_idx_type elts_read, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
551 octave_idx_type nr, octave_idx_type nc, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
552 oct_data_conv::data_type input_type, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
553 oct_data_conv::data_type output_type, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
554 oct_mach_info::float_format ffmt); |
2117 | 555 }; |
556 | |
557 class | |
6109 | 558 OCTINTERP_API |
2117 | 559 octave_stream_list |
560 { | |
561 protected: | |
562 | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
563 octave_stream_list (void) : list (), lookup_cache (list.end ()) { } |
2117 | 564 |
565 public: | |
566 | |
567 ~octave_stream_list (void) { } | |
568 | |
2926 | 569 static bool instance_ok (void); |
570 | |
6757 | 571 static int insert (octave_stream& os); |
2117 | 572 |
4468 | 573 static octave_stream |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
574 lookup (int fid, const std::string& who = ""); |
4468 | 575 |
576 static octave_stream | |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
577 lookup (const octave_value& fid, const std::string& who = ""); |
2117 | 578 |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
579 static int remove (int fid, const std::string& who = ""); |
3341 | 580 static int remove (const octave_value& fid, |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
581 const std::string& who = ""); |
2117 | 582 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
583 static void clear (bool flush = true); |
2117 | 584 |
585 static string_vector get_info (int fid); | |
586 static string_vector get_info (const octave_value& fid); | |
587 | |
3523 | 588 static std::string list_open_files (void); |
2117 | 589 |
590 static octave_value open_file_numbers (void); | |
591 | |
2609 | 592 static int get_file_number (const octave_value& fid); |
593 | |
2117 | 594 private: |
595 | |
6757 | 596 typedef std::map<int, octave_stream> ostrl_map; |
2117 | 597 |
6757 | 598 ostrl_map list; |
2117 | 599 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
600 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
|
601 |
2117 | 602 static octave_stream_list *instance; |
603 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
604 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
|
605 |
6757 | 606 int do_insert (octave_stream& os); |
2117 | 607 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
608 octave_stream do_lookup (int fid, |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
609 const std::string& who = "") const; |
3341 | 610 octave_stream do_lookup (const octave_value& fid, |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
611 const std::string& who = "") const; |
2117 | 612 |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
613 int do_remove (int fid, const std::string& who = ""); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
614 int do_remove (const octave_value& fid, |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
615 const std::string& who = ""); |
2117 | 616 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
617 void do_clear (bool flush = true); |
2117 | 618 |
619 string_vector do_get_info (int fid) const; | |
620 string_vector do_get_info (const octave_value& fid) const; | |
621 | |
3523 | 622 std::string do_list_open_files (void) const; |
2117 | 623 |
624 octave_value do_open_file_numbers (void) const; | |
625 | |
2609 | 626 int do_get_file_number (const octave_value& fid) const; |
2117 | 627 }; |
628 | |
629 #endif |