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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
1 /*
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
8
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
9 This file is part of Octave.
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
20
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
21 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
24
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
25 In addition to the terms of the GPL, you are permitted to link
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
26 this program with any Open Source program, as defined by the
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
27 Open Source Initiative (www.opensource.org)
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
28
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
29 */
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
33 #endif
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
34
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
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
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
37 #include <sstream>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5105
diff changeset
38 #include <vector>
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
42 #include "defun.h"
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
48 #include "oct-map.h"
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
49 #include "ov-base.h"
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
53 #include "pr-output.h"
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
54 #include "variables.h"
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
55
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
59 #include "ls-hdf5.h"
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
60 #include "ls-utils.h"
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
61
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
62
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
66
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
71 {
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
72 // Form a string representing the function.
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
73
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
74 std::ostringstream buf;
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
75
5007
f8c27dad3643 [project @ 2004-09-17 11:42:04 by jwe]
jwe
parents: 4988
diff changeset
76 buf << "@(";
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
79 {
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
80 if (i > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
81 buf << ", ";
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
84 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
f8c27dad3643 [project @ 2004-09-17 11:42:04 by jwe]
jwe
parents: 4988
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
94
5007
f8c27dad3643 [project @ 2004-09-17 11:42:04 by jwe]
jwe
parents: 4988
diff changeset
95 if (parse_status == 0)
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
96 {
5007
f8c27dad3643 [project @ 2004-09-17 11:42:04 by jwe]
jwe
parents: 4988
diff changeset
97 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value ();
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
98
5007
f8c27dad3643 [project @ 2004-09-17 11:42:04 by jwe]
jwe
parents: 4988
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
123 }
5007
f8c27dad3643 [project @ 2004-09-17 11:42:04 by jwe]
jwe
parents: 4988
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
126 error ("inline: unable to define function");
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
127 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
128
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
129 // This function is supplied to allow a Matlab style class structure
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
130 // to be returned..
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
131 octave_map
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
132 octave_fcn_inline::map_value (void) const
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
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
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
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
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
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
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
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
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
151
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
152 return m;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
153 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6547
diff changeset
154
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
155 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6973
diff changeset
156 octave_fcn_inline::save_ascii (std::ostream& os)
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
162 // Write an invalid value to flag empty fcn handle name.
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
163 os << "0\n";
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
167 return true;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
168 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
169
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
170 bool
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
171 octave_fcn_inline::load_ascii (std::istream& is)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
172 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
173 int nargs;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
174 if (extract_keyword (is, "nargs", nargs, true))
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
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
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
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
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
186
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
187 if (is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
188 {
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
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
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
199
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
200 return true;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
201 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
202 else
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
203 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
204 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
205
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
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
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
223 return true;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
224 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
225
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
226 bool
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
229 {
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
230 int32_t nargs;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
231 if (! is.read (reinterpret_cast<char *> (&nargs), 4))
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
232 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
233 if (swap)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
234 swap_bytes<4> (&nargs);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
235
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
236 if (nargs < 1)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
237 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
238 else
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
239 {
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
256
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
261
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
262 OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
265
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
266 if (! is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
267 return false;
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
268
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5642
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
273
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
274 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
277
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
278 if (! is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
279 return false;
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
283 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
284 return true;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
285 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
286
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
304
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
315
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
316 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
317
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
320 hdims[0] = len + 1;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
323 if (space_hid < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
324 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
325 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
326 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
335 if (data_hid < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
336 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
337 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
338 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
339 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
340 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
343
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
351 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
355
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
356 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
357 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
360 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
361 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
362 return false;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
363 }
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
364
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
365 // attach the type of the variable
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
368 if (type_hid < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
369 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
370 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
371 return false;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
372 }
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
373
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
376 if (space_hid < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
377 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
378 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
379 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
380 return false;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
392 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
393 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
394 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
395 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
396 return false;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
397 }
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
398 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
399
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
402 if (type_hid < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
403 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
404 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
405 return false;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
406 }
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
418 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
419 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
420 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
421 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
422 return false;
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
423 }
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
424
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
425 H5Dclose (data_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
426 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
427 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4973
diff changeset
428 H5Gclose (group_hid);
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
437 return retval;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
438 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
439
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
445 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
446 hsize_t rank;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
447 int slen;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
461 space_hid = H5Dget_space (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
462 rank = H5Sget_simple_extent_ndims (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
463
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
464 if (rank != 2)
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
465 {
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
466 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
467 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
468 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
469 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
470 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
471
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
472 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
473 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
474
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
475 H5Sget_simple_extent_dims (space_hid, hdims, maxdims);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
478
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
479 OCTAVE_LOCAL_BUFFER (char, s1, hdims[0] * hdims[1]);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
483 {
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
484 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
485 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
486 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
487 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
488 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
489
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
490 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
491 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
492
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
501
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
502 if (data_hid < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
503 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
504 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
505 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
506 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
507
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
508 type_hid = H5Dget_type (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
509 type_class_hid = H5Tget_class (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
510
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
511 if (type_class_hid != H5T_STRING)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
512 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
513 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
514 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
515 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
516 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
517 }
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
518
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
519 space_hid = H5Dget_space (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
520 rank = H5Sget_simple_extent_ndims (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
521
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
522 if (rank != 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
523 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
524 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
525 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
526 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
527 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
528 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
529 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
530
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
531 slen = H5Tget_size (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
532 if (slen < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
533 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
534 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
535 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
536 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
537 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
538 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
539 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
540
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
541 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
542
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
543 // create datatype for (null-terminated) string to read into:
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
544 st_id = H5Tcopy (H5T_C_S1);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
545 H5Tset_size (st_id, slen);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
549 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
550 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
551 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
552 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
553 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
554 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
555 H5Tclose (st_id);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
564
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
565 if (data_hid < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
566 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
567 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
568 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
569 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
570
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
571 type_hid = H5Dget_type (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
572 type_class_hid = H5Tget_class (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
573
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
574 if (type_class_hid != H5T_STRING)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
575 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
576 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
577 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
578 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
579 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
580 }
4973
c969a018c928 [project @ 2004-09-08 17:07:11 by jwe]
jwe
parents: 4972
diff changeset
581
4972
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
582 space_hid = H5Dget_space (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
583 rank = H5Sget_simple_extent_ndims (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
584
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
585 if (rank != 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
586 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
587 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
588 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
589 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
590 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
591 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
592 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
593
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
594 slen = H5Tget_size (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
595 if (slen < 0)
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
596 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
597 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
598 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
599 H5Dclose (data_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
600 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
601 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
602 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
603
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
604 OCTAVE_LOCAL_BUFFER (char, iftext_tmp, slen);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
605
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
606 // create datatype for (null-terminated) string to read into:
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
607 st_id = H5Tcopy (H5T_C_S1);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
608 H5Tset_size (st_id, slen);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
612 {
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
613 H5Sclose (space_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
614 H5Tclose (type_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
615 H5Gclose (group_hid);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
616 return false;
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
617 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
618 H5Tclose (st_id);
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
624
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
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
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
635 }
724675f7f7cb [project @ 2004-09-08 17:00:20 by jwe]
jwe
parents: 4966
diff changeset
636
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
639 {
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
640 print_raw (os, pr_as_read_syntax);
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
641 newline (os);
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
642 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
643
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
644 void
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
645 octave_fcn_inline::print_raw (std::ostream& os, bool pr_as_read_syntax) const
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
646 {
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
647 std::ostringstream buf;
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
650 buf << "f(";
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
655 {
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
656 if (i)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
657 buf << ", ";
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
660 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
663
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
666 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
667
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
668 octave_value
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5164
diff changeset
669 octave_fcn_inline::convert_to_str_internal (bool, bool, char type) const
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
670 {
5279
bd32f770c09a [project @ 2005-04-12 21:55:31 by jwe]
jwe
parents: 5164
diff changeset
671 return octave_value (fcn_text (), type);
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
672 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
673
6973
6fcc2f5b2c7d [project @ 2007-10-08 10:22:17 by jwe]
jwe
parents: 6635
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
701 {
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
702 int nargin = args.length ();
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
821 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
834 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
835
7394
872b263b7e62 [project @ 2008-01-17 10:16:15 by dbateman]
dbateman
parents: 7017
diff changeset
836 /*
872b263b7e62 [project @ 2008-01-17 10:16:15 by dbateman]
dbateman
parents: 7017
diff changeset
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
872b263b7e62 [project @ 2008-01-17 10:16:15 by dbateman]
dbateman
parents: 7017
diff changeset
839 %!assert (feval (fn, 6), 37)
872b263b7e62 [project @ 2008-01-17 10:16:15 by dbateman]
dbateman
parents: 7017
diff changeset
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
872b263b7e62 [project @ 2008-01-17 10:16:15 by dbateman]
dbateman
parents: 7017
diff changeset
851 */
872b263b7e62 [project @ 2008-01-17 10:16:15 by dbateman]
dbateman
parents: 7017
diff changeset
852
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
872 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
908 }
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
fda074a55b5c [project @ 2005-07-11 08:41:16 by dbateman]
dbateman
parents: 5307
diff changeset
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
fda074a55b5c [project @ 2005-07-11 08:41:16 by dbateman]
dbateman
parents: 5307
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents:
diff changeset
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 */