Mercurial > octave
annotate libinterp/octave-value/ov-fcn-inline.cc @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
4933 | 1 /* |
2 | |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 Copyright (C) 2004-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27208
diff
changeset
|
4 |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27208
diff
changeset
|
5 See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27208
diff
changeset
|
6 or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27208
diff
changeset
|
7 |
4933 | 8 |
7016 | 9 This file is part of Octave. |
4933 | 10 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24361
diff
changeset
|
11 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24361
diff
changeset
|
13 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 (at your option) any later version. |
7016 | 15 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
16 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
17 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
19 GNU General Public License for more details. |
4933 | 20 |
21 You should have received a copy of the GNU General Public License | |
7016 | 22 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24361
diff
changeset
|
23 <https://www.gnu.org/licenses/>. |
4933 | 24 |
25 In addition to the terms of the GPL, you are permitted to link | |
26 this program with any Open Source program, as defined by the | |
27 Open Source Initiative (www.opensource.org) | |
28 | |
29 */ | |
30 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
31 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21211
diff
changeset
|
32 # include "config.h" |
4933 | 33 #endif |
34 | |
4988 | 35 #include <istream> |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
36 #include <ostream> |
5765 | 37 #include <sstream> |
5164 | 38 #include <vector> |
4933 | 39 |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8045
diff
changeset
|
40 #include "oct-locbuf.h" |
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8045
diff
changeset
|
41 |
4933 | 42 #include "defun.h" |
43 #include "error.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
44 #include "errwarn.h" |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
45 #include "interpreter-private.h" |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
46 #include "interpreter.h" |
19863
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:
19697
diff
changeset
|
47 #include "oct-hdf5.h" |
4933 | 48 #include "oct-map.h" |
49 #include "ov-base.h" | |
50 #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
|
51 #include "ov-usr-fcn.h" |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
52 #include "parse.h" |
4933 | 53 #include "pr-output.h" |
54 #include "variables.h" | |
55 | |
4972 | 56 #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
|
57 #include "ls-ascii-helper.h" |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
58 #include "ls-oct-text.h" |
4972 | 59 #include "ls-hdf5.h" |
60 #include "ls-utils.h" | |
61 | |
4933 | 62 |
63 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
|
64 "inline function", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
65 "function_handle"); |
4933 | 66 |
67 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
|
68 const string_vector& a, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
69 const std::string& n) |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
70 : octave_fcn_handle (n), m_text (f), m_args (a) |
4933 | 71 { |
4973 | 72 // Form a string representing the function. |
4933 | 73 |
5765 | 74 std::ostringstream buf; |
4933 | 75 |
5007 | 76 buf << "@("; |
4933 | 77 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
78 for (int i = 0; i < m_args.numel (); i++) |
4933 | 79 { |
80 if (i > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
81 buf << ", "; |
4933 | 82 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
83 buf << m_args(i); |
4933 | 84 } |
85 | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
86 buf << ") " << m_text; |
4933 | 87 |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25438
diff
changeset
|
88 octave::interpreter& interp |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25438
diff
changeset
|
89 = octave::__get_interpreter__ ("octave_fcn_inline::octave_fcn_inline"); |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25438
diff
changeset
|
90 |
5007 | 91 int parse_status; |
26113
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25438
diff
changeset
|
92 octave_value anon_fcn_handle |
8a15f3bace49
move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents:
25438
diff
changeset
|
93 = interp.eval_string (buf.str (), true, parse_status); |
4933 | 94 |
5007 | 95 if (parse_status == 0) |
4933 | 96 { |
5007 | 97 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); |
4933 | 98 |
5007 | 99 if (fh) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
100 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
101 m_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
|
102 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
103 octave_user_function *uf = m_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
|
104 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
105 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
106 { |
27208
5b40cf4896f0
eliminate some direct access to call stack in classdef and inline objects
John W. Eaton <jwe@octave.org>
parents:
26854
diff
changeset
|
107 octave::tree_evaluator& tw = interp.get_evaluator (); |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
108 |
27208
5b40cf4896f0
eliminate some direct access to call stack in classdef and inline objects
John W. Eaton <jwe@octave.org>
parents:
26854
diff
changeset
|
109 octave_function *curr_fcn = tw.current_function (); |
8045
24701aa75ecb
scope fixes for anonymous and inline functions that appear inside subfunctions
John W. Eaton <jwe@octave.org>
parents:
8032
diff
changeset
|
110 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
111 if (curr_fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
112 { |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
113 octave::symbol_scope parent_scope |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
114 = 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
|
115 |
23602
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
116 if (! parent_scope) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
117 parent_scope = curr_fcn->scope (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
118 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
119 uf->stash_parent_fcn_scope (parent_scope); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
120 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
121 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
122 } |
4933 | 123 } |
5007 | 124 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
125 if (m_fcn.is_undefined ()) |
4933 | 126 error ("inline: unable to define function"); |
127 } | |
128 | |
6625 | 129 // This function is supplied to allow a Matlab style class structure |
130 // to be returned.. | |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
131 octave_map |
6625 | 132 octave_fcn_inline::map_value (void) const |
133 { | |
11070
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
134 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
|
135 |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 |
6625 | 140 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
|
141 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
142 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
|
143 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
|
144 |
6625 | 145 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
|
146 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20163
diff
changeset
|
147 for (int i = 0; i < args.numel (); i++) |
6625 | 148 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
|
149 |
686d5bd22132
ov-fcn-inline.cc: use octve_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
150 m.assign ("inputExpr", buf.str ()); |
6625 | 151 |
152 return m; | |
153 } | |
154 | |
4972 | 155 bool |
6974 | 156 octave_fcn_inline::save_ascii (std::ostream& os) |
4972 | 157 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
158 os << "# nargs: " << m_args.numel () << "\n"; |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
159 for (int i = 0; i < m_args.numel (); i++) |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
160 os << m_args(i) << "\n"; |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
161 if (m_name.length () < 1) |
4973 | 162 // Write an invalid value to flag empty fcn handle name. |
4972 | 163 os << "0\n"; |
164 else | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
165 os << m_name << "\n"; |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
166 os << m_text << "\n"; |
4972 | 167 return true; |
168 } | |
169 | |
170 bool | |
171 octave_fcn_inline::load_ascii (std::istream& is) | |
172 { | |
173 int nargs; | |
174 if (extract_keyword (is, "nargs", nargs, true)) | |
175 { | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
176 m_args.resize (nargs); |
4972 | 177 for (int i = 0; i < nargs; i++) |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
178 is >> m_args(i); |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
179 is >> m_name; |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
180 if (m_name == "0") |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
181 m_name = ""; |
4988 | 182 |
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
|
183 skip_preceeding_newline (is); |
4988 | 184 |
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
|
185 std::string buf; |
4988 | 186 |
187 if (is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
188 { |
4988 | 189 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
190 // Get a line of text whitespace characters included, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
191 // leaving newline in the stream. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
192 buf = read_until_newline (is, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
193 } |
4988 | 194 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
195 m_text = buf; |
4972 | 196 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
197 octave_fcn_inline tmp (m_text, m_args, m_name); |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
198 m_fcn = tmp.m_fcn; |
4972 | 199 |
200 return true; | |
201 } | |
202 else | |
203 return false; | |
204 } | |
205 | |
4973 | 206 bool |
26399
586413770c7f
pass save_as_floats by value in octave_value save_binary functions
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
207 octave_fcn_inline::save_binary (std::ostream& os, bool) |
4972 | 208 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
209 int32_t tmp = m_args.numel (); |
5760 | 210 os.write (reinterpret_cast<char *> (&tmp), 4); |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
211 for (int i = 0; i < m_args.numel (); i++) |
4972 | 212 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
213 tmp = m_args(i).length (); |
5760 | 214 os.write (reinterpret_cast<char *> (&tmp), 4); |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
215 os.write (m_args(i).c_str (), m_args(i).length ()); |
4972 | 216 } |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
217 tmp = m_name.length (); |
5760 | 218 os.write (reinterpret_cast<char *> (&tmp), 4); |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
219 os.write (m_name.c_str (), m_name.length ()); |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
220 tmp = m_text.length (); |
5760 | 221 os.write (reinterpret_cast<char *> (&tmp), 4); |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
222 os.write (m_text.c_str (), m_text.length ()); |
4972 | 223 return true; |
224 } | |
225 | |
4973 | 226 bool |
4972 | 227 octave_fcn_inline::load_binary (std::istream& is, bool swap, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
228 octave::mach_info::float_format) |
4972 | 229 { |
5828 | 230 int32_t nargs; |
5760 | 231 if (! is.read (reinterpret_cast<char *> (&nargs), 4)) |
4972 | 232 return false; |
233 if (swap) | |
234 swap_bytes<4> (&nargs); | |
235 | |
236 if (nargs < 1) | |
237 return false; | |
238 else | |
239 { | |
5828 | 240 int32_t tmp; |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
241 m_args.resize (nargs); |
4972 | 242 for (int i = 0; i < nargs; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
243 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
244 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
245 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
246 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
247 swap_bytes<4> (&tmp); |
4972 | 248 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
249 OCTAVE_LOCAL_BUFFER (char, ctmp, tmp+1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
250 is.read (ctmp, tmp); |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
251 m_args(i) = std::string (ctmp); |
4972 | 252 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
253 if (! is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
254 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
255 } |
4972 | 256 |
5760 | 257 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
|
258 return false; |
4972 | 259 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
260 swap_bytes<4> (&tmp); |
4972 | 261 |
262 OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1); | |
263 is.read (ctmp1, tmp); | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
264 m_name = std::string (ctmp1); |
4972 | 265 |
266 if (! is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
267 return false; |
4972 | 268 |
5760 | 269 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
|
270 return false; |
4972 | 271 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
272 swap_bytes<4> (&tmp); |
4972 | 273 |
274 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1); | |
275 is.read (ctmp2, tmp); | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
276 m_text = std::string (ctmp2); |
4972 | 277 |
278 if (! is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
279 return false; |
4972 | 280 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
281 octave_fcn_inline ftmp (m_text, m_args, m_name); |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
282 m_fcn = ftmp.m_fcn; |
4972 | 283 } |
284 return true; | |
285 } | |
286 | |
287 bool | |
19863
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:
19697
diff
changeset
|
288 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
|
289 bool /* save_as_floats */) |
4972 | 290 { |
19863
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:
19697
diff
changeset
|
291 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:
19697
diff
changeset
|
292 |
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:
19697
diff
changeset
|
293 #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:
19697
diff
changeset
|
294 |
4972 | 295 hid_t group_hid = -1; |
19863
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:
19697
diff
changeset
|
296 |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
297 #if defined (HAVE_HDF5_18) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
298 group_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT, octave_H5P_DEFAULT, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
299 octave_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
|
300 #else |
4972 | 301 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
|
302 #endif |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18537
diff
changeset
|
303 if (group_hid < 0) return false; |
4972 | 304 |
305 size_t len = 0; | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
306 for (int i = 0; i < m_args.numel (); i++) |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
307 if (len < m_args(i).length ()) |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
308 len = m_args(i).length (); |
4972 | 309 |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
310 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
|
311 space_hid = data_hid = type_hid = -1; |
4972 | 312 |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
313 // 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
|
314 // than a null padded matrix? |
4972 | 315 |
316 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2); | |
317 | |
318 // Octave uses column-major, while HDF5 uses row-major ordering | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
319 hdims[1] = m_args.numel (); |
4972 | 320 hdims[0] = len + 1; |
321 | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
322 space_hid = H5Screate_simple (2, hdims, nullptr); |
4972 | 323 if (space_hid < 0) |
324 { | |
325 H5Gclose (group_hid); | |
326 return false; | |
327 } | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
328 #if defined (HAVE_HDF5_18) |
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
|
329 data_hid = H5Dcreate (group_hid, "args", H5T_NATIVE_CHAR, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
330 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_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
|
331 #else |
4973 | 332 data_hid = H5Dcreate (group_hid, "args", H5T_NATIVE_CHAR, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
333 octave_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
|
334 #endif |
4972 | 335 if (data_hid < 0) |
336 { | |
337 H5Sclose (space_hid); | |
338 H5Gclose (group_hid); | |
339 return false; | |
340 } | |
341 | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
342 OCTAVE_LOCAL_BUFFER (char, s, m_args.numel () * (len + 1)); |
4972 | 343 |
344 // Save the args as a null teminated list | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
345 for (int i = 0; i < m_args.numel (); i++) |
4972 | 346 { |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
347 const char *cptr = m_args(i).c_str (); |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
348 for (size_t j = 0; j < m_args(i).length (); j++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
349 s[i*(len+1)+j] = *cptr++; |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
350 s[m_args(i).length ()] = '\0'; |
4972 | 351 } |
352 | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
353 retval = H5Dwrite (data_hid, H5T_NATIVE_CHAR, octave_H5S_ALL, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
354 octave_H5P_DEFAULT, s) >= 0; |
4972 | 355 |
356 H5Dclose (data_hid); | |
357 H5Sclose (space_hid); | |
358 | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
359 if (! retval) |
4972 | 360 { |
361 H5Gclose (group_hid); | |
362 return false; | |
4973 | 363 } |
4972 | 364 |
365 // attach the type of the variable | |
4973 | 366 type_hid = H5Tcopy (H5T_C_S1); |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
367 H5Tset_size (type_hid, m_name.length () + 1); |
4972 | 368 if (type_hid < 0) |
369 { | |
370 H5Gclose (group_hid); | |
371 return false; | |
4973 | 372 } |
4972 | 373 |
374 hdims[0] = 0; | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
375 space_hid = H5Screate_simple (0 , hdims, nullptr); |
4972 | 376 if (space_hid < 0) |
377 { | |
378 H5Tclose (type_hid); | |
379 H5Gclose (group_hid); | |
380 return false; | |
4973 | 381 } |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
382 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
383 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
384 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_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
|
385 #else |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
386 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
387 octave_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
|
388 #endif |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
389 if (data_hid < 0 |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
390 || H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL, |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
391 octave_H5P_DEFAULT, m_name.c_str ()) < 0) |
4972 | 392 { |
393 H5Sclose (space_hid); | |
394 H5Tclose (type_hid); | |
395 H5Gclose (group_hid); | |
396 return false; | |
4973 | 397 } |
4972 | 398 H5Dclose (data_hid); |
399 | |
400 // attach the type of the variable | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
401 H5Tset_size (type_hid, m_text.length () + 1); |
4972 | 402 if (type_hid < 0) |
403 { | |
404 H5Gclose (group_hid); | |
405 return false; | |
4973 | 406 } |
4972 | 407 |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
408 #if defined (HAVE_HDF5_18) |
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
|
409 data_hid = H5Dcreate (group_hid, "iftext", type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
410 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_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
|
411 #else |
4973 | 412 data_hid = H5Dcreate (group_hid, "iftext", type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
413 octave_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
|
414 #endif |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
415 if (data_hid < 0 |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
416 || H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL, |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
417 octave_H5P_DEFAULT, m_text.c_str ()) < 0) |
4972 | 418 { |
419 H5Sclose (space_hid); | |
420 H5Tclose (type_hid); | |
421 H5Gclose (group_hid); | |
422 return false; | |
4973 | 423 } |
4972 | 424 |
425 H5Dclose (data_hid); | |
4988 | 426 H5Sclose (space_hid); |
427 H5Tclose (type_hid); | |
428 H5Gclose (group_hid); | |
4972 | 429 |
19863
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:
19697
diff
changeset
|
430 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
431 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
432 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
433 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
434 warn_save ("hdf5"); |
19863
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:
19697
diff
changeset
|
435 #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:
19697
diff
changeset
|
436 |
4972 | 437 return retval; |
438 } | |
439 | |
440 bool | |
19863
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:
19697
diff
changeset
|
441 octave_fcn_inline::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4972 | 442 { |
19863
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:
19697
diff
changeset
|
443 #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:
19697
diff
changeset
|
444 |
4972 | 445 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id; |
446 hsize_t rank; | |
447 int slen; | |
448 | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
449 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
450 group_hid = H5Gopen (loc_id, name, octave_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
|
451 #else |
4972 | 452 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
|
453 #endif |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18537
diff
changeset
|
454 if (group_hid < 0) return false; |
4972 | 455 |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
456 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
457 data_hid = H5Dopen (group_hid, "args", octave_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
|
458 #else |
4972 | 459 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
|
460 #endif |
4972 | 461 space_hid = H5Dget_space (data_hid); |
462 rank = H5Sget_simple_extent_ndims (space_hid); | |
463 | |
464 if (rank != 2) | |
4973 | 465 { |
4972 | 466 H5Dclose (data_hid); |
467 H5Sclose (space_hid); | |
468 H5Gclose (group_hid); | |
469 return false; | |
470 } | |
471 | |
472 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
473 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
474 | |
475 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
476 | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
477 m_args.resize (hdims[1]); |
4972 | 478 |
479 OCTAVE_LOCAL_BUFFER (char, s1, hdims[0] * hdims[1]); | |
480 | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
481 if (H5Dread (data_hid, H5T_NATIVE_UCHAR, octave_H5S_ALL, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
482 octave_H5P_DEFAULT, s1) < 0) |
4973 | 483 { |
4972 | 484 H5Dclose (data_hid); |
485 H5Sclose (space_hid); | |
486 H5Gclose (group_hid); | |
487 return false; | |
488 } | |
489 | |
490 H5Dclose (data_hid); | |
491 H5Sclose (space_hid); | |
492 | |
493 for (size_t i = 0; i < hdims[1]; i++) | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
494 m_args(i) = std::string (s1 + i*hdims[0]); |
4972 | 495 |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
496 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
497 data_hid = H5Dopen (group_hid, "nm", octave_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
|
498 #else |
4972 | 499 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
|
500 #endif |
4972 | 501 |
502 if (data_hid < 0) | |
503 { | |
504 H5Gclose (group_hid); | |
505 return false; | |
506 } | |
507 | |
508 type_hid = H5Dget_type (data_hid); | |
509 type_class_hid = H5Tget_class (type_hid); | |
510 | |
511 if (type_class_hid != H5T_STRING) | |
512 { | |
513 H5Tclose (type_hid); | |
514 H5Dclose (data_hid); | |
515 H5Gclose (group_hid); | |
516 return false; | |
517 } | |
4973 | 518 |
4972 | 519 space_hid = H5Dget_space (data_hid); |
520 rank = H5Sget_simple_extent_ndims (space_hid); | |
521 | |
522 if (rank != 0) | |
523 { | |
524 H5Sclose (space_hid); | |
525 H5Tclose (type_hid); | |
526 H5Dclose (data_hid); | |
527 H5Gclose (group_hid); | |
528 return false; | |
529 } | |
530 | |
531 slen = H5Tget_size (type_hid); | |
532 if (slen < 0) | |
533 { | |
534 H5Sclose (space_hid); | |
535 H5Tclose (type_hid); | |
536 H5Dclose (data_hid); | |
537 H5Gclose (group_hid); | |
538 return false; | |
539 } | |
540 | |
541 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen); | |
542 | |
543 // create datatype for (null-terminated) string to read into: | |
544 st_id = H5Tcopy (H5T_C_S1); | |
545 H5Tset_size (st_id, slen); | |
546 | |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
547 if (H5Dread (data_hid, st_id, octave_H5S_ALL, octave_H5S_ALL, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
548 octave_H5P_DEFAULT, nm_tmp) < 0) |
4972 | 549 { |
550 H5Sclose (space_hid); | |
551 H5Tclose (type_hid); | |
552 H5Gclose (group_hid); | |
553 return false; | |
554 } | |
555 H5Tclose (st_id); | |
556 H5Dclose (data_hid); | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
557 m_name = nm_tmp; |
4972 | 558 |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
559 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
560 data_hid = H5Dopen (group_hid, "iftext", octave_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
|
561 #else |
4972 | 562 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
|
563 #endif |
4972 | 564 |
565 if (data_hid < 0) | |
566 { | |
567 H5Gclose (group_hid); | |
568 return false; | |
569 } | |
570 | |
571 type_hid = H5Dget_type (data_hid); | |
572 type_class_hid = H5Tget_class (type_hid); | |
573 | |
574 if (type_class_hid != H5T_STRING) | |
575 { | |
576 H5Tclose (type_hid); | |
577 H5Dclose (data_hid); | |
578 H5Gclose (group_hid); | |
579 return false; | |
580 } | |
4973 | 581 |
4972 | 582 space_hid = H5Dget_space (data_hid); |
583 rank = H5Sget_simple_extent_ndims (space_hid); | |
584 | |
585 if (rank != 0) | |
586 { | |
587 H5Sclose (space_hid); | |
588 H5Tclose (type_hid); | |
589 H5Dclose (data_hid); | |
590 H5Gclose (group_hid); | |
591 return false; | |
592 } | |
593 | |
594 slen = H5Tget_size (type_hid); | |
595 if (slen < 0) | |
596 { | |
597 H5Sclose (space_hid); | |
598 H5Tclose (type_hid); | |
599 H5Dclose (data_hid); | |
600 H5Gclose (group_hid); | |
601 return false; | |
602 } | |
603 | |
604 OCTAVE_LOCAL_BUFFER (char, iftext_tmp, slen); | |
605 | |
606 // create datatype for (null-terminated) string to read into: | |
607 st_id = H5Tcopy (H5T_C_S1); | |
608 H5Tset_size (st_id, slen); | |
609 | |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
610 if (H5Dread (data_hid, st_id, octave_H5S_ALL, octave_H5S_ALL, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
611 octave_H5P_DEFAULT, iftext_tmp) < 0) |
4972 | 612 { |
613 H5Sclose (space_hid); | |
614 H5Tclose (type_hid); | |
615 H5Gclose (group_hid); | |
616 return false; | |
617 } | |
618 H5Tclose (st_id); | |
619 H5Dclose (data_hid); | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
620 m_text = iftext_tmp; |
4972 | 621 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
622 octave_fcn_inline ftmp (m_text, m_args, m_name); |
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
623 m_fcn = ftmp.m_fcn; |
4972 | 624 |
625 return true; | |
19863
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:
19697
diff
changeset
|
626 |
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:
19697
diff
changeset
|
627 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
628 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
629 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
630 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
631 warn_load ("hdf5"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
632 |
19863
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:
19697
diff
changeset
|
633 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:
19697
diff
changeset
|
634 #endif |
4972 | 635 } |
636 | |
4933 | 637 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18100
diff
changeset
|
638 octave_fcn_inline::print (std::ostream& os, bool pr_as_read_syntax) |
4933 | 639 { |
640 print_raw (os, pr_as_read_syntax); | |
641 newline (os); | |
642 } | |
643 | |
644 void | |
645 octave_fcn_inline::print_raw (std::ostream& os, bool pr_as_read_syntax) const | |
646 { | |
5765 | 647 std::ostringstream buf; |
4933 | 648 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
649 if (m_name.empty ()) |
4933 | 650 buf << "f("; |
651 else | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
652 buf << m_name << '('; |
4933 | 653 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
654 for (int i = 0; i < m_args.numel (); i++) |
4933 | 655 { |
656 if (i) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
657 buf << ", "; |
4933 | 658 |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
659 buf << m_args(i); |
4933 | 660 } |
661 | |
26854
ab97008be411
use m_ for member variables in function handle and inline function classes
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
662 buf << ") = " << m_text; |
4933 | 663 |
5765 | 664 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
|
665 current_print_indent_level ()); |
4933 | 666 } |
667 | |
668 octave_value | |
5279 | 669 octave_fcn_inline::convert_to_str_internal (bool, bool, char type) const |
4933 | 670 { |
5279 | 671 return octave_value (fcn_text (), type); |
4933 | 672 } |
673 | |
6973 | 674 DEFUNX ("inline", Finline, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
675 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
676 @deftypefn {} {} inline (@var{str}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
677 @deftypefnx {} {} inline (@var{str}, @var{arg1}, @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
678 @deftypefnx {} {} inline (@var{str}, @var{n}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
679 Create an inline function from the character string @var{str}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
680 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
681 If called with a single argument, the arguments of the generated function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
682 are extracted from the function itself. The generated function arguments |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
683 will then be in alphabetical order. It should be noted that i and j are |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
684 ignored as arguments due to the ambiguity between their use as a variable or |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
685 their use as an built-in constant. All arguments followed by a parenthesis |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
686 are considered to be functions. If no arguments are found, a function |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
687 taking a single argument named @code{x} will be created. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
688 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
689 If the second and subsequent arguments are character strings, they are the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
690 names of the arguments of the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
691 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
692 If the second argument is an integer @var{n}, the arguments are |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
693 @qcode{"x"}, @qcode{"P1"}, @dots{}, @qcode{"P@var{N}"}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
694 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
695 Programming Note: The use of @code{inline} is discouraged and it may be |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
696 removed from a future version of Octave. The preferred way to create |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
697 functions from strings is through the use of anonymous functions |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
698 (@pxref{Anonymous Functions}) or @code{str2func}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
699 @seealso{argnames, formula, vectorize, str2func} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
700 @end deftypefn */) |
4933 | 701 { |
702 int nargin = args.length (); | |
703 | |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
704 if (nargin == 0) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
705 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
706 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
707 std::string fun = args(0).xstring_value ("inline: STR argument must be a string"); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
708 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
709 string_vector fargs; |
20580
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
710 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
711 if (nargin == 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
712 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
713 bool is_arg = false; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
714 bool in_string = false; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
715 std::string tmp_arg; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
716 size_t i = 0; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
717 size_t fun_length = fun.length (); |
20580
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
718 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
719 while (i < fun_length) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
720 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
721 bool terminate_arg = false; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
722 char c = fun[i++]; |
4933 | 723 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
724 if (in_string) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
725 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
726 if (c == '\'' || c == '\"') |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
727 in_string = false; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
728 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
729 else if (c == '\'' || c == '\"') |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
730 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
731 in_string = true; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
732 if (is_arg) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
733 terminate_arg = true; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
734 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
735 else if (! isalpha (c) && c != '_') |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
736 if (! is_arg) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
737 continue; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
738 else if (isdigit (c)) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
739 tmp_arg.append (1, c); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
740 else |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
741 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
742 // Before we do anything remove trailing whitespaces. |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
743 while (i < fun_length && isspace (c)) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
744 c = fun[i++]; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
745 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
746 // Do we have a variable or a function? |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
747 if (c != '(') |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
748 terminate_arg = true; |
20580
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
749 else |
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
750 { |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20974
diff
changeset
|
751 tmp_arg = ""; |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
752 is_arg = false; |
20580
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
753 } |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
754 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
755 else if (! is_arg) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
756 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
757 if (c == 'e' || c == 'E') |
20580
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
758 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
759 // possible number in exponent form, not arg |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
760 if (isdigit (fun[i]) || fun[i] == '-' || fun[i] == '+') |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
761 continue; |
20580
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
762 } |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
763 is_arg = true; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
764 tmp_arg.append (1, c); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
765 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
766 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
767 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
768 tmp_arg.append (1, c); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
769 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
770 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
771 if (terminate_arg || (i == fun_length && is_arg)) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
772 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
773 bool have_arg = false; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
774 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
775 for (int j = 0; j < fargs.numel (); j++) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
776 if (tmp_arg == fargs (j)) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
777 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
778 have_arg = true; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
779 break; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
780 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
781 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
782 if (! have_arg && tmp_arg != "i" && tmp_arg != "j" |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
783 && tmp_arg != "NaN" && tmp_arg != "nan" |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
784 && tmp_arg != "Inf" && tmp_arg != "inf" |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
785 && tmp_arg != "NA" && tmp_arg != "pi" |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
786 && tmp_arg != "e" && tmp_arg != "eps") |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
787 fargs.append (tmp_arg); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
788 |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20974
diff
changeset
|
789 tmp_arg = ""; |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
790 is_arg = false; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
791 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
792 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
793 |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
794 // Sort the arguments into ASCII order. |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
795 fargs.sort (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
796 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23553
diff
changeset
|
797 if (fargs.isempty ()) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
798 fargs.append (std::string ("x")); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
799 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
800 } |
23586
f6c5db0a02e7
maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
801 else if (nargin == 2 && args(1).isnumeric ()) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
802 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
803 if (! args(1).is_scalar_type ()) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
804 error ("inline: N must be an integer"); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
805 |
26366
b66765e66e87
ov-fcn-inline.cc: Fix static analyzer detected V601 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents:
26113
diff
changeset
|
806 int n = args(1).xint_value ("inline: N must be an integer"); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
807 |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
808 if (n < 0) |
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
809 error ("inline: N must be a positive integer or zero"); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
810 |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
811 fargs.resize (n+1); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
812 |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
813 fargs(0) = "x"; |
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
814 |
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
815 for (int i = 1; i < n+1; i++) |
20580
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
816 { |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
817 std::ostringstream buf; |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
818 buf << 'P' << i; |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
819 fargs(i) = buf.str (); |
20580
729a85dafba8
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
820 } |
4933 | 821 } |
822 else | |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
823 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
824 fargs.resize (nargin - 1); |
4933 | 825 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
826 for (int i = 1; i < nargin; i++) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
827 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
828 std::string s = args(i).xstring_value ("inline: additional arguments must be strings"); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
829 fargs(i-1) = s; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
830 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
831 } |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
832 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
833 return ovl (new octave_fcn_inline (fun, fargs)); |
4933 | 834 } |
835 | |
7394 | 836 /* |
837 %!shared fn | |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
838 %! fn = inline ("x.^2 + 1"); |
7394 | 839 %!assert (feval (fn, 6), 37) |
840 %!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
|
841 %!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
|
842 %!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
|
843 %!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
|
844 |
15978
dc5d42399e89
maint: whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15977
diff
changeset
|
845 ## Test input validation |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
846 %!error inline () |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
847 %!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
|
848 %!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
|
849 %!error <N must be a positive integer> inline ("2", -1) |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
850 %!error <additional arguments must be strings> inline ("2", "x", -1, "y") |
7394 | 851 */ |
852 | |
4933 | 853 DEFUN (formula, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
854 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
855 @deftypefn {} {} formula (@var{fun}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
856 Return a character string representing the inline function @var{fun}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
857 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
858 Note that @code{char (@var{fun})} is equivalent to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
859 @code{formula (@var{fun})}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
860 @seealso{char, argnames, inline, vectorize} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
861 @end deftypefn */) |
4933 | 862 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20797
diff
changeset
|
863 if (args.length () != 1) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
864 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
865 |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23432
diff
changeset
|
866 octave_fcn_inline *fn = args(0).fcn_inline_value (true); |
4933 | 867 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
868 if (! fn) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
869 error ("formula: FUN must be an inline function"); |
4933 | 870 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
871 return ovl (fn->fcn_text ()); |
4933 | 872 } |
873 | |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
874 /* |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
875 %!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
|
876 %!assert (formula (fn), char (fn)) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
877 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14145
diff
changeset
|
878 ## Test input validation |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
879 %!error formula () |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
880 %!error formula (1, 2) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
881 %!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
|
882 */ |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
883 |
4933 | 884 DEFUN (argnames, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
885 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
886 @deftypefn {} {} argnames (@var{fun}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
887 Return a cell array of character strings containing the names of the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
888 arguments of the inline function @var{fun}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
889 @seealso{inline, formula, vectorize} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
890 @end deftypefn */) |
4933 | 891 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20797
diff
changeset
|
892 if (args.length () != 1) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
893 print_usage (); |
4933 | 894 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
895 octave_fcn_inline *fn = args(0).fcn_inline_value (true); |
4933 | 896 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
897 if (! fn) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
898 error ("argnames: FUN must be an inline function"); |
4933 | 899 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
900 string_vector t1 = fn->fcn_arg_names (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
901 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
902 Cell t2 (dim_vector (t1.numel (), 1)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
903 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
904 for (int i = 0; i < t1.numel (); i++) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
905 t2(i) = t1(i); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
906 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
907 return ovl (t2); |
4933 | 908 } |
909 | |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
910 /* |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
911 %!assert (argnames (fn), {"x"}) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
912 %!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
|
913 %!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
|
914 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14145
diff
changeset
|
915 ## Test input validation |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
916 %!error argnames () |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
917 %!error argnames (1, 2) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
918 %!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
|
919 */ |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
920 |
4933 | 921 DEFUN (vectorize, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
922 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
923 @deftypefn {} {} vectorize (@var{fun}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
924 Create a vectorized version of the inline function @var{fun} by replacing |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
925 all occurrences of @code{*}, @code{/}, etc., with @code{.*}, @code{./}, etc. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
926 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
927 This may be useful, for example, when using inline functions with numerical |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
928 integration or optimization where a vector-valued function is expected. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
929 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
930 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
931 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
932 fcn = vectorize (inline ("x^2 - 1")) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
933 @result{} fcn = f(x) = x.^2 - 1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
934 quadv (fcn, 0, 3) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
935 @result{} 6 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
936 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
937 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
938 @seealso{inline, formula, argnames} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
939 @end deftypefn */) |
4933 | 940 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20797
diff
changeset
|
941 if (args.length () != 1) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
942 print_usage (); |
4933 | 943 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
944 std::string old_func; |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
945 octave_fcn_inline *old = nullptr; |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
946 bool func_is_string = true; |
5409 | 947 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
948 if (args(0).is_string ()) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
949 old_func = args(0).string_value (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
950 else |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
951 { |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
952 func_is_string = false; |
5409 | 953 |
23813
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
954 old = args(0).fcn_inline_value (true); |
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
955 if (! old) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
956 error ("vectorize: FUN must be a string or inline function"); |
23813
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
957 |
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
958 old_func = old->fcn_text (); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
959 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
960 |
23813
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
961 size_t len = old_func.length (); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
962 std::string new_func; |
23813
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
963 new_func.reserve (len + 10); |
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
964 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
965 size_t i = 0; |
23813
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
966 while (i < len) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
967 { |
23813
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
968 char t1 = old_func[i]; |
4933 | 969 |
23813
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
970 if (t1 == '*' || t1 == '/' || t1 == '\\' || t1 == '^') |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
971 { |
23813
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
972 if (i && old_func[i-1] != '.') |
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
973 new_func.push_back ('.'); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
974 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
975 // Special case for ** operator. |
23813
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
976 if (t1 == '*' && i < (len - 1) && old_func[i+1] == '*') |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
977 { |
23813
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
978 new_func.push_back ('*'); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
979 i++; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
980 } |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20447
diff
changeset
|
981 } |
23813
ccc4e85762ac
Overhaul vectorize() to use C++11 string functions.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
982 new_func.push_back (t1); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
983 i++; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
984 } |
4933 | 985 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
986 if (func_is_string) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
987 return ovl (new_func); |
4933 | 988 else |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
989 return ovl (new octave_fcn_inline (new_func, old->fcn_arg_names ())); |
4933 | 990 } |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
991 |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
992 /* |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
993 %!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
|
994 %!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
|
995 %!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
|
996 %!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
|
997 %!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
|
998 %!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
|
999 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14145
diff
changeset
|
1000 ## Test input validation |
14098
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1001 %!error vectorize () |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1002 %!error vectorize (1, 2) |
ebf41239e47e
Allow exponential numbers (1e-3) in inline() (Bug #35131)
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
1003 %!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
|
1004 */ |