annotate libinterp/octave-value/ov-cell.cc @ 29358:0a5b15007766 stable

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