Mercurial > octave
annotate libinterp/octave-value/ov-cell.cc @ 33632:fed0dc6fd44c default tip
remove unused variable from libgui/module.mk
* libgui/module.mk: remove empty variable OCTAVE_GUI_EDITOR_MOC
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Mon, 27 May 2024 19:42:05 +0200 |
parents | 976638dd9021 |
children |
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 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
32589
diff
changeset
|
3 // Copyright (C) 1999-2024 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" |
29476
c74ff452e2bb
avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
51 #include "ov-fcn-handle.h" |
3928 | 52 #include "ov-re-mat.h" |
53 #include "ov-scalar.h" | |
5360 | 54 #include "pr-output.h" |
55 #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
|
56 #include "errwarn.h" |
3928 | 57 |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
58 #include "ls-oct-text.h" |
4687 | 59 #include "ls-oct-binary.h" |
60 #include "ls-hdf5.h" | |
61 #include "ls-utils.h" | |
62 | |
3353 | 63 |
4612 | 64 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cell, "cell", "cell"); |
3353 | 65 |
32589
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32445
diff
changeset
|
66 void |
05b4479c29d8
maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents:
32445
diff
changeset
|
67 octave_cell::break_closure_cycles (const std::shared_ptr<octave::stack_frame>& frame) |
29476
c74ff452e2bb
avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
68 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
69 for (octave_idx_type i = 0; i < m_matrix.numel (); i++) |
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
70 m_matrix(i).break_closure_cycles (frame); |
29476
c74ff452e2bb
avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
71 } |
c74ff452e2bb
avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
72 |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
73 octave_value_list |
32445
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
74 octave_cell::simple_subsref (char type, octave_value_list& idx, int) |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
75 { |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
76 octave_value_list retval; |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
77 |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
78 switch (type) |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
79 { |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
80 case '(': |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
81 retval(0) = do_index_op (idx); |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
82 break; |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
83 |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
84 case '{': |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
85 { |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
86 if (idx.empty ()) |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
87 error ("invalid empty index expression {}, use {:} instead"); |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
88 |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
89 octave_value tmp = do_index_op (idx); |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
90 |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
91 Cell tcell = tmp.cell_value (); |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
92 |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
93 if (tcell.numel () == 1) |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
94 retval(0) = tcell(0, 0); |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
95 else |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
96 { |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
97 // Return a comma-separated list. |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
98 retval = octave_value (octave_value_list (tcell)); |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
99 } |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
100 } |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
101 break; |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
102 |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
103 case '.': |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
104 { |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
105 std::string nm = type_name (); |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
106 error ("%s cannot be indexed with %c", nm.c_str (), type); |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
107 } |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
108 break; |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
109 |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
110 default: |
33362
2949b89f9711
replace most uses of panic_impossible with error in octave_value classes
John W. Eaton <jwe@octave.org>
parents:
33339
diff
changeset
|
111 error ("unexpected: index not '(', '{', or '.' in octave_cell::simple_subsref - please report this bug"); |
32445
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
112 } |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
113 |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
114 return retval; |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
115 } |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
116 |
4d6615bca5b4
Split chained subsrefs to multiple instructions
Petter T.
parents:
32060
diff
changeset
|
117 octave_value_list |
4247 | 118 octave_cell::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
119 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
|
120 int nargout) |
3933 | 121 { |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
122 octave_value_list retval; |
3933 | 123 |
124 switch (type[0]) | |
125 { | |
126 case '(': | |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7622
diff
changeset
|
127 retval(0) = do_index_op (idx.front ()); |
3933 | 128 break; |
129 | |
130 case '{': | |
131 { | |
27060
3140380861ce
error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
132 if (idx.front ().empty ()) |
29605
7460baab17ad
Emit more informative error message for empty {} indexing (bug #57297).
Rik <rik@octave.org>
parents:
29572
diff
changeset
|
133 error ("invalid empty index expression {}, use {:} instead"); |
27060
3140380861ce
error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents:
26399
diff
changeset
|
134 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
135 octave_value tmp = do_index_op (idx.front ()); |
3933 | 136 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
137 Cell tcell = tmp.cell_value (); |
4582 | 138 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
139 if (tcell.numel () == 1) |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
140 retval(0) = tcell(0, 0); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
141 else |
23352
778fdffc09df
deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents:
23350
diff
changeset
|
142 { |
778fdffc09df
deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents:
23350
diff
changeset
|
143 // Return a comma-separated list. |
778fdffc09df
deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents:
23350
diff
changeset
|
144 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
|
145 } |
3933 | 146 } |
147 break; | |
148 | |
149 case '.': | |
150 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
151 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
152 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
3933 | 153 } |
154 break; | |
155 | |
156 default: | |
33362
2949b89f9711
replace most uses of panic_impossible with error in octave_value classes
John W. Eaton <jwe@octave.org>
parents:
33339
diff
changeset
|
157 error ("unexpected: index not '(', '{', or '.' in octave_cell::subsref - please report this bug"); |
3933 | 158 } |
159 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
160 // FIXME: perhaps there should be an |
4994 | 161 // octave_value_list::next_subsref member function? See also |
162 // octave_user_function::subsref. | |
163 | |
164 if (idx.size () > 1) | |
23481
73558a835b64
eliminate lvalue list arguments from evaluator functions
John W. Eaton <jwe@octave.org>
parents:
23468
diff
changeset
|
165 retval = retval(0).next_subsref (nargout, type, idx); |
4994 | 166 |
167 return retval; | |
3933 | 168 } |
169 | |
170 octave_value | |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
171 octave_cell::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
172 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
173 bool auto_add) |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
174 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
175 octave_value retval; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
176 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
177 switch (type[0]) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
178 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
179 case '(': |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
180 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
|
181 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
182 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
183 case '{': |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
184 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
185 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
|
186 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
187 const Cell tcell = tmp.cell_value (); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
188 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
189 if (tcell.numel () == 1) |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
190 retval = tcell(0, 0); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
191 else |
23352
778fdffc09df
deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents:
23350
diff
changeset
|
192 { |
778fdffc09df
deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents:
23350
diff
changeset
|
193 // Return a comma-separated list. |
778fdffc09df
deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents:
23350
diff
changeset
|
194 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
|
195 } |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
196 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
197 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
198 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
199 case '.': |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
200 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
201 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
202 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
|
203 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
204 break; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
205 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
206 default: |
33362
2949b89f9711
replace most uses of panic_impossible with error in octave_value classes
John W. Eaton <jwe@octave.org>
parents:
33339
diff
changeset
|
207 error ("unexpected: index not '(', '{', or '.' in octave_cell::subsref - please report this bug"); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
208 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
209 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
210 // FIXME: perhaps there should be an |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
211 // 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
|
212 // octave_user_function::subsref. |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
213 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
214 if (idx.size () > 1) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
215 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
|
216 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
217 return retval; |
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 |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8546
diff
changeset
|
220 octave_value |
4247 | 221 octave_cell::subsasgn (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
222 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
223 const octave_value& rhs) |
3933 | 224 { |
225 octave_value retval; | |
226 | |
227 int n = type.length (); | |
228 | |
229 octave_value t_rhs = rhs; | |
230 | |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
231 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
232 |
9286
c2248cc4821a
don't crash on assignments like a() = 1
Jaroslav Hajek <highegg@gmail.com>
parents:
9109
diff
changeset
|
233 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
|
234 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
|
235 |
3933 | 236 if (n > 1) |
237 { | |
238 switch (type[0]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
239 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
240 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
241 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
242 if (isempty () && type[1] == '.') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
243 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
244 // 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
|
245 // type in cases like |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
246 // |
10871
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
247 // x = {}; x(i).f = rhs |
3933 | 248 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
249 octave_value tmp = octave_value::empty_conv (type, rhs); |
3933 | 250 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
251 return tmp.subsasgn (type, idx, rhs); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
252 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
253 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
254 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
255 octave_value tmp = do_index_op (idx.front (), true); |
3933 | 256 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
257 if (! tmp.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
258 tmp = octave_value::empty_conv (type.substr (1), rhs); |
3933 | 259 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
260 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
|
261 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
262 next_idx.erase (next_idx.begin ()); |
4362 | 263 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
264 tmp.make_unique (); |
6767 | 265 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
266 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
|
267 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
268 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
269 break; |
3933 | 270 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
271 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
272 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
273 m_matrix.make_unique (); |
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
274 Cell tmpc = m_matrix.index (idx.front (), true); |
3933 | 275 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
276 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
|
277 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
278 next_idx.erase (next_idx.begin ()); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
279 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
280 std::string next_type = type.substr (1); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
281 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
282 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
|
283 err_indexed_cs_list (); |
8546
3d8a914c580e
improve parser indexed assigment code
Jaroslav Hajek <highegg@gmail.com>
parents:
8523
diff
changeset
|
284 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
285 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
|
286 tmpc = Cell (); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
287 |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
288 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
|
289 { |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
290 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
|
291 tmp.make_unique (); // probably a no-op. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
292 } |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
293 else |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
294 // 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
|
295 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
|
296 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
297 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
|
298 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
299 break; |
3933 | 300 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
301 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
302 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
303 if (! isempty ()) |
10871
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
304 { |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
305 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
|
306 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
|
307 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
308 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
309 // 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
|
310 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
311 break; |
3933 | 312 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
313 default: |
33362
2949b89f9711
replace most uses of panic_impossible with error in octave_value classes
John W. Eaton <jwe@octave.org>
parents:
33339
diff
changeset
|
314 error ("unexpected: index not '(', '{', or '.' in octave_cell::subsasgn - please report this bug"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
315 } |
3933 | 316 } |
317 | |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
318 switch (type[0]) |
3933 | 319 { |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
320 case '(': |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
321 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
322 octave_value_list i = idx.front (); |
3933 | 323 |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23575
diff
changeset
|
324 if (t_rhs.iscell ()) |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
325 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
|
326 else if (t_rhs.isnull ()) |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
327 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
|
328 else |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
329 octave_base_matrix<Cell>::assign (i, Cell (t_rhs)); |
3933 | 330 |
31814
53c10d69a9be
maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents:
31813
diff
changeset
|
331 m_count++; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
332 retval = octave_value (this); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
333 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
334 break; |
3933 | 335 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
336 case '{': |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
337 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
338 octave_value_list idxf = idx.front (); |
5846 | 339 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
340 if (t_rhs.is_cs_list ()) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
341 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
342 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
|
343 |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
344 // 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
|
345 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
346 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
|
347 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
|
348 if (! idxf(k).is_magic_colon ()) didx(k) = idxf(k).numel (); |
7040 | 349 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
350 if (didx.numel () == tmp_cell.numel ()) |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
351 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
|
352 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
353 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
|
354 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
355 else if (idxf.all_scalars () |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
356 || 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
|
357 // 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
|
358 octave_base_matrix<Cell>::assign (idxf, |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
359 Cell (t_rhs.storable_value ())); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
360 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
361 err_nonbraced_cs_list_assignment (); |
3933 | 362 |
31814
53c10d69a9be
maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents:
31813
diff
changeset
|
363 m_count++; |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
364 retval = octave_value (this); |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
365 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
366 break; |
10871
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10840
diff
changeset
|
367 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
368 case '.': |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
369 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
370 if (! isempty ()) |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
371 { |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
372 std::string nm = type_name (); |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
373 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
|
374 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
375 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
376 // 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
|
377 // type in cases like |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
378 // |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
379 // x = {}; x.f = rhs |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
380 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
381 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
|
382 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
383 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
|
384 } |
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
385 break; |
3933 | 386 |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
387 default: |
33362
2949b89f9711
replace most uses of panic_impossible with error in octave_value classes
John W. Eaton <jwe@octave.org>
parents:
33339
diff
changeset
|
388 error ("unexpected: index not '(', '{', or '.' in octave_cell::subsasgn - please report this bug"); |
3933 | 389 } |
390 | |
391 return retval; | |
392 } | |
393 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
394 bool |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31718
diff
changeset
|
395 octave_cell::iscellstr () const |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
396 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
397 bool retval; |
30132
72afd5cd4a0c
maint: use "m_" prefix for member variables in class octave_cell.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
398 if (m_cellstr_cache.get ()) |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
399 retval = true; |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
400 else |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
401 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
402 retval = m_matrix.iscellstr (); |
10065
64a06079cae4
improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10030
diff
changeset
|
403 // 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
|
404 if (retval) |
30132
72afd5cd4a0c
maint: use "m_" prefix for member variables in class octave_cell.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
405 m_cellstr_cache.reset (new Array<std::string> ()); |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
406 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
407 |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
408 return retval; |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
409 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
410 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
411 void |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
412 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
|
413 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
414 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
415 octave_base_matrix<Cell>::assign (idx, rhs); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
416 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
417 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
418 void |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
419 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
|
420 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
421 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
422 octave_base_matrix<Cell>::assign (idx, rhs); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
423 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
424 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
425 void |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
426 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
|
427 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
428 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
429 octave_base_matrix<Cell>::delete_elements (idx); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
430 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
431 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29476
diff
changeset
|
432 std::size_t |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31718
diff
changeset
|
433 octave_cell::byte_size () const |
4791 | 434 { |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29476
diff
changeset
|
435 std::size_t retval = 0; |
4791 | 436 |
5275 | 437 for (octave_idx_type i = 0; i < numel (); i++) |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
438 retval += m_matrix(i).byte_size (); |
4791 | 439 |
440 return retval; | |
441 } | |
442 | |
8732 | 443 octave_value |
444 octave_cell::sort (octave_idx_type dim, sortmode mode) const | |
445 { | |
446 octave_value retval; | |
447 | |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
448 if (! iscellstr ()) |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
449 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
|
450 |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
451 Array<std::string> tmp = cellstr_value (); |
8824
76ddf0ab985d
auto-set cellstr cache when sorting cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8823
diff
changeset
|
452 |
20681
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
453 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
|
454 |
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
455 // 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
|
456 retval = new octave_cell (tmp); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
457 |
8732 | 458 return retval; |
459 } | |
460 | |
461 octave_value | |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
462 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
|
463 sortmode mode) const |
8732 | 464 { |
465 octave_value retval; | |
466 | |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
467 if (! iscellstr ()) |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
468 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
|
469 |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
470 Array<std::string> tmp = cellstr_value (); |
8824
76ddf0ab985d
auto-set cellstr cache when sorting cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8823
diff
changeset
|
471 |
20681
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
472 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
|
473 |
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
474 // 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
|
475 retval = new octave_cell (tmp); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
476 |
8732 | 477 return retval; |
478 } | |
479 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
480 sortmode |
23588
0549061d35b9
maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
481 octave_cell::issorted (sortmode mode) const |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
482 { |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
483 sortmode retval = UNSORTED; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
484 |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
485 if (! iscellstr ()) |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
486 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
|
487 |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
488 Array<std::string> tmp = cellstr_value (); |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
489 |
23588
0549061d35b9
maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
490 retval = tmp.issorted (mode); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
491 |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
492 return retval; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
493 } |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
494 |
8732 | 495 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
|
496 octave_cell::sort_rows_idx (sortmode mode) const |
8732 | 497 { |
498 Array<octave_idx_type> retval; | |
499 | |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
500 if (! iscellstr ()) |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
501 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
|
502 |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
503 Array<std::string> tmp = cellstr_value (); |
8732 | 504 |
20681
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
505 retval = tmp.sort_rows_idx (mode); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
506 |
8732 | 507 return retval; |
508 } | |
509 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
510 sortmode |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
511 octave_cell::is_sorted_rows (sortmode mode) const |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
512 { |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
513 sortmode retval = UNSORTED; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
514 |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
515 if (! iscellstr ()) |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
516 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
|
517 |
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20681
diff
changeset
|
518 Array<std::string> tmp = cellstr_value (); |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
519 |
20681
b0b37f0d7e6d
new cellstr_value function and elimination of error_state
John W. Eaton <jwe@octave.org>
parents:
20558
diff
changeset
|
520 retval = tmp.is_sorted_rows (mode); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
521 |
8823
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
522 return retval; |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
523 } |
3efa512a0957
make issorted work for cells
Jaroslav Hajek <highegg@gmail.com>
parents:
8815
diff
changeset
|
524 |
8626
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
525 bool |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31718
diff
changeset
|
526 octave_cell::is_true () const |
8626
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
527 { |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
528 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
|
529 } |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
8587
diff
changeset
|
530 |
3933 | 531 octave_value_list |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31718
diff
changeset
|
532 octave_cell::list_value () const |
3933 | 533 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
534 return octave_value_list (m_matrix); |
3933 | 535 } |
536 | |
4243 | 537 string_vector |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
538 octave_cell::string_vector_value (bool pad) const |
4243 | 539 { |
4358 | 540 string_vector retval; |
541 | |
7285 | 542 octave_idx_type nel = numel (); |
4243 | 543 |
4358 | 544 int n_elts = 0; |
545 | |
5275 | 546 octave_idx_type max_len = 0; |
4358 | 547 |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
548 std::queue<string_vector> strvec_queue; |
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
549 |
7285 | 550 for (octave_idx_type i = 0; i < nel; i++) |
4358 | 551 { |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
552 string_vector s = m_matrix(i).string_vector_value (); |
7285 | 553 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
554 octave_idx_type s_len = s.numel (); |
4358 | 555 |
7285 | 556 n_elts += s_len ? s_len : 1; |
4358 | 557 |
7285 | 558 octave_idx_type s_max_len = s.max_length (); |
4358 | 559 |
7285 | 560 if (s_max_len > max_len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
561 max_len = s_max_len; |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
562 |
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
563 strvec_queue.push (s); |
4358 | 564 } |
565 | |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
566 retval = string_vector (n_elts); |
4243 | 567 |
5275 | 568 octave_idx_type k = 0; |
4243 | 569 |
7285 | 570 for (octave_idx_type i = 0; i < nel; i++) |
4243 | 571 { |
9370
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
572 const string_vector s = strvec_queue.front (); |
4ff6f8efdda2
fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
9338
diff
changeset
|
573 strvec_queue.pop (); |
7285 | 574 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
575 octave_idx_type s_len = s.numel (); |
4358 | 576 |
7285 | 577 if (s_len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
578 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
579 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
|
580 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
581 std::string t = s[j]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
582 int t_len = t.length (); |
5715 | 583 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
584 if (pad && max_len > t_len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
585 t += std::string (max_len - t_len, ' '); |
5715 | 586 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
587 retval[k++] = t; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
588 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
589 } |
7285 | 590 else if (pad) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
591 retval[k++] = std::string (max_len, ' '); |
7285 | 592 else |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
593 retval[k++] = ""; |
4243 | 594 } |
595 | |
596 return retval; | |
597 } | |
598 | |
8732 | 599 Array<std::string> |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31718
diff
changeset
|
600 octave_cell::cellstr_value () const |
8732 | 601 { |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
602 if (! iscellstr ()) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
603 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
|
604 |
30132
72afd5cd4a0c
maint: use "m_" prefix for member variables in class octave_cell.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
605 if (m_cellstr_cache->isempty ()) |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
606 *m_cellstr_cache = m_matrix.cellstr_value (); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
607 |
30132
72afd5cd4a0c
maint: use "m_" prefix for member variables in class octave_cell.
Rik <rik@octave.org>
parents:
29961
diff
changeset
|
608 return *m_cellstr_cache; |
8732 | 609 } |
610 | |
4604 | 611 bool |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31718
diff
changeset
|
612 octave_cell::print_as_scalar () const |
4604 | 613 { |
11474 | 614 return true; |
4604 | 615 } |
616 | |
3933 | 617 void |
18416
bcd71a2531d3
Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents:
18409
diff
changeset
|
618 octave_cell::print (std::ostream& os, bool) |
3933 | 619 { |
620 print_raw (os); | |
621 } | |
622 | |
623 void | |
624 octave_cell::print_raw (std::ostream& os, bool) const | |
625 { | |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
626 int nd = m_matrix.ndims (); |
4513 | 627 |
4587 | 628 if (nd == 2) |
4513 | 629 { |
5275 | 630 octave_idx_type nr = rows (); |
631 octave_idx_type nc = columns (); | |
4513 | 632 |
633 if (nr > 0 && nc > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
634 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
635 indent (os); |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
636 os << '{'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
637 newline (os); |
4513 | 638 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
639 increment_indent_level (); |
4513 | 640 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
641 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
|
642 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
643 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
|
644 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
645 octave_quit (); |
4513 | 646 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
647 std::ostringstream buf; |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
648 buf << '[' << i+1 << ',' << j+1 << ']'; |
3933 | 649 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
650 octave_value val = m_matrix(i, j); |
4513 | 651 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
652 val.print_with_name (os, buf.str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
653 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
654 } |
4513 | 655 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
656 decrement_indent_level (); |
4513 | 657 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
658 indent (os); |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
659 os << '}'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
660 newline (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
661 } |
4513 | 662 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
663 { |
9781
ea88eece12f5
fix printing of empty cells
Jaroslav Hajek <highegg@gmail.com>
parents:
9370
diff
changeset
|
664 indent (os); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
665 os << "{}"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
666 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
|
667 os << '(' << nr << 'x' << nc << ')'; |
9781
ea88eece12f5
fix printing of empty cells
Jaroslav Hajek <highegg@gmail.com>
parents:
9370
diff
changeset
|
668 newline (os); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
669 } |
4513 | 670 } |
671 else | |
3933 | 672 { |
673 indent (os); | |
32598
2f3b54f81947
avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents:
32589
diff
changeset
|
674 const dim_vector& dv = m_matrix.dims (); |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
675 os << '{' << dv.str () << " Cell Array}"; |
3933 | 676 newline (os); |
677 } | |
678 } | |
679 | |
23350
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
680 bool |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
681 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
|
682 { |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
683 bool retval = false; |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
684 |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
685 indent (os); |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
686 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
687 if (isempty () || ndims () > 2) |
23350
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
688 os << name << " = "; |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
689 else |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
690 { |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
691 os << name << " ="; |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
692 newline (os); |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
693 retval = true; |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
694 } |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
695 |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
696 return retval; |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
697 } |
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
698 |
17870 | 699 void |
700 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
|
701 { |
33590
976638dd9021
Show ellipsis at end of long arrays for short_disp (bug #65637).
John W. Eaton <jwe@octave.org>
parents:
33446
diff
changeset
|
702 // octave_base_matrix<octave_value>::short_disp is not appropriate for |
976638dd9021
Show ellipsis at end of long arrays for short_disp (bug #65637).
John W. Eaton <jwe@octave.org>
parents:
33446
diff
changeset
|
703 // cell arrays. |
976638dd9021
Show ellipsis at end of long arrays for short_disp (bug #65637).
John W. Eaton <jwe@octave.org>
parents:
33446
diff
changeset
|
704 |
976638dd9021
Show ellipsis at end of long arrays for short_disp (bug #65637).
John W. Eaton <jwe@octave.org>
parents:
33446
diff
changeset
|
705 octave_base_value::short_disp (os); |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
706 } |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
707 |
4687 | 708 #define CELL_ELT_TAG "<cell-element>" |
709 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
710 bool |
6974 | 711 octave_cell::save_ascii (std::ostream& os) |
4687 | 712 { |
32598
2f3b54f81947
avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents:
32589
diff
changeset
|
713 const dim_vector& dv = dims (); |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
714 if (dv.ndims () > 2) |
4687 | 715 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
716 os << "# ndims: " << dv.ndims () << "\n"; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
717 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
718 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
|
719 os << ' ' << dv(i); |
4687 | 720 os << "\n"; |
721 | |
722 Cell tmp = cell_value (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
723 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
724 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
|
725 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
726 octave_value o_val = tmp.elem (i); |
4687 | 727 |
23350
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
728 // 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
|
729 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
|
730 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
731 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
|
732 return ! os.fail (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
733 } |
4687 | 734 } |
735 else | |
736 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
737 // 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
|
738 // compatibility. Makes load_ascii much more complex!! |
4687 | 739 os << "# rows: " << rows () << "\n" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
740 << "# columns: " << columns () << "\n"; |
4687 | 741 |
742 Cell tmp = cell_value (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
743 |
5275 | 744 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
|
745 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
746 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
|
747 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
748 octave_value o_val = tmp.elem (i, j); |
4687 | 749 |
23350
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
750 // 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
|
751 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
|
752 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
753 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
|
754 return ! os.fail (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
755 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
756 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
757 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
758 } |
4687 | 759 } |
760 | |
761 return true; | |
762 } | |
763 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
764 bool |
4687 | 765 octave_cell::load_ascii (std::istream& is) |
766 { | |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
767 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
768 |
5099 | 769 string_vector keywords(2); |
4687 | 770 |
5099 | 771 keywords[0] = "ndims"; |
772 keywords[1] = "rows"; | |
773 | |
774 std::string kw; | |
5275 | 775 octave_idx_type val = 0; |
5099 | 776 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
777 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
|
778 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
|
779 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
780 if (kw == "ndims") |
4687 | 781 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
782 int mdims = static_cast<int> (val); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
783 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
784 if (mdims < 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
785 error ("load: failed to extract number of rows and columns"); |
4687 | 786 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
787 dim_vector dv; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
788 dv.resize (mdims); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
789 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
790 for (int i = 0; i < mdims; i++) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
791 is >> dv(i); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
792 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
793 Cell tmp(dv); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
794 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
795 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
|
796 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
797 octave_value t2; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
798 bool dummy; |
5099 | 799 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
800 // recurse to read cell elements |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
801 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
|
802 dummy, t2, i); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
803 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
804 if (nm != CELL_ELT_TAG) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
805 error ("load: cell array element had unexpected name"); |
4687 | 806 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
807 if (is) |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
808 tmp.elem (i) = t2; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
809 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
810 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
811 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
812 error ("load: failed to load matrix constant"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
813 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
814 m_matrix = tmp; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
815 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
816 else if (kw == "rows") |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
817 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
818 octave_idx_type nr = val; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
819 octave_idx_type nc = 0; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
820 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
821 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
|
822 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
|
823 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
824 if (nr > 0 && nc > 0) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
825 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
826 Cell tmp (nr, nc); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
827 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
828 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
|
829 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
830 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
|
831 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
832 octave_value t2; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
833 bool dummy; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
834 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
835 // recurse to read cell elements |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
836 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
|
837 dummy, t2, i); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
838 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
839 if (nm != CELL_ELT_TAG) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
840 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
|
841 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
842 if (is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
843 tmp.elem (i, j) = t2; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
844 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
845 } |
4687 | 846 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
847 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
848 error ("load: failed to load cell element"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
849 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
850 m_matrix = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
851 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
852 else if (nr == 0 || nc == 0) |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
853 m_matrix = Cell (nr, nc); |
4687 | 854 else |
33362
2949b89f9711
replace most uses of panic_impossible with error in octave_value classes
John W. Eaton <jwe@octave.org>
parents:
33339
diff
changeset
|
855 error ("unexpected dimensions in octave_cell::load_ascii - please report this bug"); |
4687 | 856 } |
857 else | |
33362
2949b89f9711
replace most uses of panic_impossible with error in octave_value classes
John W. Eaton <jwe@octave.org>
parents:
33339
diff
changeset
|
858 error ("unexpected dimensions keyword (= '%s') octave_cell::load_ascii - please report this bug", kw.c_str ()); |
4687 | 859 |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
860 return true; |
4687 | 861 } |
862 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
863 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
|
864 octave_cell::save_binary (std::ostream& os, bool save_as_floats) |
4687 | 865 { |
32598
2f3b54f81947
avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents:
32589
diff
changeset
|
866 const dim_vector& dv = dims (); |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
867 if (dv.ndims () < 1) |
4687 | 868 return false; |
869 | |
870 // 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
|
871 int32_t di = - dv.ndims (); |
5760 | 872 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
|
873 for (int i = 0; i < dv.ndims (); i++) |
4687 | 874 { |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
875 di = dv(i); |
5760 | 876 os.write (reinterpret_cast<char *> (&di), 4); |
4687 | 877 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
878 |
4687 | 879 Cell tmp = cell_value (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
880 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
881 for (octave_idx_type i = 0; i < dv.numel (); i++) |
4687 | 882 { |
883 octave_value o_val = tmp.elem (i); | |
884 | |
23350
0f18524973eb
Fix initial newline for disp() of cells (bug #50683).
Rik <rik@octave.org>
parents:
23344
diff
changeset
|
885 // Recurse to save sub-value. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
886 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
|
887 save_as_floats); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
888 |
4687 | 889 if (! b) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
890 return false; |
4687 | 891 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
892 |
4687 | 893 return true; |
894 } | |
895 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
896 bool |
4687 | 897 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
|
898 octave::mach_info::float_format fmt) |
4687 | 899 { |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
900 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
901 |
5828 | 902 int32_t mdims; |
5760 | 903 if (! is.read (reinterpret_cast<char *> (&mdims), 4)) |
4687 | 904 return false; |
905 if (swap) | |
4944 | 906 swap_bytes<4> (&mdims); |
4687 | 907 if (mdims >= 0) |
908 return false; | |
909 | |
910 mdims = -mdims; | |
5828 | 911 int32_t di; |
4687 | 912 dim_vector dv; |
913 dv.resize (mdims); | |
914 | |
915 for (int i = 0; i < mdims; i++) | |
916 { | |
5760 | 917 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
|
918 return false; |
4687 | 919 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
920 swap_bytes<4> (&di); |
4687 | 921 dv(i) = di; |
922 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
923 |
5157 | 924 // Convert an array with a single dimension to be a row vector. |
925 // Octave should never write files like this, other software | |
926 // might. | |
927 | |
928 if (mdims == 1) | |
929 { | |
930 mdims = 2; | |
931 dv.resize (mdims); | |
932 dv(1) = dv(0); | |
933 dv(0) = 1; | |
934 } | |
935 | |
5275 | 936 octave_idx_type nel = dv.numel (); |
4687 | 937 Cell tmp(dv); |
938 | |
5275 | 939 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 940 { |
941 octave_value t2; | |
942 bool dummy; | |
943 std::string doc; | |
944 | |
945 // recurse to read cell elements | |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
946 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
|
947 dummy, t2, doc); |
4687 | 948 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
949 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
|
950 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
|
951 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
952 if (is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
953 tmp.elem (i) = t2; |
4687 | 954 } |
955 | |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
956 if (! is) |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
957 error ("load: failed to load matrix constant"); |
4687 | 958 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
959 m_matrix = tmp; |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
960 |
20879
5357423bca0a
Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents:
20853
diff
changeset
|
961 return true; |
4687 | 962 } |
963 | |
30232
a2936935c7c8
attempt to limit possible const_cast damage
John W. Eaton <jwe@octave.org>
parents:
30139
diff
changeset
|
964 const void * |
31771
21f9b34eb893
maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents:
31718
diff
changeset
|
965 octave_cell::mex_get_data () const |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
966 { |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
967 clear_cellstr_cache (); |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
968 return m_matrix.data (); |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
969 } |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
970 |
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
|
971 bool |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
972 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
|
973 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
|
974 { |
4687 | 975 #if defined (HAVE_HDF5) |
4815 | 976 |
32598
2f3b54f81947
avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents:
32589
diff
changeset
|
977 const dim_vector& dv = dims (); |
4837 | 978 int empty = save_hdf5_empty (loc_id, name, dv); |
979 if (empty) | |
980 return (empty > 0); | |
981 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
982 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
|
983 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
|
984 space_hid = data_hid = size_hid = -1; |
4687 | 985 |
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
|
986 #if defined (HAVE_HDF5_18) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
987 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
|
988 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
|
989 #else |
4687 | 990 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
|
991 #endif |
4815 | 992 |
993 if (data_hid < 0) | |
994 return false; | |
4687 | 995 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
996 // Have to save cell array shape, since can't have a |
4814 | 997 // dataset of groups.... |
4815 | 998 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23589
diff
changeset
|
999 space_hid = H5Screate_simple (1, &rank, nullptr); |
4815 | 1000 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1001 if (space_hid < 0) |
4687 | 1002 { |
1003 H5Gclose (data_hid); | |
1004 return false; | |
1005 } | |
1006 | |
5351 | 1007 OCTAVE_LOCAL_BUFFER (octave_idx_type, hdims, rank); |
4814 | 1008 |
1009 // Octave uses column-major, while HDF5 uses row-major ordering | |
4933 | 1010 for (hsize_t i = 0; i < rank; i++) |
4815 | 1011 hdims[i] = dv(rank-i-1); |
4814 | 1012 |
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
|
1013 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1014 size_hid = H5Dcreate (data_hid, "dims", H5T_NATIVE_IDX, space_hid, |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
1015 octave_H5P_DEFAULT, octave_H5P_DEFAULT, |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
1016 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
|
1017 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1018 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
|
1019 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
|
1020 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1021 if (size_hid < 0) |
4687 | 1022 { |
1023 H5Sclose (space_hid); | |
1024 H5Gclose (data_hid); | |
1025 return false; | |
1026 } | |
1027 | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1028 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
|
1029 octave_H5P_DEFAULT, hdims) < 0) |
4687 | 1030 { |
1031 H5Dclose (size_hid); | |
1032 H5Sclose (space_hid); | |
1033 H5Gclose (data_hid); | |
1034 return false; | |
1035 } | |
4815 | 1036 |
4687 | 1037 H5Dclose (size_hid); |
1038 H5Sclose (space_hid); | |
1039 | |
4815 | 1040 // Recursively add each element of the cell to this group. |
1041 | |
4687 | 1042 Cell tmp = cell_value (); |
5850 | 1043 |
1044 octave_idx_type nel = dv.numel (); | |
1045 | |
1046 for (octave_idx_type i = 0; i < nel; i++) | |
4687 | 1047 { |
5765 | 1048 std::ostringstream buf; |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
1049 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
|
1050 (nel)) + 1.0)); |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
1051 buf << '_' << std::setw (digits) << std::setfill ('0') << i; |
5765 | 1052 std::string s = buf.str (); |
4687 | 1053 |
5850 | 1054 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
|
1055 save_as_floats)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1056 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1057 H5Gclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1058 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1059 } |
4687 | 1060 } |
1061 | |
1062 H5Gclose (data_hid); | |
4815 | 1063 |
4687 | 1064 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
|
1065 |
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
|
1066 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1067 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1068 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1069 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
|
1070 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1071 warn_save ("hdf5"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1072 |
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
|
1073 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
|
1074 #endif |
4687 | 1075 } |
1076 | |
1077 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
|
1078 octave_cell::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4687 | 1079 { |
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
|
1080 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
|
1081 |
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
|
1082 #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
|
1083 |
8815
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1084 clear_cellstr_cache (); |
af907aeedbf4
cache cellstr_value in ov-cell
Jaroslav Hajek <highegg@gmail.com>
parents:
8733
diff
changeset
|
1085 |
4837 | 1086 dim_vector dv; |
1087 int empty = load_hdf5_empty (loc_id, name, dv); | |
1088 if (empty > 0) | |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
1089 m_matrix.resize (dv); |
4837 | 1090 if (empty) |
1091 return (empty > 0); | |
1092 | |
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
|
1093 #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
|
1094 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
|
1095 #else |
4687 | 1096 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
|
1097 #endif |
4687 | 1098 |
1099 if (group_id < 0) | |
1100 return false; | |
1101 | |
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
|
1102 #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
|
1103 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
|
1104 #else |
4814 | 1105 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
|
1106 #endif |
4687 | 1107 hid_t space_hid = H5Dget_space (data_hid); |
1108 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
|
1109 if (rank != 1) |
4687 | 1110 { |
4837 | 1111 H5Dclose (data_hid); |
1112 H5Gclose (group_id); | |
4687 | 1113 return false; |
1114 } | |
1115 | |
4814 | 1116 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
1117 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
4815 | 1118 |
4814 | 1119 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); |
4687 | 1120 |
4815 | 1121 // Octave uses column-major, while HDF5 uses row-major ordering. |
1122 | |
4814 | 1123 dv.resize (hdims[0]); |
4815 | 1124 |
5351 | 1125 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
|
1126 |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
1127 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
|
1128 octave_H5P_DEFAULT, tmp) < 0) |
4687 | 1129 { |
4837 | 1130 H5Dclose (data_hid); |
1131 H5Gclose (group_id); | |
4687 | 1132 return false; |
1133 } | |
4815 | 1134 |
4687 | 1135 H5Dclose (data_hid); |
1136 H5Gclose (group_id); | |
1137 | |
4815 | 1138 for (hsize_t i = 0, j = hdims[0] - 1; i < hdims[0]; i++, j--) |
4814 | 1139 dv(j) = tmp[i]; |
1140 | |
4687 | 1141 hdf5_callback_data dsub; |
1142 | |
1143 herr_t retval2 = -1; | |
4815 | 1144 |
4814 | 1145 Cell m (dv); |
4815 | 1146 |
4687 | 1147 int current_item = 0; |
4815 | 1148 |
4696 | 1149 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
|
1150 #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
|
1151 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
|
1152 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1153 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
|
1154 #endif |
5060 | 1155 H5Gget_num_objs (group_id, &num_obj); |
1156 H5Gclose (group_id); | |
4696 | 1157 |
5275 | 1158 for (octave_idx_type i = 0; i < dv.numel (); i++) |
4687 | 1159 { |
4696 | 1160 |
4814 | 1161 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
|
1162 retval2 = -1; |
4814 | 1163 else |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
1164 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
|
1165 |
4687 | 1166 if (retval2 <= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1167 break; |
4814 | 1168 |
1169 octave_value ov = dsub.tc; | |
1170 m.elem (i) = ov; | |
1171 | |
4687 | 1172 } |
1173 | |
1174 if (retval2 >= 0) | |
1175 { | |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
1176 m_matrix = m; |
4687 | 1177 retval = true; |
1178 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1179 |
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
|
1180 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1181 octave_unused_parameter (loc_id); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1182 octave_unused_parameter (name); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
1183 |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1184 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
|
1185 #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
|
1186 |
4687 | 1187 return retval; |
1188 } | |
4815 | 1189 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31262
diff
changeset
|
1190 OCTAVE_BEGIN_NAMESPACE(octave) |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
1191 |
3354 | 1192 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
|
1193 doc: /* -*- texinfo -*- |
30559
841a10208c38
doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents:
30391
diff
changeset
|
1194 @deftypefn {} {@var{tf} =} iscell (@var{x}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1195 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
|
1196 @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
|
1197 @end deftypefn */) |
3354 | 1198 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1199 if (args.length () != 1) |
5823 | 1200 print_usage (); |
3354 | 1201 |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23575
diff
changeset
|
1202 return ovl (args(0).iscell ()); |
3354 | 1203 } |
1204 | |
1205 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
|
1206 doc: /* -*- texinfo -*- |
30888
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
1207 @deftypefn {} {@var{C} =} cell (@var{n}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
1208 @deftypefnx {} {@var{C} =} cell (@var{m}, @var{n}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
1209 @deftypefnx {} {@var{C} =} cell (@var{m}, @var{n}, @var{k}, @dots{}) |
32d2b6604a9f
doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents:
30565
diff
changeset
|
1210 @deftypefnx {} {@var{C} =} cell ([@var{m} @var{n} @dots{}]) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1211 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
|
1212 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1213 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
|
1214 @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
|
1215 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
|
1216 dimensions. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1217 @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
|
1218 @end deftypefn */) |
3354 | 1219 { |
1220 int nargin = args.length (); | |
1221 | |
4563 | 1222 dim_vector dims; |
1223 | |
3354 | 1224 switch (nargin) |
1225 { | |
4563 | 1226 case 0: |
1227 dims = dim_vector (0, 0); | |
3354 | 1228 break; |
1229 | |
4563 | 1230 case 1: |
31262
b8f4ec18e728
Allow cell input to cell() function (bug #63132)
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
1231 if (args(0).iscell ()) |
b8f4ec18e728
Allow cell input to cell() function (bug #63132)
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
1232 return args(0); // shortcut path for input which is already a Cell |
b8f4ec18e728
Allow cell input to cell() function (bug #63132)
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
1233 else |
b8f4ec18e728
Allow cell input to cell() function (bug #63132)
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
1234 get_dimensions (args(0), "cell", dims); |
3354 | 1235 break; |
1236 | |
1237 default: | |
4563 | 1238 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1239 dims.resize (nargin); |
4563 | 1240 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1241 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
|
1242 dims(i) = (args(i).isempty () |
33446
5fded8395daa
rename yTYPE_value functions strict_TYPE_value
John W. Eaton <jwe@octave.org>
parents:
33365
diff
changeset
|
1243 ? 0 : args(i).strict_idx_type_value ("cell: dimension must be a scalar integer")); |
4563 | 1244 } |
3354 | 1245 break; |
1246 } | |
1247 | |
20558
1a0a433c8263
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20449
diff
changeset
|
1248 dims.chop_trailing_singletons (); |
4563 | 1249 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1250 check_dimensions (dims, "cell"); |
4563 | 1251 |
22200
46b67f1569b5
FCell: avoid repeating default value for a newly created Cell.
Carnë Draug <carandraug@octave.org>
parents:
22197
diff
changeset
|
1252 return ovl (Cell (dims)); |
3354 | 1253 } |
1254 | |
23467
0ada77ed24dd
use idx_type for dimensions instead of int (bug #50934)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
1255 /* |
32060
1203a2d81a42
Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents:
31814
diff
changeset
|
1256 ## Note: Matlab compatibility requires using 0 for negative dimensions. |
1203a2d81a42
Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents:
31814
diff
changeset
|
1257 %!assert (size (cell (2, -3)), [2, 0]) |
31262
b8f4ec18e728
Allow cell input to cell() function (bug #63132)
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
1258 |
b8f4ec18e728
Allow cell input to cell() function (bug #63132)
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
1259 %!test <*63132> |
b8f4ec18e728
Allow cell input to cell() function (bug #63132)
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
1260 %! x = {1, 3}; |
b8f4ec18e728
Allow cell input to cell() function (bug #63132)
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
1261 %! y = cell (x); |
b8f4ec18e728
Allow cell input to cell() function (bug #63132)
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
1262 %! assert (x, y); |
b8f4ec18e728
Allow cell input to cell() function (bug #63132)
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
1263 %! x = cell (0, 3); |
b8f4ec18e728
Allow cell input to cell() function (bug #63132)
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
1264 %! y = cell (x); |
b8f4ec18e728
Allow cell input to cell() function (bug #63132)
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
1265 %! assert (x, y); |
b8f4ec18e728
Allow cell input to cell() function (bug #63132)
Rik <rik@octave.org>
parents:
31138
diff
changeset
|
1266 |
23467
0ada77ed24dd
use idx_type for dimensions instead of int (bug #50934)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
1267 ## 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
|
1268 ## where a 16 yottabyte array can be allocated? See bug #50934. |
28907
11f1207111c5
maint: Don't use semicolon at end of single-line BIST tests.
Rik <rik@octave.org>
parents:
28496
diff
changeset
|
1269 %!error <out of memory> cell (1e24, 1) |
23467
0ada77ed24dd
use idx_type for dimensions instead of int (bug #50934)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
1270 */ |
0ada77ed24dd
use idx_type for dimensions instead of int (bug #50934)
John W. Eaton <jwe@octave.org>
parents:
23219
diff
changeset
|
1271 |
4610 | 1272 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
|
1273 doc: /* -*- texinfo -*- |
30559
841a10208c38
doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents:
30391
diff
changeset
|
1274 @deftypefn {} {@var{tf} =} iscellstr (@var{cell}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1275 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
|
1276 string. |
24474
0b65949870e3
isstring.m: Add new function for identifying string arrays.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
1277 @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
|
1278 @end deftypefn */) |
4610 | 1279 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1280 if (args.length () != 1) |
5823 | 1281 print_usage (); |
4610 | 1282 |
23575
e95738a119da
maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents:
23481
diff
changeset
|
1283 return ovl (args(0).iscellstr ()); |
4610 | 1284 } |
1285 | |
4817 | 1286 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
|
1287 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
|
1288 @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
|
1289 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
|
1290 @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
|
1291 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1292 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
|
1293 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
|
1294 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1295 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
|
1296 @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
|
1297 @end deftypefn */) |
4817 | 1298 { |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1299 if (args.length () != 1) |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1300 print_usage (); |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1301 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1302 octave_value_list tmp = Fiscellstr (args, 1); |
4817 | 1303 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1304 if (tmp(0).is_true ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1305 return ovl (args(0)); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1306 else |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1307 { |
31718
52a5bec0fc74
style fixes: avoid breaking lines after "(" and prefer "" over QString ("")
John W. Eaton <jwe@octave.org>
parents:
31706
diff
changeset
|
1308 string_vector s = args(0).xstring_vector_value ("cellstr: argument STRING must be a 2-D character array"); |
4817 | 1309 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
1310 return ovl (s.isempty () ? Cell (octave_value ("")) |
31813
73fdf7f8381b
maint: Use consistent coding style when calling Ffunction().
Rik <rik@octave.org>
parents:
31771
diff
changeset
|
1311 : Cell (s, true)); |
4817 | 1312 } |
1313 } | |
1314 | |
4762 | 1315 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
|
1316 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
|
1317 @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
|
1318 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
|
1319 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1320 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
|
1321 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
|
1322 @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
|
1323 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1324 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1325 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1326 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
|
1327 "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
|
1328 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
|
1329 @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
|
1330 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
|
1331 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1332 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1333 [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
|
1334 [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
|
1335 [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
|
1336 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1337 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
|
1338 @result{} |
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 [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
|
1341 [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
|
1342 [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
|
1343 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
1344 @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
|
1345 @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
|
1346 |
27426
3ec072ab1bda
namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
27277
diff
changeset
|
1347 @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
|
1348 @end deftypefn */) |
4762 | 1349 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20797
diff
changeset
|
1350 if (args.length () != 1) |
5823 | 1351 print_usage (); |
4764 | 1352 |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1353 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
|
1354 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1355 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
|
1356 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1357 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
|
1358 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1359 // 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
|
1360 // [numel(fields) size(struct)] |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1361 // 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
|
1362 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1363 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
|
1364 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
|
1365 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
|
1366 else |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1367 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
|
1368 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1369 result_dv(0) = num_fields; |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1370 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1371 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
|
1372 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
|
1373 |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27426
diff
changeset
|
1374 Cell c (result_dv); |
20797
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1375 |
492738d32c60
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1376 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
|
1377 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1378 // 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
|
1379 // 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
|
1380 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
|
1381 for (octave_idx_type i = 0; i < num_fields; i++) |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30232
diff
changeset
|
1382 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
|
1383 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20879
diff
changeset
|
1384 return ovl (c); |
4762 | 1385 } |
1386 | |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1387 /* |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1388 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1389 %! 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
|
1390 %! 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
|
1391 %! 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
|
1392 %! s = struct ([keys; vals]{:}); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1393 %! t = cell2struct ([vals{:}], keys, 2); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1394 %! assert (s, t); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1395 %! assert (struct2cell (s), [vals{:}]'); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1396 %! assert (fieldnames (s), keys'); |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1397 */ |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10065
diff
changeset
|
1398 |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
31262
diff
changeset
|
1399 OCTAVE_END_NAMESPACE(octave) |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
1400 |
5900 | 1401 mxArray * |
28126
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
1402 octave_cell::as_mxArray (bool interleaved) const |
5900 | 1403 { |
28126
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
1404 mxArray *retval = new mxArray (interleaved, dims ()); |
5900 | 1405 |
1406 mxArray **elts = static_cast<mxArray **> (retval->get_data ()); | |
1407 | |
6686 | 1408 mwSize nel = numel (); |
5900 | 1409 |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
1410 const octave_value *p = m_matrix.data (); |
5900 | 1411 |
6686 | 1412 for (mwIndex i = 0; i < nel; i++) |
28126
4c21f99b4ad5
handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
1413 elts[i] = new mxArray (interleaved, p[i]); |
5900 | 1414 |
1415 return retval; | |
1416 } | |
1417 | |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1418 octave_value |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1419 octave_cell::map (unary_mapper_t umap) const |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1420 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1421 switch (umap) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1422 { |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1423 #define FORWARD_MAPPER(UMAP) \ |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
1424 case umap_ ## UMAP: \ |
31138
b3ca7f891750
maint: use "m_" prefix for member variables in class octave_base_matrix.
Rik <rik@octave.org>
parents:
30888
diff
changeset
|
1425 return m_matrix.UMAP () |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22028
diff
changeset
|
1426 |
31607
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1427 FORWARD_MAPPER (xisalnum); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1428 FORWARD_MAPPER (xisalpha); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1429 FORWARD_MAPPER (xisascii); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1430 FORWARD_MAPPER (xiscntrl); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1431 FORWARD_MAPPER (xisdigit); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1432 FORWARD_MAPPER (xisgraph); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1433 FORWARD_MAPPER (xislower); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1434 FORWARD_MAPPER (xisprint); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1435 FORWARD_MAPPER (xispunct); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1436 FORWARD_MAPPER (xisspace); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1437 FORWARD_MAPPER (xisupper); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1438 FORWARD_MAPPER (xisxdigit); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1439 FORWARD_MAPPER (xtolower); |
aac27ad79be6
maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents:
31605
diff
changeset
|
1440 FORWARD_MAPPER (xtoupper); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1441 |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1442 default: |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1443 return octave_base_value::map (umap); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1444 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9781
diff
changeset
|
1445 } |