Mercurial > octave
annotate libinterp/octave-value/ov-cell.cc @ 29476:c74ff452e2bb stable
avoid memory leaks when returning handles to nested functions
When a handle to a nested function is created with a std::shared_ptr
object holding a reference to the stack frames associated with the
parent function, we create a circular reference because the referenced
stack frame contains the function handle object. To break the link,
we'll scan the stack frame associated with the nested function handle
and convert the shared_ptr links to be weak_ptr links instead,
breaking the circular reference allowing the resources held by the
closure frames to be released when all external references are cleared.
Another possible solution to this problem is to create weak_ptr links
initially and then convert them to shared_ptr links when the closure
"escapes" the scope of the function. While that might be slightly
more efficient (we would only have to look at assignments to global
variables and the values that are actually returned from the
function) the current design of global assignments does not make that
easy because it is possible to ask for a reference to a global
variable, so either all places where we grab references and then later
perform assignments must be checked for assignments of handles to
nested functions, or we must eliminate the interface that returns
references to global variables and only allow assignments so that we
would only have to perform the check in the assignment function(s).
Perhaps this can be done in a future version, but for now, it works
well enough to break the closure cycles in local variables when a
function returns.
* call-stack.cc (call_stack::pop): If popped stack frame is a closure
context, then break closure cycles.
* stack-frame.h, stack-frame.cc (stack_frame::m_is_closure_context):
New member variable.
(stack_frame::break_closure_cycles,
user_fcn_stack_frame::break_closure_cycles): New functions.
(stack_frame::mark_closure_context, stack_frame::is_closure_context):
New functions.
* ov-fcn-handle.h, ov-fcn-handle.cc (base_nested_fcn_handle):
New base class for handles to nested functions.
(nested_fcn_handle, weak_nested_fcn_handle): New classes to represent
handles to nested functions. Currently, all handles to nested
functions begin as nested_fcn_handle objects but are converted to
weak_nested_fcn_handles when the functions where they are created
return.
(base_fcn_handle::is_nested (const std::shared_ptr<stack_frame>&) const,
base_fcn_handle::make_weak_nested_handle,
New virtual functions.
(octave_fcn_handle::is_nested, octave_fcn_handle::is_weak_nested,
octave_fcn_handle::make_weak_nested_handle): New functions.
* ov-struct.h, ov-struct.cc (octave_scalar_map::break_closure_cycles,
octave_map::break_closure_cycles): New functions.
* ov.h, ov.cc (octave_value::break_closure_cycles): New function.
* ov-base.h (octave_base_value::break_closure_cycles): New virtual function.
* cdef-object.h (cdef_object::break_closure_cycles): New function.
(cdef_object_rep::break_closure_cycles): New virtual function.
* cdef-object.h, cdef-object.cc (cdef_object_scalar::break_closure_cycles):
New function.
* ov-cell.h, ov-cell.cc (octave_cell::break_closure_cycles): New function.
* ov-class.h, ov-class.cc (octave_class::break_closure_cycles): New function.
* ov-classdef.h (octave_classdef::break_closure_cycles): New function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 05 Mar 2021 16:14:34 -0500 |
parents | 0a5b15007766 |
children | e88444be8468 d13d090cb03a |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
28495
diff
changeset
|
3 // Copyright (C) 1999-2021 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
3353 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21691
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21211
diff
changeset
|
27 # include "config.h" |
3353 | 28 #endif |
29 | |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
30 #include <istream> |
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
31 #include <ostream> |
5765 | 32 #include <sstream> |
5164 | 33 #include <vector> |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
34 #include <queue> |
3353 | 35 |
5360 | 36 #include "Array-util.h" |
37 #include "byte-swap.h" | |
3353 | 38 #include "lo-utils.h" |
4153 | 39 #include "quit.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
40 #include "oct-locbuf.h" |
3353 | 41 |
23454
30b6eccd6708
use builtin-defun-decls.h to ensure declarations of interpreter functions
John W. Eaton <jwe@octave.org>
parents:
23352
diff
changeset
|
42 #include "builtin-defun-decls.h" |
3353 | 43 #include "defun.h" |
44 #include "error.h" | |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15057
diff
changeset
|
45 #include "mxarray.h" |
3353 | 46 #include "ov-cell.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
47 #include "ovl.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
|
48 #include "oct-hdf5.h" |
3353 | 49 #include "unwind-prot.h" |
3354 | 50 #include "utils.h" |
3928 | 51 #include "ov-base-mat.h" |
52 #include "ov-base-mat.cc" | |
29476
c74ff452e2bb
avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
53 #include "ov-fcn-handle.h" |
3928 | 54 #include "ov-re-mat.h" |
55 #include "ov-scalar.h" | |
5360 | 56 #include "pr-output.h" |
57 #include "ov-scalar.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
58 #include "errwarn.h" |
3928 | 59 |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
60 #include "ls-oct-text.h" |
4687 | 61 #include "ls-oct-binary.h" |
62 #include "ls-hdf5.h" | |
63 #include "ls-utils.h" | |
64 | |
8679
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
65 // Cell is able to handle octave_value indexing by itself, so just forward |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
66 // everything. |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
67 |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
68 template <> |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
69 octave_value |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
70 octave_base_matrix<Cell>::do_index_op (const octave_value_list& idx, |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
71 bool resize_ok) |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
72 { |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
73 return matrix.index (idx, resize_ok); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
74 } |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
75 |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
76 template <> |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
77 void |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
78 octave_base_matrix<Cell>::assign (const octave_value_list& idx, const Cell& rhs) |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
79 { |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
80 matrix.assign (idx, rhs); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
81 } |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
82 |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
83 template <> |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
84 void |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
85 octave_base_matrix<Cell>::assign (const octave_value_list& idx, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
86 octave_value rhs) |
8679
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
87 { |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
88 // FIXME: Really? |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23575
diff
changeset
|
89 if (rhs.iscell ()) |
8679
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
90 matrix.assign (idx, rhs.cell_value ()); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
91 else |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
92 matrix.assign (idx, Cell (rhs)); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
93 } |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
94 |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
95 template <> |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
96 void |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
97 octave_base_matrix<Cell>::delete_elements (const octave_value_list& idx) |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
98 { |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
99 matrix.delete_elements (idx); |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
100 } |
280fae940bb0
optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
101 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
102 // FIXME: this list of specializations is becoming so long that we should |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
103 // really ask whether octave_cell should inherit from octave_base_matrix at all. |
10670
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
104 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
105 template <> |
24643
78aff6f14227
more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents:
24620
diff
changeset
|
106 std::string |
24700
aaf7bcea71dd
Silence build warnings about unused parameters.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
24668
diff
changeset
|
107 octave_base_matrix<Cell>::edit_display (const float_display_format&, |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24655
diff
changeset
|
108 octave_idx_type i, |
24643
78aff6f14227
more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents:
24620
diff
changeset
|
109 octave_idx_type j) const |
78aff6f14227
more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents:
24620
diff
changeset
|
110 { |
78aff6f14227
more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents:
24620
diff
changeset
|
111 octave_value val = matrix(i,j); |
78aff6f14227
more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents:
24620
diff
changeset
|
112 |
24655
3ceee1910e1a
allow single character strings to be edited (bug #51848)
John W. Eaton <jwe@octave.org>
parents:
24652
diff
changeset
|
113 std::string tname = val.type_name (); |
3ceee1910e1a
allow single character strings to be edited (bug #51848)
John W. Eaton <jwe@octave.org>
parents:
24652
diff
changeset
|
114 dim_vector dv = val.dims (); |
3ceee1910e1a
allow single character strings to be edited (bug #51848)
John W. Eaton <jwe@octave.org>
parents:
24652
diff
changeset
|
115 std::string dimstr = dv.str (); |
3ceee1910e1a
allow single character strings to be edited (bug #51848)
John W. Eaton <jwe@octave.org>
parents:
24652
diff
changeset
|
116 return "[" + dimstr + " " + tname + "]"; |
24643
78aff6f14227
more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents:
24620
diff
changeset
|
117 } |
78aff6f14227
more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents:
24620
diff
changeset
|
118 |
78aff6f14227
more variable editor improvements; allow more variable types to be edited
John W. Eaton <jwe@octave.org>
parents:
24620
diff
changeset
|
119 template <> |
10670
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
120 octave_value |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
121 octave_base_matrix<Cell>::fast_elem_extract (octave_idx_type n) const |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
122 { |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
123 if (n < matrix.numel ()) |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
124 return Cell (matrix(n)); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
125 else |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
126 return octave_value (); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
127 } |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
128 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
129 template <> |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
130 bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
131 octave_base_matrix<Cell>::fast_elem_insert (octave_idx_type n, |
10670
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
132 const octave_value& x) |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
133 { |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27060
diff
changeset
|
134 const octave_cell *xrep = dynamic_cast<const octave_cell *> (&x.get_rep ()); |
10670
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
135 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
136 bool retval = xrep && xrep->matrix.numel () == 1 && n < matrix.numel (); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
137 if (retval) |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
138 matrix(n) = xrep->matrix(0); |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
139 |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
140 return retval; |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
141 } |
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10600
diff
changeset
|
142 |
3928 | 143 template class octave_base_matrix<Cell>; |
3353 | 144 |
4612 | 145 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cell, "cell", "cell"); |
3353 | 146 |
29476
c74ff452e2bb
avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
147 void octave_cell::break_closure_cycles (const std::shared_ptr<octave::stack_frame>& frame) |
c74ff452e2bb
avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
148 { |
c74ff452e2bb
avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
149 for (octave_idx_type i = 0; i < matrix.numel (); i++) |
c74ff452e2bb
avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
150 matrix(i).break_closure_cycles (frame); |
c74ff452e2bb
avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
151 } |
c74ff452e2bb
avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
152 |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
153 octave_value_list |
4247 | 154 octave_cell::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
155 const std::list<octave_value_list>& idx, |
23481
73558a835b64
eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
156 int nargout) |
3933 | 157 { |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
158 octave_value_list retval; |
3933 | 159 |
160 switch (type[0]) | |
161 { | |
162 case '(': | |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
163 retval(0) = do_index_op (idx.front ()); |
3933 | 164 break; |
165 | |
166 case '{': | |
167 { | |
27060
3140380861ce
error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
168 if (idx.front ().empty ()) |
3140380861ce
error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
169 error ("invalid empty index expression"); |
3140380861ce
error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
170 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
171 octave_value tmp = do_index_op (idx.front ()); |
3933 | 172 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
173 Cell tcell = tmp.cell_value (); |
4582 | 174 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
175 if (tcell.numel () == 1) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
176 retval(0) = tcell(0,0); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
177 else |
23352
778fdffc09df
deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents:
23350
diff
changeset
|
178 { |
778fdffc09df
deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents:
23350
diff
changeset
|
179 // Return a comma-separated list. |
778fdffc09df
deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents:
23350
diff
changeset
|
180 retval = octave_value (octave_value_list (tcell)); |
778fdffc09df
deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents:
23350
diff
changeset
|
181 } |
3933 | 182 } |
183 break; | |
184 | |
185 case '.': | |
186 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
187 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
188 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
3933 | 189 } |
190 break; | |
191 | |
192 default: | |
193 panic_impossible (); | |
194 } | |
195 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
196 // FIXME: perhaps there should be an |
4994 | 197 // octave_value_list::next_subsref member function? See also |
198 // octave_user_function::subsref. | |
199 | |
200 if (idx.size () > 1) | |
23481
73558a835b64
eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
201 retval = retval(0).next_subsref (nargout, type, idx); |
4994 | 202 |
203 return retval; | |
3933 | 204 } |
205 | |
206 octave_value | |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
207 octave_cell::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
208 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
209 bool auto_add) |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
210 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
211 octave_value retval; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
212 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
213 switch (type[0]) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
214 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
215 case '(': |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
216 retval = do_index_op (idx.front (), auto_add); |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
217 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
218 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
219 case '{': |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
220 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
221 octave_value tmp = do_index_op (idx.front (), auto_add); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
222 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
223 const Cell tcell = tmp.cell_value (); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
224 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
225 if (tcell.numel () == 1) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
226 retval = tcell(0,0); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
227 else |
23352
778fdffc09df
deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents:
23350
diff
changeset
|
228 { |
778fdffc09df
deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents:
23350
diff
changeset
|
229 // Return a comma-separated list. |
778fdffc09df
deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents:
23350
diff
changeset
|
230 retval = octave_value (octave_value_list (tcell)); |
778fdffc09df
deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents:
23350
diff
changeset
|
231 } |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
232 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
233 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
234 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
235 case '.': |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
236 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
237 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
238 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
239 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
240 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
241 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
242 default: |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
243 panic_impossible (); |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
244 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
245 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
246 // FIXME: perhaps there should be an |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
247 // octave_value_list::next_subsref member function? See also |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
248 // octave_user_function::subsref. |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
249 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
250 if (idx.size () > 1) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
251 retval = retval.next_subsref (auto_add, type, idx); |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
252 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
253 return retval; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
254 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
255 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
256 octave_value |
4247 | 257 octave_cell::subsasgn (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
258 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
259 const octave_value& rhs) |
3933 | 260 { |
261 octave_value retval; | |
262 | |
263 int n = type.length (); | |
264 | |
265 octave_value t_rhs = rhs; | |
266 | |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
267 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
268 |
9286
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
269 if (idx.front ().empty ()) |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
270 error ("missing index in indexed assignment"); |
9286
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
271 |
3933 | 272 if (n > 1) |
273 { | |
274 switch (type[0]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
275 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
276 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
277 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
278 if (isempty () && type[1] == '.') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
279 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
280 // Allow conversion of empty cell array to some other |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
281 // type in cases like |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
282 // |
10871
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
283 // x = {}; x(i).f = rhs |
3933 | 284 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
285 octave_value tmp = octave_value::empty_conv (type, rhs); |
3933 | 286 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
287 return tmp.subsasgn (type, idx, rhs); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
288 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
289 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
290 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
291 octave_value tmp = do_index_op (idx.front (), true); |
3933 | 292 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
293 if (! tmp.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
294 tmp = octave_value::empty_conv (type.substr (1), rhs); |
3933 | 295 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
296 std::list<octave_value_list> next_idx (idx); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
297 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
298 next_idx.erase (next_idx.begin ()); |
4362 | 299 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
300 tmp.make_unique (); |
6767 | 301 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
302 t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
303 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
304 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
305 break; |
3933 | 306 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
307 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
308 { |
9106
1eb5b24186b6
fix nested cell assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
309 matrix.make_unique (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
310 Cell tmpc = matrix.index (idx.front (), true); |
3933 | 311 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
312 std::list<octave_value_list> next_idx (idx); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
313 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
314 next_idx.erase (next_idx.begin ()); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
315 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
316 std::string next_type = type.substr (1); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
317 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
318 if (tmpc.numel () != 1) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
319 err_indexed_cs_list (); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
320 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
321 octave_value tmp = tmpc(0); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
322 tmpc = Cell (); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
323 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
324 if (! tmp.is_defined () || tmp.is_zero_by_zero ()) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
325 { |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
326 tmp = octave_value::empty_conv (type.substr (1), rhs); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
327 tmp.make_unique (); // probably a no-op. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
328 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
329 else |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
330 // optimization: ignore copy still stored inside array. |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
331 tmp.make_unique (1); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
332 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
333 t_rhs = tmp.subsasgn (next_type, next_idx, rhs); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
334 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
335 break; |
3933 | 336 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
337 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
338 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
339 if (! isempty ()) |
10871
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
340 { |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
341 std::string nm = type_name (); |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
342 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
343 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
344 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
345 // Do nothing; the next branch will handle it. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
346 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
347 break; |
3933 | 348 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
349 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
350 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
351 } |
3933 | 352 } |
353 | |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
354 switch (type[0]) |
3933 | 355 { |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
356 case '(': |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
357 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
358 octave_value_list i = idx.front (); |
3933 | 359 |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23575
diff
changeset
|
360 if (t_rhs.iscell ()) |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
361 octave_base_matrix<Cell>::assign (i, t_rhs.cell_value ()); |
23589
63950abd2f81
maint: Deprecate is_null_type and replace with isnull.
Rik <rik@octave.org>
parents:
23588
diff
changeset
|
362 else if (t_rhs.isnull ()) |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
363 octave_base_matrix<Cell>::delete_elements (i); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
364 else |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
365 octave_base_matrix<Cell>::assign (i, Cell (t_rhs)); |
3933 | 366 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
367 count++; |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
368 retval = octave_value (this); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
369 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
370 break; |
3933 | 371 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
372 case '{': |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
373 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
374 octave_value_list idxf = idx.front (); |
5846 | 375 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
376 if (t_rhs.is_cs_list ()) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
377 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
378 Cell tmp_cell = Cell (t_rhs.list_value ()); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
379 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
380 // Inquire the proper shape of the RHS. |
8587
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
381 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
382 dim_vector didx = dims ().redim (idxf.length ()); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
383 for (octave_idx_type k = 0; k < idxf.length (); k++) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
384 if (! idxf(k).is_magic_colon ()) didx(k) = idxf(k).numel (); |
7040 | 385 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
386 if (didx.numel () == tmp_cell.numel ()) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
387 tmp_cell = tmp_cell.reshape (didx); |
8587
35656d6ad061
properly reshape cs-lists assigned to struct & cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8580
diff
changeset
|
388 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
389 octave_base_matrix<Cell>::assign (idxf, tmp_cell); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
390 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
391 else if (idxf.all_scalars () |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
392 || do_index_op (idxf, true).numel () == 1) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
393 // Regularize a null matrix if stored into a cell. |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
394 octave_base_matrix<Cell>::assign (idxf, |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
395 Cell (t_rhs.storable_value ())); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
396 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
397 err_nonbraced_cs_list_assignment (); |
3933 | 398 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
399 count++; |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
400 retval = octave_value (this); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
401 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
402 break; |
10871
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
403 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
404 case '.': |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
405 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
406 if (! isempty ()) |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
407 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
408 std::string nm = type_name (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
409 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
410 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
411 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
412 // Allow conversion of empty cell array to some other |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
413 // type in cases like |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
414 // |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
415 // x = {}; x.f = rhs |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
416 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
417 octave_value tmp = octave_value::empty_conv (type, rhs); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
418 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
419 return tmp.subsasgn (type, idx, rhs); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
420 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
421 break; |
3933 | 422 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
423 default: |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
424 panic_impossible (); |
3933 | 425 } |
426 | |
427 return retval; | |
428 } | |
429 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
430 bool |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
431 octave_cell::iscellstr (void) const |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
432 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
433 bool retval; |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
434 if (cellstr_cache.get ()) |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
435 retval = true; |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
436 else |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
437 { |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
438 retval = matrix.iscellstr (); |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
439 // Allocate empty cache to mark that this is indeed a cellstr. |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
440 if (retval) |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
441 cellstr_cache.reset (new Array<std::string> ()); |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
442 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
443 |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
444 return retval; |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
445 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
446 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
447 void |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
448 octave_cell::assign (const octave_value_list& idx, const Cell& rhs) |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
449 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
450 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
451 octave_base_matrix<Cell>::assign (idx, rhs); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
452 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
453 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
454 void |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
455 octave_cell::assign (const octave_value_list& idx, const octave_value& rhs) |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
456 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
457 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
458 octave_base_matrix<Cell>::assign (idx, rhs); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
459 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
460 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
461 void |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
462 octave_cell::delete_elements (const octave_value_list& idx) |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
463 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
464 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
465 octave_base_matrix<Cell>::delete_elements (idx); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
466 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
467 |
4791 | 468 size_t |
469 octave_cell::byte_size (void) const | |
470 { | |
471 size_t retval = 0; | |
472 | |
5275 | 473 for (octave_idx_type i = 0; i < numel (); i++) |
4791 | 474 retval += matrix(i).byte_size (); |
475 | |
476 return retval; | |
477 } | |
478 | |
8732 | 479 octave_value |
480 octave_cell::sort (octave_idx_type dim, sortmode mode) const | |
481 { | |
482 octave_value retval; | |
483 | |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
484 if (! iscellstr ()) |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
485 error ("sort: only cell arrays of character strings may be sorted"); |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
486 |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
487 Array<std::string> tmp = cellstr_value (); |
8824
76ddf0ab985d
auto-set cellstr cache when sorting cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8823
diff
changeset
|
488 |
20681
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
489 tmp = tmp.sort (dim, mode); |
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
490 |
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
491 // We already have the cache. |
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
492 retval = new octave_cell (tmp); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
493 |
8732 | 494 return retval; |
495 } | |
496 | |
497 octave_value | |
498 octave_cell::sort (Array<octave_idx_type> &sidx, octave_idx_type dim, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
499 sortmode mode) const |
8732 | 500 { |
501 octave_value retval; | |
502 | |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
503 if (! iscellstr ()) |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
504 error ("sort: only cell arrays of character strings may be sorted"); |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
505 |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
506 Array<std::string> tmp = cellstr_value (); |
8824
76ddf0ab985d
auto-set cellstr cache when sorting cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8823
diff
changeset
|
507 |
20681
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
508 tmp = tmp.sort (sidx, dim, mode); |
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
509 |
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
510 // We already have the cache. |
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
511 retval = new octave_cell (tmp); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
512 |
8732 | 513 return retval; |
514 } | |
515 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
516 sortmode |
23588
0549061d35b9
maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
517 octave_cell::issorted (sortmode mode) const |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
518 { |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
519 sortmode retval = UNSORTED; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
520 |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
521 if (! iscellstr ()) |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
522 error ("issorted: A is not a cell array of strings"); |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
523 |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
524 Array<std::string> tmp = cellstr_value (); |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
525 |
23588
0549061d35b9
maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
526 retval = tmp.issorted (mode); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
527 |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
528 return retval; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
529 } |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
530 |
8732 | 531 Array<octave_idx_type> |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8732
diff
changeset
|
532 octave_cell::sort_rows_idx (sortmode mode) const |
8732 | 533 { |
534 Array<octave_idx_type> retval; | |
535 | |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
536 if (! iscellstr ()) |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
537 error ("sortrows: only cell arrays of character strings may be sorted"); |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
538 |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
539 Array<std::string> tmp = cellstr_value (); |
8732 | 540 |
20681
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
541 retval = tmp.sort_rows_idx (mode); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
542 |
8732 | 543 return retval; |
544 } | |
545 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
546 sortmode |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
547 octave_cell::is_sorted_rows (sortmode mode) const |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
548 { |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
549 sortmode retval = UNSORTED; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
550 |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
551 if (! iscellstr ()) |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
552 error ("issorted: A is not a cell array of strings"); |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
553 |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
554 Array<std::string> tmp = cellstr_value (); |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
555 |
20681
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
556 retval = tmp.is_sorted_rows (mode); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
557 |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
558 return retval; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
559 } |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
560 |
8626
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
561 bool |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
562 octave_cell::is_true (void) const |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
563 { |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
564 error ("invalid conversion from cell array to logical value"); |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
565 } |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
566 |
3933 | 567 octave_value_list |
568 octave_cell::list_value (void) const | |
569 { | |
8580
188d38a553c7
further indexing optimization touches
Jaroslav Hajek <highegg@gmail.com>
parents:
8579
diff
changeset
|
570 return octave_value_list (matrix); |
3933 | 571 } |
572 | |
4243 | 573 string_vector |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
574 octave_cell::string_vector_value (bool pad) const |
4243 | 575 { |
4358 | 576 string_vector retval; |
577 | |
7285 | 578 octave_idx_type nel = numel (); |
4243 | 579 |
4358 | 580 int n_elts = 0; |
581 | |
5275 | 582 octave_idx_type max_len = 0; |
4358 | 583 |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
584 std::queue<string_vector> strvec_queue; |
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
585 |
7285 | 586 for (octave_idx_type i = 0; i < nel; i++) |
4358 | 587 { |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
588 string_vector s = matrix(i).string_vector_value (); |
7285 | 589 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
590 octave_idx_type s_len = s.numel (); |
4358 | 591 |
7285 | 592 n_elts += s_len ? s_len : 1; |
4358 | 593 |
7285 | 594 octave_idx_type s_max_len = s.max_length (); |
4358 | 595 |
7285 | 596 if (s_max_len > max_len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
597 max_len = s_max_len; |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
598 |
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
599 strvec_queue.push (s); |
4358 | 600 } |
601 | |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
602 retval = string_vector (n_elts); |
4243 | 603 |
5275 | 604 octave_idx_type k = 0; |
4243 | 605 |
7285 | 606 for (octave_idx_type i = 0; i < nel; i++) |
4243 | 607 { |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
608 const string_vector s = strvec_queue.front (); |
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
609 strvec_queue.pop (); |
7285 | 610 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
611 octave_idx_type s_len = s.numel (); |
4358 | 612 |
7285 | 613 if (s_len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
614 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
615 for (octave_idx_type j = 0; j < s_len; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
616 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
617 std::string t = s[j]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
618 int t_len = t.length (); |
5715 | 619 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
620 if (pad && max_len > t_len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
621 t += std::string (max_len - t_len, ' '); |
5715 | 622 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
623 retval[k++] = t; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
624 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
625 } |
7285 | 626 else if (pad) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
627 retval[k++] = std::string (max_len, ' '); |
7285 | 628 else |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
629 retval[k++] = ""; |
4243 | 630 } |
631 | |
632 return retval; | |
633 } | |
634 | |
8732 | 635 Array<std::string> |
636 octave_cell::cellstr_value (void) const | |
637 { | |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
638 if (! iscellstr ()) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
639 error ("invalid conversion from cell array to array of strings"); |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
640 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
641 if (cellstr_cache->isempty ()) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
642 *cellstr_cache = matrix.cellstr_value (); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
643 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
644 return *cellstr_cache; |
8732 | 645 } |
646 | |
4604 | 647 bool |
648 octave_cell::print_as_scalar (void) const | |
649 { | |
11474 | 650 return true; |
4604 | 651 } |
652 | |
3933 | 653 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18409
diff
changeset
|
654 octave_cell::print (std::ostream& os, bool) |
3933 | 655 { |
656 print_raw (os); | |
657 } | |
658 | |
659 void | |
660 octave_cell::print_raw (std::ostream& os, bool) const | |
661 { | |
4587 | 662 int nd = matrix.ndims (); |
4513 | 663 |
4587 | 664 if (nd == 2) |
4513 | 665 { |
5275 | 666 octave_idx_type nr = rows (); |
667 octave_idx_type nc = columns (); | |
4513 | 668 |
669 if (nr > 0 && nc > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
670 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
671 indent (os); |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
672 os << '{'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
673 newline (os); |
4513 | 674 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
675 increment_indent_level (); |
4513 | 676 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
677 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
678 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
679 for (octave_idx_type i = 0; i < nr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
680 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
681 octave_quit (); |
4513 | 682 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
683 std::ostringstream buf; |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
684 buf << '[' << i+1 << ',' << j+1 << ']'; |
3933 | 685 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
686 octave_value val = matrix(i,j); |
4513 | 687 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
688 val.print_with_name (os, buf.str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
689 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
690 } |
4513 | 691 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
692 decrement_indent_level (); |
4513 | 693 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
694 indent (os); |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
695 os << '}'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
696 newline (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
697 } |
4513 | 698 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
699 { |
9781
ea88eece12f5
fix printing of empty cells
Jaroslav Hajek <highegg@gmail.com>
parents:
9370
diff
changeset
|
700 indent (os); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
701 os << "{}"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
702 if (Vprint_empty_dimensions) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
703 os << '(' << nr << 'x' << nc << ')'; |
9781
ea88eece12f5
fix printing of empty cells
Jaroslav Hajek <highegg@gmail.com>
parents:
9370
diff
changeset
|
704 newline (os); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
705 } |
4513 | 706 } |
707 else | |
3933 | 708 { |
709 indent (os); | |
4513 | 710 dim_vector dv = matrix.dims (); |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
711 os << '{' << dv.str () << " Cell Array}"; |
3933 | 712 newline (os); |
713 } | |
714 } | |
715 | |
23350
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
716 bool |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
717 octave_cell::print_name_tag (std::ostream& os, const std::string& name) const |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
718 { |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
719 bool retval = false; |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
720 |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
721 indent (os); |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
722 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
723 if (isempty () || ndims () > 2) |
23350
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
724 os << name << " = "; |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
725 else |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
726 { |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
727 os << name << " ="; |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
728 newline (os); |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
729 retval = true; |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
730 } |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
731 |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
732 return retval; |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
733 } |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
734 |
17870 | 735 void |
736 octave_cell::short_disp (std::ostream& os) const | |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
737 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
738 os << (matrix.isempty () ? "{}" : "..."); |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
739 } |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
740 |
4687 | 741 #define CELL_ELT_TAG "<cell-element>" |
742 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
743 bool |
6974 | 744 octave_cell::save_ascii (std::ostream& os) |
4687 | 745 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
746 dim_vector dv = dims (); |
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
747 if (dv.ndims () > 2) |
4687 | 748 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
749 os << "# ndims: " << dv.ndims () << "\n"; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
750 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
751 for (int i = 0; i < dv.ndims (); i++) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
752 os << ' ' << dv(i); |
4687 | 753 os << "\n"; |
754 | |
755 Cell tmp = cell_value (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
756 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
757 for (octave_idx_type i = 0; i < dv.numel (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
758 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
759 octave_value o_val = tmp.elem (i); |
4687 | 760 |
23350
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
761 // Recurse to save sub-value. |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
762 bool b = save_text_data (os, o_val, CELL_ELT_TAG, false, 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
763 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
764 if (! b) |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17874
diff
changeset
|
765 return ! os.fail (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
766 } |
4687 | 767 } |
768 else | |
769 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
770 // Keep this case, rather than use generic code above for backward |
20449
df4165dfc676
maint: Fix misspelled word compatibility in code comments.
Rik <rik@octave.org>
parents:
20447
diff
changeset
|
771 // compatibility. Makes load_ascii much more complex!! |
4687 | 772 os << "# rows: " << rows () << "\n" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
773 << "# columns: " << columns () << "\n"; |
4687 | 774 |
775 Cell tmp = cell_value (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
776 |
5275 | 777 for (octave_idx_type j = 0; j < tmp.cols (); j++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
778 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
779 for (octave_idx_type i = 0; i < tmp.rows (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
780 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
781 octave_value o_val = tmp.elem (i, j); |
4687 | 782 |
23350
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
783 // Recurse to save sub-value. |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
784 bool b = save_text_data (os, o_val, CELL_ELT_TAG, false, 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
785 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
786 if (! b) |
18384
bd9d34f28b0f
Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents:
17874
diff
changeset
|
787 return ! os.fail (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
788 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
789 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
790 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
791 } |
4687 | 792 } |
793 | |
794 return true; | |
795 } | |
796 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
797 bool |
4687 | 798 octave_cell::load_ascii (std::istream& is) |
799 { | |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
800 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
801 |
5099 | 802 string_vector keywords(2); |
4687 | 803 |
5099 | 804 keywords[0] = "ndims"; |
805 keywords[1] = "rows"; | |
806 | |
807 std::string kw; | |
5275 | 808 octave_idx_type val = 0; |
5099 | 809 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
810 if (! extract_keyword (is, keywords, kw, val, true)) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
811 error ("load: failed to extract number of rows and columns"); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
812 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
813 if (kw == "ndims") |
4687 | 814 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
815 int mdims = static_cast<int> (val); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
816 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
817 if (mdims < 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
818 error ("load: failed to extract number of rows and columns"); |
4687 | 819 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
820 dim_vector dv; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
821 dv.resize (mdims); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
822 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
823 for (int i = 0; i < mdims; i++) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
824 is >> dv(i); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
825 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
826 Cell tmp(dv); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
827 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
828 for (octave_idx_type i = 0; i < dv.numel (); i++) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
829 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
830 octave_value t2; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
831 bool dummy; |
5099 | 832 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
833 // recurse to read cell elements |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
834 std::string nm = read_text_data (is, "", |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
835 dummy, t2, i); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
836 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
837 if (nm != CELL_ELT_TAG) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
838 error ("load: cell array element had unexpected name"); |
4687 | 839 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
840 if (is) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
841 tmp.elem (i) = t2; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
842 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
843 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
844 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
845 error ("load: failed to load matrix constant"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
846 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
847 matrix = tmp; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
848 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
849 else if (kw == "rows") |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
850 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
851 octave_idx_type nr = val; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
852 octave_idx_type nc = 0; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
853 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
854 if (nr < 0 || ! extract_keyword (is, "columns", nc) || nc < 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
855 error ("load: failed to extract number of rows and columns for cell array"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
856 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
857 if (nr > 0 && nc > 0) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
858 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
859 Cell tmp (nr, nc); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
860 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
861 for (octave_idx_type j = 0; j < nc; j++) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
862 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
863 for (octave_idx_type i = 0; i < nr; i++) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
864 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
865 octave_value t2; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
866 bool dummy; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
867 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
868 // recurse to read cell elements |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
869 std::string nm = read_text_data (is, "", |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
870 dummy, t2, i); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
871 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
872 if (nm != CELL_ELT_TAG) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
873 error ("load: cell array element had unexpected name"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
874 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
875 if (is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
876 tmp.elem (i, j) = t2; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
877 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
878 } |
4687 | 879 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
880 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
881 error ("load: failed to load cell element"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
882 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
883 matrix = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
884 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
885 else if (nr == 0 || nc == 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
886 matrix = Cell (nr, nc); |
4687 | 887 else |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
888 panic_impossible (); |
4687 | 889 } |
890 else | |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
891 panic_impossible (); |
4687 | 892 |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
893 return true; |
4687 | 894 } |
895 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
896 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
|
897 octave_cell::save_binary (std::ostream& os, bool save_as_floats) |
4687 | 898 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
899 dim_vector dv = dims (); |
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
900 if (dv.ndims () < 1) |
4687 | 901 return false; |
902 | |
903 // Use negative value for ndims | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
904 int32_t di = - dv.ndims (); |
5760 | 905 os.write (reinterpret_cast<char *> (&di), 4); |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
906 for (int i = 0; i < dv.ndims (); i++) |
4687 | 907 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
908 di = dv(i); |
5760 | 909 os.write (reinterpret_cast<char *> (&di), 4); |
4687 | 910 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
911 |
4687 | 912 Cell tmp = cell_value (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
913 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
914 for (octave_idx_type i = 0; i < dv.numel (); i++) |
4687 | 915 { |
916 octave_value o_val = tmp.elem (i); | |
917 | |
23350
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
918 // Recurse to save sub-value. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
919 bool b = save_binary_data (os, o_val, CELL_ELT_TAG, "", 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
920 save_as_floats); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
921 |
4687 | 922 if (! b) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
923 return false; |
4687 | 924 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
925 |
4687 | 926 return true; |
927 } | |
928 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
929 bool |
4687 | 930 octave_cell::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
|
931 octave::mach_info::float_format fmt) |
4687 | 932 { |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
933 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
934 |
5828 | 935 int32_t mdims; |
5760 | 936 if (! is.read (reinterpret_cast<char *> (&mdims), 4)) |
4687 | 937 return false; |
938 if (swap) | |
4944 | 939 swap_bytes<4> (&mdims); |
4687 | 940 if (mdims >= 0) |
941 return false; | |
942 | |
943 mdims = -mdims; | |
5828 | 944 int32_t di; |
4687 | 945 dim_vector dv; |
946 dv.resize (mdims); | |
947 | |
948 for (int i = 0; i < mdims; i++) | |
949 { | |
5760 | 950 if (! is.read (reinterpret_cast<char *> (&di), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
951 return false; |
4687 | 952 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
953 swap_bytes<4> (&di); |
4687 | 954 dv(i) = di; |
955 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
956 |
5157 | 957 // Convert an array with a single dimension to be a row vector. |
958 // Octave should never write files like this, other software | |
959 // might. | |
960 | |
961 if (mdims == 1) | |
962 { | |
963 mdims = 2; | |
964 dv.resize (mdims); | |
965 dv(1) = dv(0); | |
966 dv(0) = 1; | |
967 } | |
968 | |
5275 | 969 octave_idx_type nel = dv.numel (); |
4687 | 970 Cell tmp(dv); |
971 | |
5275 | 972 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 973 { |
974 octave_value t2; | |
975 bool dummy; | |
976 std::string doc; | |
977 | |
978 // recurse to read cell elements | |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
979 std::string nm = read_binary_data (is, swap, fmt, "", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
980 dummy, t2, doc); |
4687 | 981 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
982 if (nm != CELL_ELT_TAG) |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
983 error ("load: cell array element had unexpected name"); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
984 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
985 if (is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
986 tmp.elem (i) = t2; |
4687 | 987 } |
988 | |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
989 if (! is) |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
990 error ("load: failed to load matrix constant"); |
4687 | 991 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
992 matrix = tmp; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
993 |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
994 return true; |
4687 | 995 } |
996 | |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
997 void * |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
998 octave_cell::mex_get_data (void) const |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
999 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1000 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1001 return matrix.mex_get_data (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1002 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1003 |
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
|
1004 bool |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1005 octave_cell::save_hdf5 (octave_hdf5_id loc_id, const char *name, |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1006 bool save_as_floats) |
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
|
1007 { |
4687 | 1008 #if defined (HAVE_HDF5) |
4815 | 1009 |
4814 | 1010 dim_vector dv = dims (); |
4837 | 1011 int empty = save_hdf5_empty (loc_id, name, dv); |
1012 if (empty) | |
1013 return (empty > 0); | |
1014 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1015 hsize_t rank = dv.ndims (); |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17874
diff
changeset
|
1016 hid_t space_hid, data_hid, size_hid; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17874
diff
changeset
|
1017 space_hid = data_hid = size_hid = -1; |
4687 | 1018 |
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
|
1019 #if defined (HAVE_HDF5_18) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1020 data_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
|
1021 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
|
1022 #else |
4687 | 1023 data_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
|
1024 #endif |
4815 | 1025 |
1026 if (data_hid < 0) | |
1027 return false; | |
4687 | 1028 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1029 // Have to save cell array shape, since can't have a |
4814 | 1030 // dataset of groups.... |
4815 | 1031 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23589
diff
changeset
|
1032 space_hid = H5Screate_simple (1, &rank, nullptr); |
4815 | 1033 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1034 if (space_hid < 0) |
4687 | 1035 { |
1036 H5Gclose (data_hid); | |
1037 return false; | |
1038 } | |
1039 | |
5351 | 1040 OCTAVE_LOCAL_BUFFER (octave_idx_type, hdims, rank); |
4814 | 1041 |
1042 // Octave uses column-major, while HDF5 uses row-major ordering | |
4933 | 1043 for (hsize_t i = 0; i < rank; i++) |
4815 | 1044 hdims[i] = dv(rank-i-1); |
4814 | 1045 |
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
|
1046 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1047 size_hid = H5Dcreate (data_hid, "dims", H5T_NATIVE_IDX, 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
|
1048 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
|
1049 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1050 size_hid = H5Dcreate (data_hid, "dims", H5T_NATIVE_IDX, 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
|
1051 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
|
1052 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1053 if (size_hid < 0) |
4687 | 1054 { |
1055 H5Sclose (space_hid); | |
1056 H5Gclose (data_hid); | |
1057 return false; | |
1058 } | |
1059 | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1060 if (H5Dwrite (size_hid, H5T_NATIVE_IDX, 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
|
1061 octave_H5P_DEFAULT, hdims) < 0) |
4687 | 1062 { |
1063 H5Dclose (size_hid); | |
1064 H5Sclose (space_hid); | |
1065 H5Gclose (data_hid); | |
1066 return false; | |
1067 } | |
4815 | 1068 |
4687 | 1069 H5Dclose (size_hid); |
1070 H5Sclose (space_hid); | |
1071 | |
4815 | 1072 // Recursively add each element of the cell to this group. |
1073 | |
4687 | 1074 Cell tmp = cell_value (); |
5850 | 1075 |
1076 octave_idx_type nel = dv.numel (); | |
1077 | |
1078 for (octave_idx_type i = 0; i < nel; i++) | |
4687 | 1079 { |
5765 | 1080 std::ostringstream buf; |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
1081 int digits = static_cast<int> (std::floor (::log10 (static_cast<double> |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1082 (nel)) + 1.0)); |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
1083 buf << '_' << std::setw (digits) << std::setfill ('0') << i; |
5765 | 1084 std::string s = buf.str (); |
4687 | 1085 |
5850 | 1086 if (! add_hdf5_data (data_hid, tmp.elem (i), s.c_str (), "", false, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1087 save_as_floats)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1088 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1089 H5Gclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1090 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1091 } |
4687 | 1092 } |
1093 | |
1094 H5Gclose (data_hid); | |
4815 | 1095 |
4687 | 1096 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
|
1097 |
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
|
1098 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1099 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1100 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1101 octave_unused_parameter (save_as_floats); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1102 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1103 warn_save ("hdf5"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1104 |
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
|
1105 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
|
1106 #endif |
4687 | 1107 } |
1108 | |
1109 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
|
1110 octave_cell::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4687 | 1111 { |
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
|
1112 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
|
1113 |
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
|
1114 #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
|
1115 |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1116 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1117 |
4837 | 1118 dim_vector dv; |
1119 int empty = load_hdf5_empty (loc_id, name, dv); | |
1120 if (empty > 0) | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1121 matrix.resize (dv); |
4837 | 1122 if (empty) |
1123 return (empty > 0); | |
1124 | |
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
|
1125 #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
|
1126 hid_t group_id = 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
|
1127 #else |
4687 | 1128 hid_t group_id = 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
|
1129 #endif |
4687 | 1130 |
1131 if (group_id < 0) | |
1132 return false; | |
1133 | |
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
|
1134 #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
|
1135 hid_t data_hid = H5Dopen (group_id, "dims", 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
|
1136 #else |
4814 | 1137 hid_t data_hid = H5Dopen (group_id, "dims"); |
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
|
1138 #endif |
4687 | 1139 hid_t space_hid = H5Dget_space (data_hid); |
1140 hsize_t rank = H5Sget_simple_extent_ndims (space_hid); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1141 if (rank != 1) |
4687 | 1142 { |
4837 | 1143 H5Dclose (data_hid); |
1144 H5Gclose (group_id); | |
4687 | 1145 return false; |
1146 } | |
1147 | |
4814 | 1148 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
1149 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
4815 | 1150 |
4814 | 1151 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); |
4687 | 1152 |
4815 | 1153 // Octave uses column-major, while HDF5 uses row-major ordering. |
1154 | |
4814 | 1155 dv.resize (hdims[0]); |
4815 | 1156 |
5351 | 1157 OCTAVE_LOCAL_BUFFER (octave_idx_type, tmp, hdims[0]); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1158 |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1159 if (H5Dread (data_hid, H5T_NATIVE_IDX, 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
|
1160 octave_H5P_DEFAULT, tmp) < 0) |
4687 | 1161 { |
4837 | 1162 H5Dclose (data_hid); |
1163 H5Gclose (group_id); | |
4687 | 1164 return false; |
1165 } | |
4815 | 1166 |
4687 | 1167 H5Dclose (data_hid); |
1168 H5Gclose (group_id); | |
1169 | |
4815 | 1170 for (hsize_t i = 0, j = hdims[0] - 1; i < hdims[0]; i++, j--) |
4814 | 1171 dv(j) = tmp[i]; |
1172 | |
4687 | 1173 hdf5_callback_data dsub; |
1174 | |
1175 herr_t retval2 = -1; | |
4815 | 1176 |
4814 | 1177 Cell m (dv); |
4815 | 1178 |
4687 | 1179 int current_item = 0; |
4815 | 1180 |
4696 | 1181 hsize_t num_obj = 0; |
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
|
1182 #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
|
1183 group_id = 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
|
1184 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1185 group_id = 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
|
1186 #endif |
5060 | 1187 H5Gget_num_objs (group_id, &num_obj); |
1188 H5Gclose (group_id); | |
4696 | 1189 |
5275 | 1190 for (octave_idx_type i = 0; i < dv.numel (); i++) |
4687 | 1191 { |
4696 | 1192 |
4814 | 1193 if (current_item >= static_cast<int> (num_obj)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1194 retval2 = -1; |
4814 | 1195 else |
22028
5c949eecb6dd
use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents:
22022
diff
changeset
|
1196 retval2 = hdf5_h5g_iterate (loc_id, name, ¤t_item,&dsub); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1197 |
4687 | 1198 if (retval2 <= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1199 break; |
4814 | 1200 |
1201 octave_value ov = dsub.tc; | |
1202 m.elem (i) = ov; | |
1203 | |
4687 | 1204 } |
1205 | |
1206 if (retval2 >= 0) | |
1207 { | |
1208 matrix = m; | |
1209 retval = true; | |
1210 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1211 |
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
|
1212 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1213 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1214 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1215 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1216 warn_load ("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
|
1217 #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
|
1218 |
4687 | 1219 return retval; |
1220 } | |
4815 | 1221 |
3354 | 1222 DEFUN (iscell, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1223 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1224 @deftypefn {} {} iscell (@var{x}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1225 Return true if @var{x} is a cell array object. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1226 @seealso{ismatrix, isstruct, iscellstr, isa} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1227 @end deftypefn */) |
3354 | 1228 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1229 if (args.length () != 1) |
5823 | 1230 print_usage (); |
3354 | 1231 |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23575
diff
changeset
|
1232 return ovl (args(0).iscell ()); |
3354 | 1233 } |
1234 | |
1235 DEFUN (cell, args, , | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1236 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1237 @deftypefn {} {} cell (@var{n}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1238 @deftypefnx {} {} cell (@var{m}, @var{n}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1239 @deftypefnx {} {} cell (@var{m}, @var{n}, @var{k}, @dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1240 @deftypefnx {} {} cell ([@var{m} @var{n} @dots{}]) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1241 Create a new cell array object. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1242 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1243 If invoked with a single scalar integer argument, return a square |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1244 @nospell{NxN} cell array. If invoked with two or more scalar integer |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1245 arguments, or a vector of integer values, return an array with the given |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1246 dimensions. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1247 @seealso{cellstr, mat2cell, num2cell, struct2cell} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1248 @end deftypefn */) |
3354 | 1249 { |
1250 int nargin = args.length (); | |
1251 | |
4563 | 1252 dim_vector dims; |
1253 | |
3354 | 1254 switch (nargin) |
1255 { | |
4563 | 1256 case 0: |
1257 dims = dim_vector (0, 0); | |
3354 | 1258 break; |
1259 | |
4563 | 1260 case 1: |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25438
diff
changeset
|
1261 octave::get_dimensions (args(0), "cell", dims); |
3354 | 1262 break; |
1263 | |
1264 default: | |
4563 | 1265 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1266 dims.resize (nargin); |
4563 | 1267 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1268 for (int i = 0; i < nargin; i++) |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
1269 dims(i) = (args(i).isempty () |
23467
0ada77ed24dd
use idx_type for dimensions instead of int (bug #50934)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
1270 ? 0 : args(i).xidx_type_value ("cell: dimension must be a scalar integer")); |
4563 | 1271 } |
3354 | 1272 break; |
1273 } | |
1274 | |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
1275 dims.chop_trailing_singletons (); |
4563 | 1276 |
25646
4d565baa475e
move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
25438
diff
changeset
|
1277 octave::check_dimensions (dims, "cell"); |
4563 | 1278 |
22200
46b67f1569b5
FCell: avoid repeating default value for a newly created Cell.
Carnë Draug <carandraug@octave.org>
parents:
22197
diff
changeset
|
1279 return ovl (Cell (dims)); |
3354 | 1280 } |
1281 | |
23467
0ada77ed24dd
use idx_type for dimensions instead of int (bug #50934)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
1282 /* |
0ada77ed24dd
use idx_type for dimensions instead of int (bug #50934)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
1283 ## This might work on some system someday, but for now, who has a system |
0ada77ed24dd
use idx_type for dimensions instead of int (bug #50934)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
1284 ## where a 16 yottabyte array can be allocated? See bug #50934. |
0ada77ed24dd
use idx_type for dimensions instead of int (bug #50934)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
1285 %!error <out of memory> cell (1e24, 1); |
0ada77ed24dd
use idx_type for dimensions instead of int (bug #50934)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
1286 */ |
0ada77ed24dd
use idx_type for dimensions instead of int (bug #50934)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
1287 |
4610 | 1288 DEFUN (iscellstr, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1289 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1290 @deftypefn {} {} iscellstr (@var{cell}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1291 Return true if every element of the cell array @var{cell} is a character |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1292 string. |
24474
0b65949870e3
isstring.m: Add new function for identifying string arrays.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1293 @seealso{ischar, isstring} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1294 @end deftypefn */) |
4610 | 1295 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1296 if (args.length () != 1) |
5823 | 1297 print_usage (); |
4610 | 1298 |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
1299 return ovl (args(0).iscellstr ()); |
4610 | 1300 } |
1301 | |
4817 | 1302 DEFUN (cellstr, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1303 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1304 @deftypefn {} {@var{cstr} =} cellstr (@var{strmat}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1305 Create a new cell array object from the elements of the string array |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1306 @var{strmat}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1307 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1308 Each row of @var{strmat} becomes an element of @var{cstr}. Any trailing |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1309 spaces in a row are deleted before conversion. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1310 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1311 To convert back from a cellstr to a character array use @code{char}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1312 @seealso{cell, char} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1313 @end deftypefn */) |
4817 | 1314 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1315 if (args.length () != 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1316 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1317 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1318 octave_value_list tmp = Fiscellstr (args, 1); |
4817 | 1319 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1320 if (tmp(0).is_true ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1321 return ovl (args(0)); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1322 else |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1323 { |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
1324 string_vector s = args(0).xstring_vector_value ("cellstr: argument STRING must be a 2-D character array"); |
4817 | 1325 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
1326 return ovl (s.isempty () ? Cell (octave_value ("")) |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
1327 : Cell (s, true)); |
4817 | 1328 } |
1329 } | |
1330 | |
4762 | 1331 DEFUN (struct2cell, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1332 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1333 @deftypefn {} {@var{c} =} struct2cell (@var{s}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1334 Create a new cell array from the objects stored in the struct object. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1335 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1336 If @var{f} is the number of fields in the structure, the resulting cell |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1337 array will have a dimension vector corresponding to |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1338 @code{[@var{f} size(@var{s})]}. For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1339 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1340 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1341 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1342 s = struct ("name", @{"Peter", "Hannah", "Robert"@}, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1343 "age", @{23, 16, 3@}); |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1344 c = struct2cell (s) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1345 @result{} c = @{2x1x3 Cell Array@} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1346 c(1,1,:)(:) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1347 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1348 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1349 [1,1] = Peter |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1350 [2,1] = Hannah |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1351 [3,1] = Robert |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1352 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1353 c(2,1,:)(:) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1354 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1355 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1356 [1,1] = 23 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1357 [2,1] = 16 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1358 [3,1] = 3 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1359 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1360 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1361 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1362 |
27426
3ec072ab1bda
namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
1363 @seealso{cell2struct, namedargs2cell, fieldnames} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1364 @end deftypefn */) |
4762 | 1365 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20797
diff
changeset
|
1366 if (args.length () != 1) |
5823 | 1367 print_usage (); |
4764 | 1368 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1369 const octave_map m = args(0).xmap_value ("struct2cell: argument S must be a structure"); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1370 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1371 const dim_vector m_dv = m.dims (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1372 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1373 octave_idx_type num_fields = m.nfields (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1374 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1375 // The resulting dim_vector should have dimensions: |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1376 // [numel(fields) size(struct)] |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1377 // except if the struct is a column vector. |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1378 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1379 dim_vector result_dv; |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1380 if (m_dv(m_dv.ndims () - 1) == 1) |
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1381 result_dv.resize (m_dv.ndims ()); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1382 else |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1383 result_dv.resize (m_dv.ndims () + 1); // Add 1 for the fields. |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1384 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1385 result_dv(0) = num_fields; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1386 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1387 for (int i = 1; i < result_dv.ndims (); i++) |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1388 result_dv(i) = m_dv(i-1); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1389 |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27426
diff
changeset
|
1390 Cell c (result_dv); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1391 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1392 octave_idx_type n_elts = m.numel (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1393 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1394 // Fill c in one sweep. Note that thanks to octave_map structure, |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1395 // we don't need a key lookup at all. |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1396 for (octave_idx_type j = 0; j < n_elts; j++) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1397 for (octave_idx_type i = 0; i < num_fields; i++) |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27426
diff
changeset
|
1398 c.xelem (i,j) = m.contents(i)(j); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1399 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1400 return ovl (c); |
4762 | 1401 } |
1402 | |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1403 /* |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1404 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1405 %! keys = cellstr (char (floor (rand (11,10)*24+65)))'; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1406 %! vals = cellfun (@(x) mat2cell (rand (19,1), ones (19,1), 1), ... |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1407 %! mat2cell ([1:11]', ones (11,1), 1), "uniformoutput", false)'; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1408 %! s = struct ([keys; vals]{:}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1409 %! t = cell2struct ([vals{:}], keys, 2); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1410 %! assert (s, t); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1411 %! assert (struct2cell (s), [vals{:}]'); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1412 %! assert (fieldnames (s), keys'); |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1413 */ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1414 |
5900 | 1415 mxArray * |
1416 octave_cell::as_mxArray (void) const | |
1417 { | |
1418 mxArray *retval = new mxArray (dims ()); | |
1419 | |
1420 mxArray **elts = static_cast<mxArray **> (retval->get_data ()); | |
1421 | |
6686 | 1422 mwSize nel = numel (); |
5900 | 1423 |
1424 const octave_value *p = matrix.data (); | |
1425 | |
6686 | 1426 for (mwIndex i = 0; i < nel; i++) |
5900 | 1427 elts[i] = new mxArray (p[i]); |
1428 | |
1429 return retval; | |
1430 } | |
1431 | |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1432 octave_value |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1433 octave_cell::map (unary_mapper_t umap) const |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1434 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1435 switch (umap) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1436 { |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1437 #define FORWARD_MAPPER(UMAP) \ |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1438 case umap_ ## UMAP: \ |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1439 return matrix.UMAP () |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22028
diff
changeset
|
1440 |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1441 FORWARD_MAPPER (xisalnum); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1442 FORWARD_MAPPER (xisalpha); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1443 FORWARD_MAPPER (xisascii); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1444 FORWARD_MAPPER (xiscntrl); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1445 FORWARD_MAPPER (xisdigit); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1446 FORWARD_MAPPER (xisgraph); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1447 FORWARD_MAPPER (xislower); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1448 FORWARD_MAPPER (xisprint); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1449 FORWARD_MAPPER (xispunct); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1450 FORWARD_MAPPER (xisspace); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1451 FORWARD_MAPPER (xisupper); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1452 FORWARD_MAPPER (xisxdigit); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1453 FORWARD_MAPPER (xtolower); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1454 FORWARD_MAPPER (xtoupper); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1455 |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1456 default: |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1457 return octave_base_value::map (umap); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1458 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1459 } |