Mercurial > octave-nkf
annotate libinterp/octave-value/ov-fcn-inline.cc @ 20615:729a85dafba8
use new string_value method to handle value extraction errors
* ov-class.cc, ov-classdef.cc, ov-fcn-handle.cc, ov-fcn-inline.cc,
ov.cc, pt-idx.cc: Use new string_value method.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 08 Oct 2015 17:55:57 -0400 |
parents | f90c8372b7ba |
children |
rev | line source |
---|---|
4933 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19632
diff
changeset
|
3 Copyright (C) 2004-2015 David Bateman |
4933 | 4 |
7016 | 5 This file is part of Octave. |
4933 | 6 |
7016 | 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. | |
4933 | 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/>. | |
4933 | 20 |
21 In addition to the terms of the GPL, you are permitted to link | |
22 this program with any Open Source program, as defined by the | |
23 Open Source Initiative (www.opensource.org) | |
24 | |
25 */ | |
26 | |
27 #ifdef HAVE_CONFIG_H | |
28 #include <config.h> | |
29 #endif | |
30 | |
4988 | 31 #include <istream> |
4933 | 32 #include <iostream> |
5765 | 33 #include <sstream> |
5164 | 34 #include <vector> |
4933 | 35 |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8045
diff
changeset
|
36 #include "oct-locbuf.h" |
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8045
diff
changeset
|
37 |
4933 | 38 #include "defun.h" |
39 #include "error.h" | |
40 #include "gripes.h" | |
19897
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
41 #include "oct-hdf5.h" |
4933 | 42 #include "oct-map.h" |
43 #include "ov-base.h" | |
44 #include "ov-fcn-inline.h" | |
8032
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7908
diff
changeset
|
45 #include "ov-usr-fcn.h" |
4933 | 46 #include "pr-output.h" |
47 #include "variables.h" | |
48 #include "parse.h" | |
8032
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7908
diff
changeset
|
49 #include "toplev.h" |
4933 | 50 |
4972 | 51 #include "byte-swap.h" |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
52 #include "ls-ascii-helper.h" |
20482
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20267
diff
changeset
|
53 #include "ls-oct-text.h" |
4972 | 54 #include "ls-hdf5.h" |
55 #include "ls-utils.h" | |
56 | |
4933 | 57 |
58 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fcn_inline, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
59 "inline function", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
60 "function_handle"); |
4933 | 61 |
62 octave_fcn_inline::octave_fcn_inline (const std::string& f, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
63 const string_vector& a, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
64 const std::string& n) |
5007 | 65 : octave_fcn_handle (n), iftext (f), ifargs (a) |
4933 | 66 { |
4973 | 67 // Form a string representing the function. |
4933 | 68 |
5765 | 69 std::ostringstream buf; |
4933 | 70 |
5007 | 71 buf << "@("; |
4933 | 72 |
20267
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20198
diff
changeset
|
73 for (int i = 0; i < ifargs.numel (); i++) |
4933 | 74 { |
75 if (i > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
76 buf << ", "; |
4933 | 77 |
78 buf << ifargs(i); | |
79 } | |
80 | |
5765 | 81 buf << ") " << iftext; |
4933 | 82 |
5007 | 83 int parse_status; |
5765 | 84 octave_value anon_fcn_handle = eval_string (buf.str (), true, parse_status); |
4933 | 85 |
5007 | 86 if (parse_status == 0) |
4933 | 87 { |
5007 | 88 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); |
4933 | 89 |
5007 | 90 if (fh) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
91 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
92 fcn = fh->fcn_val (); |
8032
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7908
diff
changeset
|
93 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
94 octave_user_function *uf = fcn.user_function_value (); |
8032
2fd4a5ef6b59
stash parent function scope for inline functions and anonymous function handles.
John W. Eaton <jwe@octave.org>
parents:
7908
diff
changeset
|
95 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
96 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
97 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
98 octave_function *curr_fcn = octave_call_stack::current (); |
8045
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
99 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
100 if (curr_fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
101 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
102 symbol_table::scope_id parent_scope |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
103 = curr_fcn->parent_fcn_scope (); |
8045
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
104 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
105 if (parent_scope < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
106 parent_scope = curr_fcn->scope (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
107 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
108 uf->stash_parent_fcn_scope (parent_scope); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
109 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
110 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
111 } |
4933 | 112 } |
5007 | 113 |
114 if (fcn.is_undefined ()) | |
4933 | 115 error ("inline: unable to define function"); |
116 } | |
117 | |
6625 | 118 // This function is supplied to allow a Matlab style class structure |
119 // to be returned.. | |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
120 octave_map |
6625 | 121 octave_fcn_inline::map_value (void) const |
122 { | |
11070
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
123 octave_scalar_map m; |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
124 |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
125 m.assign ("version", 1.0); |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
126 m.assign ("isEmpty", 0.0); |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
127 m.assign ("expr", fcn_text ()); |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
128 |
6625 | 129 string_vector args = fcn_arg_names (); |
11070
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
130 |
20267
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20198
diff
changeset
|
131 m.assign ("numArgs", args.numel ()); |
11070
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
132 m.assign ("args", args); |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
133 |
6625 | 134 std::ostringstream buf; |
11070
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
135 |
20267
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20198
diff
changeset
|
136 for (int i = 0; i < args.numel (); i++) |
6625 | 137 buf << args(i) << " = INLINE_INPUTS_{" << i + 1 << "}; "; |
11070
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
138 |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
139 m.assign ("inputExpr", buf.str ()); |
6625 | 140 |
141 return m; | |
142 } | |
143 | |
4972 | 144 bool |
6974 | 145 octave_fcn_inline::save_ascii (std::ostream& os) |
4972 | 146 { |
20267
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20198
diff
changeset
|
147 os << "# nargs: " << ifargs.numel () << "\n"; |
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20198
diff
changeset
|
148 for (int i = 0; i < ifargs.numel (); i++) |
4973 | 149 os << ifargs(i) << "\n"; |
150 if (nm.length () < 1) | |
151 // Write an invalid value to flag empty fcn handle name. | |
4972 | 152 os << "0\n"; |
153 else | |
154 os << nm << "\n"; | |
155 os << iftext << "\n"; | |
156 return true; | |
157 } | |
158 | |
159 bool | |
160 octave_fcn_inline::load_ascii (std::istream& is) | |
161 { | |
162 int nargs; | |
163 if (extract_keyword (is, "nargs", nargs, true)) | |
164 { | |
165 ifargs.resize (nargs); | |
166 for (int i = 0; i < nargs; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
167 is >> ifargs(i); |
4972 | 168 is >> nm; |
169 if (nm == "0") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
170 nm = ""; |
4988 | 171 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
172 skip_preceeding_newline (is); |
4988 | 173 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
174 std::string buf; |
4988 | 175 |
176 if (is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
177 { |
4988 | 178 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
179 // Get a line of text whitespace characters included, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
180 // leaving newline in the stream. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
181 buf = read_until_newline (is, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
182 } |
4988 | 183 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
184 iftext = buf; |
4972 | 185 |
186 octave_fcn_inline tmp (iftext, ifargs, nm); | |
187 fcn = tmp.fcn; | |
188 | |
189 return true; | |
190 } | |
191 else | |
192 return false; | |
193 } | |
194 | |
4973 | 195 bool |
4972 | 196 octave_fcn_inline::save_binary (std::ostream& os, bool&) |
197 { | |
20267
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20198
diff
changeset
|
198 int32_t tmp = ifargs.numel (); |
5760 | 199 os.write (reinterpret_cast<char *> (&tmp), 4); |
20267
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20198
diff
changeset
|
200 for (int i = 0; i < ifargs.numel (); i++) |
4972 | 201 { |
4973 | 202 tmp = ifargs(i).length (); |
5760 | 203 os.write (reinterpret_cast<char *> (&tmp), 4); |
4973 | 204 os.write (ifargs(i).c_str (), ifargs(i).length ()); |
4972 | 205 } |
4973 | 206 tmp = nm.length (); |
5760 | 207 os.write (reinterpret_cast<char *> (&tmp), 4); |
4973 | 208 os.write (nm.c_str (), nm.length ()); |
209 tmp = iftext.length (); | |
5760 | 210 os.write (reinterpret_cast<char *> (&tmp), 4); |
4973 | 211 os.write (iftext.c_str (), iftext.length ()); |
4972 | 212 return true; |
213 } | |
214 | |
4973 | 215 bool |
4972 | 216 octave_fcn_inline::load_binary (std::istream& is, bool swap, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
217 oct_mach_info::float_format) |
4972 | 218 { |
5828 | 219 int32_t nargs; |
5760 | 220 if (! is.read (reinterpret_cast<char *> (&nargs), 4)) |
4972 | 221 return false; |
222 if (swap) | |
223 swap_bytes<4> (&nargs); | |
224 | |
225 if (nargs < 1) | |
226 return false; | |
227 else | |
228 { | |
5828 | 229 int32_t tmp; |
4973 | 230 ifargs.resize (nargs); |
4972 | 231 for (int i = 0; i < nargs; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
232 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
233 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
234 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
235 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
236 swap_bytes<4> (&tmp); |
4972 | 237 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
238 OCTAVE_LOCAL_BUFFER (char, ctmp, tmp+1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
239 is.read (ctmp, tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
240 ifargs(i) = std::string (ctmp); |
4972 | 241 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
242 if (! is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
243 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
244 } |
4972 | 245 |
5760 | 246 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
247 return false; |
4972 | 248 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
249 swap_bytes<4> (&tmp); |
4972 | 250 |
251 OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1); | |
252 is.read (ctmp1, tmp); | |
253 nm = std::string (ctmp1); | |
254 | |
255 if (! is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
256 return false; |
4972 | 257 |
5760 | 258 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
259 return false; |
4972 | 260 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
261 swap_bytes<4> (&tmp); |
4972 | 262 |
263 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1); | |
264 is.read (ctmp2, tmp); | |
265 iftext = std::string (ctmp2); | |
266 | |
267 if (! is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
268 return false; |
4972 | 269 |
270 octave_fcn_inline ftmp (iftext, ifargs, nm); | |
271 fcn = ftmp.fcn; | |
272 } | |
273 return true; | |
274 } | |
275 | |
276 bool | |
19897
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
277 octave_fcn_inline::save_hdf5 (octave_hdf5_id loc_id, const char *name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
278 bool /* save_as_floats */) |
4972 | 279 { |
19897
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
280 bool retval = false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
281 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
282 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
283 |
4972 | 284 hid_t group_hid = -1; |
19897
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
285 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
286 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
287 group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
288 #else |
4972 | 289 group_hid = H5Gcreate (loc_id, name, 0); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
290 #endif |
18712
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18537
diff
changeset
|
291 if (group_hid < 0) return false; |
4972 | 292 |
293 size_t len = 0; | |
20267
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20198
diff
changeset
|
294 for (int i = 0; i < ifargs.numel (); i++) |
4973 | 295 if (len < ifargs(i).length ()) |
296 len = ifargs(i).length (); | |
4972 | 297 |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
298 hid_t space_hid, data_hid, type_hid; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
299 space_hid = data_hid = type_hid = -1; |
4972 | 300 |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
301 // FIXME: Is there a better way of saving string vectors, |
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
302 // than a null padded matrix? |
4972 | 303 |
304 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2); | |
305 | |
306 // Octave uses column-major, while HDF5 uses row-major ordering | |
20267
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20198
diff
changeset
|
307 hdims[1] = ifargs.numel (); |
4972 | 308 hdims[0] = len + 1; |
309 | |
310 space_hid = H5Screate_simple (2, hdims, 0); | |
311 if (space_hid < 0) | |
312 { | |
313 H5Gclose (group_hid); | |
314 return false; | |
315 } | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
316 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
317 data_hid = H5Dcreate (group_hid, "args", H5T_NATIVE_CHAR, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
318 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
319 #else |
4973 | 320 data_hid = H5Dcreate (group_hid, "args", H5T_NATIVE_CHAR, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
321 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
322 #endif |
4972 | 323 if (data_hid < 0) |
324 { | |
325 H5Sclose (space_hid); | |
326 H5Gclose (group_hid); | |
327 return false; | |
328 } | |
329 | |
20267
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20198
diff
changeset
|
330 OCTAVE_LOCAL_BUFFER (char, s, ifargs.numel () * (len + 1)); |
4972 | 331 |
332 // Save the args as a null teminated list | |
20267
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20198
diff
changeset
|
333 for (int i = 0; i < ifargs.numel (); i++) |
4972 | 334 { |
4973 | 335 const char * cptr = ifargs(i).c_str (); |
336 for (size_t j = 0; j < ifargs(i).length (); j++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
337 s[i*(len+1)+j] = *cptr++; |
4973 | 338 s[ifargs(i).length ()] = '\0'; |
4972 | 339 } |
340 | |
4973 | 341 retval = H5Dwrite (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
342 H5P_DEFAULT, s) >= 0; |
4972 | 343 |
344 H5Dclose (data_hid); | |
345 H5Sclose (space_hid); | |
346 | |
347 if (!retval) | |
348 { | |
349 H5Gclose (group_hid); | |
350 return false; | |
4973 | 351 } |
4972 | 352 |
353 // attach the type of the variable | |
4973 | 354 type_hid = H5Tcopy (H5T_C_S1); |
4972 | 355 H5Tset_size (type_hid, nm.length () + 1); |
356 if (type_hid < 0) | |
357 { | |
358 H5Gclose (group_hid); | |
359 return false; | |
4973 | 360 } |
4972 | 361 |
362 hdims[0] = 0; | |
5760 | 363 space_hid = H5Screate_simple (0 , hdims, 0); |
4972 | 364 if (space_hid < 0) |
365 { | |
366 H5Tclose (type_hid); | |
367 H5Gclose (group_hid); | |
368 return false; | |
4973 | 369 } |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
370 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
371 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
372 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
373 #else |
4972 | 374 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
375 #endif |
4973 | 376 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
377 H5P_DEFAULT, nm.c_str ()) < 0) |
4972 | 378 { |
379 H5Sclose (space_hid); | |
380 H5Tclose (type_hid); | |
381 H5Gclose (group_hid); | |
382 return false; | |
4973 | 383 } |
4972 | 384 H5Dclose (data_hid); |
385 | |
386 // attach the type of the variable | |
387 H5Tset_size (type_hid, iftext.length () + 1); | |
388 if (type_hid < 0) | |
389 { | |
390 H5Gclose (group_hid); | |
391 return false; | |
4973 | 392 } |
4972 | 393 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
394 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
395 data_hid = H5Dcreate (group_hid, "iftext", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
396 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
397 #else |
4973 | 398 data_hid = H5Dcreate (group_hid, "iftext", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
399 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
400 #endif |
4973 | 401 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
402 H5P_DEFAULT, iftext.c_str ()) < 0) |
4972 | 403 { |
404 H5Sclose (space_hid); | |
405 H5Tclose (type_hid); | |
406 H5Gclose (group_hid); | |
407 return false; | |
4973 | 408 } |
4972 | 409 |
410 H5Dclose (data_hid); | |
4988 | 411 H5Sclose (space_hid); |
412 H5Tclose (type_hid); | |
413 H5Gclose (group_hid); | |
4972 | 414 |
19897
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
415 #else |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
416 gripe_save ("hdf5"); |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
417 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
418 |
4972 | 419 return retval; |
420 } | |
421 | |
422 bool | |
19897
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
423 octave_fcn_inline::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4972 | 424 { |
19897
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
425 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
426 |
4972 | 427 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id; |
428 hsize_t rank; | |
429 int slen; | |
430 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
431 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
432 group_hid = H5Gopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
433 #else |
4972 | 434 group_hid = H5Gopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
435 #endif |
18712
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18537
diff
changeset
|
436 if (group_hid < 0) return false; |
4972 | 437 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
438 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
439 data_hid = H5Dopen (group_hid, "args", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
440 #else |
4972 | 441 data_hid = H5Dopen (group_hid, "args"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
442 #endif |
4972 | 443 space_hid = H5Dget_space (data_hid); |
444 rank = H5Sget_simple_extent_ndims (space_hid); | |
445 | |
446 if (rank != 2) | |
4973 | 447 { |
4972 | 448 H5Dclose (data_hid); |
449 H5Sclose (space_hid); | |
450 H5Gclose (group_hid); | |
451 return false; | |
452 } | |
453 | |
454 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
455 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
456 | |
457 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
458 | |
4973 | 459 ifargs.resize (hdims[1]); |
4972 | 460 |
461 OCTAVE_LOCAL_BUFFER (char, s1, hdims[0] * hdims[1]); | |
462 | |
4973 | 463 if (H5Dread (data_hid, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
464 H5P_DEFAULT, s1) < 0) |
4973 | 465 { |
4972 | 466 H5Dclose (data_hid); |
467 H5Sclose (space_hid); | |
468 H5Gclose (group_hid); | |
469 return false; | |
470 } | |
471 | |
472 H5Dclose (data_hid); | |
473 H5Sclose (space_hid); | |
474 | |
475 for (size_t i = 0; i < hdims[1]; i++) | |
476 ifargs(i) = std::string (s1 + i*hdims[0]); | |
477 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
478 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
479 data_hid = H5Dopen (group_hid, "nm", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
480 #else |
4972 | 481 data_hid = H5Dopen (group_hid, "nm"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
482 #endif |
4972 | 483 |
484 if (data_hid < 0) | |
485 { | |
486 H5Gclose (group_hid); | |
487 return false; | |
488 } | |
489 | |
490 type_hid = H5Dget_type (data_hid); | |
491 type_class_hid = H5Tget_class (type_hid); | |
492 | |
493 if (type_class_hid != H5T_STRING) | |
494 { | |
495 H5Tclose (type_hid); | |
496 H5Dclose (data_hid); | |
497 H5Gclose (group_hid); | |
498 return false; | |
499 } | |
4973 | 500 |
4972 | 501 space_hid = H5Dget_space (data_hid); |
502 rank = H5Sget_simple_extent_ndims (space_hid); | |
503 | |
504 if (rank != 0) | |
505 { | |
506 H5Sclose (space_hid); | |
507 H5Tclose (type_hid); | |
508 H5Dclose (data_hid); | |
509 H5Gclose (group_hid); | |
510 return false; | |
511 } | |
512 | |
513 slen = H5Tget_size (type_hid); | |
514 if (slen < 0) | |
515 { | |
516 H5Sclose (space_hid); | |
517 H5Tclose (type_hid); | |
518 H5Dclose (data_hid); | |
519 H5Gclose (group_hid); | |
520 return false; | |
521 } | |
522 | |
523 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen); | |
524 | |
525 // create datatype for (null-terminated) string to read into: | |
526 st_id = H5Tcopy (H5T_C_S1); | |
527 H5Tset_size (st_id, slen); | |
528 | |
5760 | 529 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, nm_tmp) < 0) |
4972 | 530 { |
531 H5Sclose (space_hid); | |
532 H5Tclose (type_hid); | |
533 H5Gclose (group_hid); | |
534 return false; | |
535 } | |
536 H5Tclose (st_id); | |
537 H5Dclose (data_hid); | |
538 nm = nm_tmp; | |
539 | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
540 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
541 data_hid = H5Dopen (group_hid, "iftext", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
542 #else |
4972 | 543 data_hid = H5Dopen (group_hid, "iftext"); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
544 #endif |
4972 | 545 |
546 if (data_hid < 0) | |
547 { | |
548 H5Gclose (group_hid); | |
549 return false; | |
550 } | |
551 | |
552 type_hid = H5Dget_type (data_hid); | |
553 type_class_hid = H5Tget_class (type_hid); | |
554 | |
555 if (type_class_hid != H5T_STRING) | |
556 { | |
557 H5Tclose (type_hid); | |
558 H5Dclose (data_hid); | |
559 H5Gclose (group_hid); | |
560 return false; | |
561 } | |
4973 | 562 |
4972 | 563 space_hid = H5Dget_space (data_hid); |
564 rank = H5Sget_simple_extent_ndims (space_hid); | |
565 | |
566 if (rank != 0) | |
567 { | |
568 H5Sclose (space_hid); | |
569 H5Tclose (type_hid); | |
570 H5Dclose (data_hid); | |
571 H5Gclose (group_hid); | |
572 return false; | |
573 } | |
574 | |
575 slen = H5Tget_size (type_hid); | |
576 if (slen < 0) | |
577 { | |
578 H5Sclose (space_hid); | |
579 H5Tclose (type_hid); | |
580 H5Dclose (data_hid); | |
581 H5Gclose (group_hid); | |
582 return false; | |
583 } | |
584 | |
585 OCTAVE_LOCAL_BUFFER (char, iftext_tmp, slen); | |
586 | |
587 // create datatype for (null-terminated) string to read into: | |
588 st_id = H5Tcopy (H5T_C_S1); | |
589 H5Tset_size (st_id, slen); | |
590 | |
5760 | 591 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, iftext_tmp) < 0) |
4972 | 592 { |
593 H5Sclose (space_hid); | |
594 H5Tclose (type_hid); | |
595 H5Gclose (group_hid); | |
596 return false; | |
597 } | |
598 H5Tclose (st_id); | |
599 H5Dclose (data_hid); | |
600 iftext = iftext_tmp; | |
601 | |
602 octave_fcn_inline ftmp (iftext, ifargs, nm); | |
603 fcn = ftmp.fcn; | |
604 | |
605 return true; | |
19897
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
606 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
607 #else |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
608 gripe_load ("hdf5"); |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
609 return false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19731
diff
changeset
|
610 #endif |
4972 | 611 } |
612 | |
4933 | 613 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18099
diff
changeset
|
614 octave_fcn_inline::print (std::ostream& os, bool pr_as_read_syntax) |
4933 | 615 { |
616 print_raw (os, pr_as_read_syntax); | |
617 newline (os); | |
618 } | |
619 | |
620 void | |
621 octave_fcn_inline::print_raw (std::ostream& os, bool pr_as_read_syntax) const | |
622 { | |
5765 | 623 std::ostringstream buf; |
4933 | 624 |
625 if (nm.empty ()) | |
626 buf << "f("; | |
627 else | |
628 buf << nm << "("; | |
629 | |
20267
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20198
diff
changeset
|
630 for (int i = 0; i < ifargs.numel (); i++) |
4933 | 631 { |
632 if (i) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
633 buf << ", "; |
4933 | 634 |
635 buf << ifargs(i); | |
636 } | |
637 | |
5765 | 638 buf << ") = " << iftext; |
4933 | 639 |
5765 | 640 octave_print_internal (os, buf.str (), pr_as_read_syntax, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
641 current_print_indent_level ()); |
4933 | 642 } |
643 | |
644 octave_value | |
5279 | 645 octave_fcn_inline::convert_to_str_internal (bool, bool, char type) const |
4933 | 646 { |
5279 | 647 return octave_value (fcn_text (), type); |
4933 | 648 } |
649 | |
6973 | 650 DEFUNX ("inline", Finline, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
651 "-*- texinfo -*-\n\ |
10840 | 652 @deftypefn {Built-in Function} {} inline (@var{str})\n\ |
6547 | 653 @deftypefnx {Built-in Function} {} inline (@var{str}, @var{arg1}, @dots{})\n\ |
4933 | 654 @deftypefnx {Built-in Function} {} inline (@var{str}, @var{n})\n\ |
655 Create an inline function from the character string @var{str}.\n\ | |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
656 \n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
657 If called with a single argument, the arguments of the generated function\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
658 are extracted from the function itself. The generated function arguments\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
659 will then be in alphabetical order. It should be noted that i and j are\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
660 ignored as arguments due to the ambiguity between their use as a variable or\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
661 their use as an built-in constant. All arguments followed by a parenthesis\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
662 are considered to be functions. If no arguments are found, a function\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
663 taking a single argument named @code{x} will be created.\n\ |
4933 | 664 \n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
665 If the second and subsequent arguments are character strings, they are the\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
666 names of the arguments of the function.\n\ |
4933 | 667 \n\ |
668 If the second argument is an integer @var{n}, the arguments are\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
669 @qcode{\"x\"}, @qcode{\"P1\"}, @dots{}, @qcode{\"P@var{N}\"}.\n\ |
18533
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
670 \n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
671 Programming Note: The use of @code{inline} is discouraged and it may be\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
672 removed from a future version of Octave. The preferred way to create\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
673 functions from strings is through the use of anonymous functions\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
674 (@pxref{Anonymous Functions}) or @code{str2func}.\n\ |
ea0d4dea1a17
doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
675 @seealso{argnames, formula, vectorize, str2func}\n\ |
5642 | 676 @end deftypefn") |
4933 | 677 { |
678 octave_value retval; | |
679 | |
680 int nargin = args.length (); | |
681 | |
682 if (nargin > 0) | |
683 { | |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
684 std::string fun = args(0).string_value ("inline: STR argument must be a string"); |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
685 |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
686 string_vector fargs; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
687 |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
688 if (nargin == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
689 { |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
690 bool is_arg = false; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
691 bool in_string = false; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
692 std::string tmp_arg; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
693 size_t i = 0; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
694 size_t fun_length = fun.length (); |
4933 | 695 |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
696 while (i < fun_length) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
697 { |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
698 bool terminate_arg = false; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
699 char c = fun[i++]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
700 |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
701 if (in_string) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
702 { |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
703 if (c == '\'' || c == '\"') |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
704 in_string = false; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
705 } |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
706 else if (c == '\'' || c == '\"') |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
707 { |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
708 in_string = true; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
709 if (is_arg) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
710 terminate_arg = true; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
711 } |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
712 else if (! isalpha (c) && c != '_') |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
713 if (! is_arg) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
714 continue; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
715 else if (isdigit (c)) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
716 tmp_arg.append (1, c); |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
717 else |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
718 { |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
719 // Before we do anything remove trailing whitespaces. |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
720 while (i < fun_length && isspace (c)) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
721 c = fun[i++]; |
4933 | 722 |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
723 // Do we have a variable or a function? |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
724 if (c != '(') |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
725 terminate_arg = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
726 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
727 { |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
728 tmp_arg = std::string (); |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
729 is_arg = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
730 } |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
731 } |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
732 else if (! is_arg) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
733 { |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
734 if (c == 'e' || c == 'E') |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
735 { |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
736 // possible number in exponent form, not arg |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
737 if (isdigit (fun[i]) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
738 || fun[i] == '-' || fun[i] == '+') |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
739 continue; |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
740 } |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
741 is_arg = true; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
742 tmp_arg.append (1, c); |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
743 } |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
744 else |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
745 { |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
746 tmp_arg.append (1, c); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
747 } |
5034 | 748 |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
749 if (terminate_arg || (i == fun_length && is_arg)) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
750 { |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
751 bool have_arg = false; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
752 |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
753 for (int j = 0; j < fargs.numel (); j++) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
754 if (tmp_arg == fargs (j)) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
755 { |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
756 have_arg = true; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
757 break; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
758 } |
15977
6535f92350ec
Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
759 |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
760 if (! have_arg && tmp_arg != "i" && tmp_arg != "j" |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
761 && tmp_arg != "NaN" && tmp_arg != "nan" |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
762 && tmp_arg != "Inf" && tmp_arg != "inf" |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
763 && tmp_arg != "NA" && tmp_arg != "pi" |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
764 && tmp_arg != "e" && tmp_arg != "eps") |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
765 fargs.append (tmp_arg); |
15977
6535f92350ec
Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
766 |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
767 tmp_arg = std::string (); |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
768 is_arg = false; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
769 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
770 } |
15978
dc5d42399e89
maint: whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15977
diff
changeset
|
771 |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
772 // Sort the arguments into ascii order. |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
773 fargs.sort (); |
4933 | 774 |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
775 if (fargs.numel () == 0) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
776 fargs.append (std::string ("x")); |
4933 | 777 |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
778 } |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
779 else if (nargin == 2 && args(1).is_numeric_type ()) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
780 { |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
781 if (! args(1).is_scalar_type ()) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
782 { |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
783 error ("inline: N must be an integer"); |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
784 return retval; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
785 } |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
786 |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
787 int n = args(1).int_value (); |
4933 | 788 |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
789 if (! error_state) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
790 { |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
791 if (n >= 0) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
792 { |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
793 fargs.resize (n+1); |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
794 |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
795 fargs(0) = "x"; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
796 |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
797 for (int i = 1; i < n+1; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
798 { |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
799 std::ostringstream buf; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
800 buf << "P" << i; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
801 fargs(i) = buf.str (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
802 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
803 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
804 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
805 { |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
806 error ("inline: N must be a positive integer or zero"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
807 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
808 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
809 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
810 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
811 { |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
812 error ("inline: N must be an integer"); |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
813 return retval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
814 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
815 } |
4933 | 816 else |
20615
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
817 { |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
818 fargs.resize (nargin - 1); |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
819 |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
820 for (int i = 1; i < nargin; i++) |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
821 { |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
822 std::string s = args(i).string_value ("inline: expecting string arguments"); |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
823 fargs(i-1) = s; |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
824 } |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
825 } |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
826 |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20587
diff
changeset
|
827 retval = octave_value (new octave_fcn_inline (fun, fargs)); |
4933 | 828 } |
829 else | |
5823 | 830 print_usage (); |
4933 | 831 |
832 return retval; | |
833 } | |
834 | |
7394 | 835 /* |
836 %!shared fn | |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
837 %! fn = inline ("x.^2 + 1"); |
7394 | 838 %!assert (feval (fn, 6), 37) |
839 %!assert (fn (6), 37) | |
15977
6535f92350ec
Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
840 %!assert (feval (inline ("sum (x(:))"), [1 2; 3 4]), 10) |
6535f92350ec
Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
841 %!assert (feval (inline ("sqrt (x^2 + y^2)", "x", "y"), 3, 4), 5) |
6535f92350ec
Always give inline functions a default argument (bug #38164)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15195
diff
changeset
|
842 %!assert (feval (inline ("exp (P1*x) + P2", 3), 3, 4, 5), exp(3*4) + 5) |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
843 |
15978
dc5d42399e89
maint: whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15977
diff
changeset
|
844 ## Test input validation |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
845 %!error inline () |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
846 %!error <STR argument must be a string> inline (1) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
847 %!error <N must be an integer> inline ("2", ones (2,2)) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
848 %!error <N must be a positive integer> inline ("2", -1) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
849 %!error <expecting string arguments> inline ("2", "x", -1, "y") |
7394 | 850 */ |
851 | |
4933 | 852 DEFUN (formula, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
853 "-*- texinfo -*-\n\ |
4933 | 854 @deftypefn {Built-in Function} {} formula (@var{fun})\n\ |
855 Return a character string representing the inline function @var{fun}.\n\ | |
19156
c43223245085
doc: Add warnings about eventual removal of inline functions.
Rik <rik@octave.org>
parents:
18712
diff
changeset
|
856 \n\ |
4933 | 857 Note that @code{char (@var{fun})} is equivalent to\n\ |
858 @code{formula (@var{fun})}.\n\ | |
19156
c43223245085
doc: Add warnings about eventual removal of inline functions.
Rik <rik@octave.org>
parents:
18712
diff
changeset
|
859 @seealso{char, argnames, inline, vectorize}\n\ |
5642 | 860 @end deftypefn") |
4933 | 861 { |
862 octave_value retval; | |
863 | |
864 int nargin = args.length (); | |
865 | |
866 if (nargin == 1) | |
867 { | |
868 octave_fcn_inline* fn = args(0).fcn_inline_value (true); | |
869 | |
870 if (fn) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
871 retval = octave_value (fn->fcn_text ()); |
4933 | 872 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
873 error ("formula: FUN must be an inline function"); |
4933 | 874 } |
875 else | |
5823 | 876 print_usage (); |
4933 | 877 |
878 return retval; | |
879 } | |
880 | |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
881 /* |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
882 %!assert (formula (fn), "x.^2 + 1") |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
883 %!assert (formula (fn), char (fn)) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
884 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14145
diff
changeset
|
885 ## Test input validation |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
886 %!error formula () |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
887 %!error formula (1, 2) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
888 %!error <FUN must be an inline function> formula (1) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
889 */ |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
890 |
4933 | 891 DEFUN (argnames, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
892 "-*- texinfo -*-\n\ |
4933 | 893 @deftypefn {Built-in Function} {} argnames (@var{fun})\n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
894 Return a cell array of character strings containing the names of the\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
895 arguments of the inline function @var{fun}.\n\ |
6529 | 896 @seealso{inline, formula, vectorize}\n\ |
5642 | 897 @end deftypefn") |
4933 | 898 { |
899 octave_value retval; | |
900 | |
901 int nargin = args.length (); | |
902 | |
903 if (nargin == 1) | |
904 { | |
905 octave_fcn_inline *fn = args(0).fcn_inline_value (true); | |
906 | |
907 if (fn) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
908 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
909 string_vector t1 = fn->fcn_arg_names (); |
4933 | 910 |
20267
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20198
diff
changeset
|
911 Cell t2 (dim_vector (t1.numel (), 1)); |
4933 | 912 |
20267
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20198
diff
changeset
|
913 for (int i = 0; i < t1.numel (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
914 t2(i) = t1(i); |
4933 | 915 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
916 retval = t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
917 } |
4933 | 918 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
919 error ("argnames: FUN must be an inline function"); |
4933 | 920 } |
921 else | |
5823 | 922 print_usage (); |
4933 | 923 |
924 return retval; | |
925 } | |
926 | |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
927 /* |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
928 %!assert (argnames (fn), {"x"}) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
929 %!assert (argnames (inline ("1e-3*y + 2e4*z")), {"y"; "z"}) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
930 %!assert (argnames (inline ("2", 2)), {"x"; "P1"; "P2"}) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
931 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14145
diff
changeset
|
932 ## Test input validation |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
933 %!error argnames () |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
934 %!error argnames (1, 2) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
935 %!error <FUN must be an inline function> argnames (1) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
936 */ |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
937 |
4933 | 938 DEFUN (vectorize, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
939 "-*- texinfo -*-\n\ |
6635 | 940 @deftypefn {Built-in Function} {} vectorize (@var{fun})\n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
941 Create a vectorized version of the inline function @var{fun} by replacing\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
942 all occurrences of @code{*}, @code{/}, etc., with @code{.*}, @code{./}, etc.\n\ |
12632
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
943 \n\ |
20198
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
944 This may be useful, for example, when using inline functions with numerical\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
945 integration or optimization where a vector-valued function is expected.\n\ |
12632
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
946 \n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
947 @example\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
948 @group\n\ |
12632
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
949 fcn = vectorize (inline (\"x^2 - 1\"))\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
950 @result{} fcn = f(x) = x.^2 - 1\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
951 quadv (fcn, 0, 3)\n\ |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
952 @result{} 6\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12632
diff
changeset
|
953 @end group\n\ |
12632
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
954 @end example\n\ |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
955 @seealso{inline, formula, argnames}\n\ |
5642 | 956 @end deftypefn") |
4933 | 957 { |
958 octave_value retval; | |
959 | |
960 int nargin = args.length (); | |
961 | |
962 if (nargin == 1) | |
963 { | |
5409 | 964 std::string old_func; |
965 octave_fcn_inline* old = 0; | |
966 bool func_is_string = true; | |
4933 | 967 |
5409 | 968 if (args(0).is_string ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
969 old_func = args(0).string_value (); |
5409 | 970 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
971 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
972 old = args(0).fcn_inline_value (true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
973 func_is_string = false; |
5409 | 974 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
975 if (old) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
976 old_func = old->fcn_text (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
977 else |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
978 error ("vectorize: FUN must be a string or inline function"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
979 } |
5409 | 980 |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
981 std::string new_func; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
982 size_t i = 0; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
983 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
984 while (i < old_func.length ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
985 { |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
986 std::string t1 = old_func.substr (i, 1); |
4933 | 987 |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
988 if (t1 == "*" || t1 == "/" || t1 == "\\" || t1 == "^") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
989 { |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
990 if (i && old_func.substr (i-1, 1) != ".") |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
991 new_func.append ("."); |
4933 | 992 |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
993 // Special case for ** operator. |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
994 if (t1 == "*" && i < (old_func.length () - 1) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
995 && old_func.substr (i+1, 1) == "*") |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
996 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
997 new_func.append ("*"); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
998 i++; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
999 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1000 } |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
1001 new_func.append (t1); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
1002 i++; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
1003 } |
4933 | 1004 |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
1005 if (func_is_string) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
1006 retval = octave_value (new_func); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
1007 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
1008 retval = octave_value (new octave_fcn_inline |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20482
diff
changeset
|
1009 (new_func, old->fcn_arg_names ())); |
4933 | 1010 } |
1011 else | |
5823 | 1012 print_usage (); |
4933 | 1013 |
1014 return retval; | |
1015 } | |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1016 |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1017 /* |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1018 %!assert (char (vectorize (fn)), "x.^2 + 1") |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1019 %!assert (char (vectorize (inline ("1e-3*y + 2e4*z"))), "1e-3.*y + 2e4.*z") |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1020 %!assert (char (vectorize (inline ("2**x^5"))), "2.**x.^5") |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1021 %!assert (vectorize ("x.^2 + 1"), "x.^2 + 1") |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1022 %!assert (vectorize ("1e-3*y + 2e4*z"), "1e-3.*y + 2e4.*z") |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1023 %!assert (vectorize ("2**x^5"), "2.**x.^5") |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1024 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14145
diff
changeset
|
1025 ## Test input validation |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1026 %!error vectorize () |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1027 %!error vectorize (1, 2) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1028 %!error <FUN must be a string or inline function> vectorize (1) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1029 */ |