comparison libinterp/corefcn/ls-oct-text.h @ 20657:c6224b4e7774

maint: Rename instances of LS_ASCII to LS_TEXT for clarity. Octave's default save format is '-text' which is confusingly referred to in the code base as LS_ASCII (looks like '-ascii' mode). * ls-oct-text.cc, ls-oct-text.h: Renamed from ls-oct-ascii.[cc|h]. * ls-oct-ascii.cc, ls-oct-ascii.h: Removed files. * libinterp/corefcn/module.mk: Add ls-oct-text.cc, ls-oct-text.h to build system. * load-save.h (load_save_format_type): Change first value of enum from LS_ASCII to LS_TEXT. * load-save.cc: Rename instances of LS_ASCII to LS_TEXT. Rename instances of read_ascii_data to read_text_data. * ov-base-diag.cc, ov-base-int.cc, ov-base-sparse.cc, ov-bool-mat.cc, ov-bool.cc, ov-complex.cc, ov-cx-mat.cc ov-fcn-inline.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-int16.cc, ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-perm.cc, ov-re-mat.cc, ov-scalar.cc, ov-str-mat.cc, ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc: Use '#include "ls-oct-text.h"' rather than ls-oct-ascii.h. ov-cell.cc, ov-class.cc, ov-fcn-handle.cc, ov-lazy-idx.cc, ov-struct.cc: Use '#include "ls-oct-text.h"' rather than ls-oct-ascii.h. Rename save_ascii_data to save_text_data, read_ascii_data to read_text_data.
author Rik <rik@octave.org>
date Mon, 17 Aug 2015 09:20:03 -0700
parents libinterp/corefcn/ls-oct-ascii.h@a9574e3c6e9e
children
comparison
equal deleted inserted replaced
20654:ab2c5e84954a 20657:c6224b4e7774
1 /*
2
3 Copyright (C) 2003-2015 John W. Eaton
4
5 This file is part of Octave.
6
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20
21 */
22
23 #if !defined (octave_ls_oct_text_h)
24 #define octave_ls_oct_text_h 1
25
26 #include <cfloat>
27
28 #include <sstream>
29 #include <string>
30
31 #include "str-vec.h"
32
33 #include "ls-ascii-helper.h"
34
35 // Flag for cell elements
36 #define CELL_ELT_TAG "<cell-element>"
37
38 // Used when converting Inf to something that gnuplot can read.
39
40 #ifndef OCT_RBV
41 #define OCT_RBV (std::numeric_limits<double>::max () / 100.0)
42 #endif
43
44 extern OCTINTERP_API std::string
45 extract_keyword (std::istream& is, const char *keyword,
46 const bool next_only = false);
47
48 extern OCTINTERP_API std::string
49 read_text_data (std::istream& is, const std::string& filename, bool& global,
50 octave_value& tc, octave_idx_type count);
51
52 extern OCTINTERP_API bool
53 save_text_data (std::ostream& os, const octave_value& val_arg,
54 const std::string& name, bool mark_as_global, int precision);
55
56 extern OCTINTERP_API bool
57 save_text_data_for_plotting (std::ostream& os, const octave_value& t,
58 const std::string& name);
59
60 extern OCTINTERP_API bool
61 save_three_d (std::ostream& os, const octave_value& t,
62 bool parametric = false);
63
64 // Match KEYWORD on stream IS, placing the associated value in VALUE,
65 // returning TRUE if successful and FALSE otherwise.
66 //
67 // Input should look something like:
68 //
69 // [%#][ \t]*keyword[ \t]*int-value.*\n
70
71 template <class T>
72 bool
73 extract_keyword (std::istream& is, const char *keyword, T& value,
74 const bool next_only = false)
75 {
76 bool status = false;
77 value = T ();
78
79 char c;
80 while (is.get (c))
81 {
82 if (c == '%' || c == '#')
83 {
84 std::ostringstream buf;
85
86 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#'))
87 ; // Skip whitespace and comment characters.
88
89 if (isalpha (c))
90 buf << c;
91
92 while (is.get (c) && isalpha (c))
93 buf << c;
94
95 std::string tmp = buf.str ();
96 bool match = (tmp.compare (0, strlen (keyword), keyword) == 0);
97
98 if (match)
99 {
100 while (is.get (c) && (c == ' ' || c == '\t' || c == ':'))
101 ; // Skip whitespace and the colon.
102
103 is.putback (c);
104 if (c != '\n' && c != '\r')
105 is >> value;
106 if (is)
107 status = true;
108 skip_until_newline (is, false);
109 break;
110 }
111 else if (next_only)
112 break;
113 }
114 }
115 return status;
116 }
117
118 template <class T>
119 bool
120 extract_keyword (std::istream& is, const std::string& kw, T& value,
121 const bool next_only = false)
122 {
123 return extract_keyword (is, kw.c_str (), value, next_only);
124 }
125
126 // Match one of the elements in KEYWORDS on stream IS, placing the
127 // matched keyword in KW and the associated value in VALUE,
128 // returning TRUE if successful and FALSE otherwise.
129 //
130 // Input should look something like:
131 //
132 // [%#][ \t]*keyword[ \t]*int-value.*\n
133
134 template <class T>
135 bool
136 extract_keyword (std::istream& is, const string_vector& keywords,
137 std::string& kw, T& value, const bool next_only = false)
138 {
139 bool status = false;
140 kw = "";
141 value = 0;
142
143 char c;
144 while (is.get (c))
145 {
146 if (c == '%' || c == '#')
147 {
148 std::ostringstream buf;
149
150 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#'))
151 ; // Skip whitespace and comment characters.
152
153 if (isalpha (c))
154 buf << c;
155
156 while (is.get (c) && isalpha (c))
157 buf << c;
158
159 std::string tmp = buf.str ();
160
161 for (int i = 0; i < keywords.numel (); i++)
162 {
163 int match = (tmp == keywords[i]);
164
165 if (match)
166 {
167 kw = keywords[i];
168
169 while (is.get (c) && (c == ' ' || c == '\t' || c == ':'))
170 ; // Skip whitespace and the colon.
171
172 is.putback (c);
173 if (c != '\n' && c != '\r')
174 is >> value;
175 if (is)
176 status = true;
177 skip_until_newline (is, false);
178 return status;
179 }
180 }
181
182 if (next_only)
183 break;
184 }
185 }
186 return status;
187 }
188
189 #endif