annotate src/Cell.cc @ 8732:a669df7beb73

[mq]: x
author John W. Eaton <jwe@octave.org>
date Thu, 12 Feb 2009 14:37:43 -0500
parents 280fae940bb0
children eb63fbe60fab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
1 /*
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1999, 2002, 2003, 2004, 2005, 2006, 2007 John W. Eaton
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
4
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
6
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6116
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6116
diff changeset
10 option) any later version.
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
11
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
15 for more details.
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
16
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6116
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6116
diff changeset
19 <http://www.gnu.org/licenses/>.
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
20
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
21 */
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
22
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
25 #endif
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
26
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
27 #include "idx-vector.h"
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
28
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
29 #include "Cell.h"
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
30 #include "error.h"
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
31 #include "gripes.h"
8579
7e0f36dfefbe implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
32 #include "oct-obj.h"
7e0f36dfefbe implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
33
7e0f36dfefbe implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
34 Cell::Cell (const octave_value_list& ovl)
7e0f36dfefbe implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
35 : ArrayN<octave_value> (ovl.cell_value ())
7e0f36dfefbe implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
36 {
7e0f36dfefbe implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
37 }
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
38
5805
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
39 Cell::Cell (const string_vector& sv, bool trim)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
40 : ArrayN<octave_value> ()
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
41 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
42 octave_idx_type n = sv.length ();
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
43
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
44 if (n > 0)
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
45 {
4625
87c01a296263 [project @ 2003-11-15 12:51:20 by jwe]
jwe
parents: 4587
diff changeset
46 resize (dim_vector (n, 1));
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
47
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
48 for (octave_idx_type i = 0; i < n; i++)
5805
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
49 {
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
50 std::string s = sv[i];
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
51
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
52 if (trim)
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
53 {
5814
67bf9b4f2ae2 [project @ 2006-05-11 21:58:34 by jwe]
jwe
parents: 5805
diff changeset
54 size_t pos = s.find_last_not_of (' ');
5805
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
55
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
56 s = (pos == std::string::npos) ? "" : s.substr (0, pos+1);
5805
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
57 }
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
58
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
59 elem(i,0) = s;
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
60 }
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
61 }
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
62 }
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3353
diff changeset
63
8732
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
64 Cell::Cell (const Array<std::string>& sa)
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
65 : ArrayN<octave_value> (sa.dims ())
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
66 {
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
67 octave_idx_type n = sa.numel ();
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
68
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
69 octave_value *dst = fortran_vec ();
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
70 const std::string *src = sa.data ();
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
71
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
72 for (octave_idx_type i = 0; i < n; i++)
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
73 dst[i] = src[i];
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
74 }
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
75
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
76 // Set size to DV, filling with []. Then fill with as many elements of
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
77 // SV as possible.
7209
f06b8150fe56 [project @ 2007-11-28 05:46:58 by jwe]
jwe
parents: 7017
diff changeset
78
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
79 Cell::Cell (const dim_vector& dv, const string_vector& sv, bool trim)
7209
f06b8150fe56 [project @ 2007-11-28 05:46:58 by jwe]
jwe
parents: 7017
diff changeset
80 : ArrayN<octave_value> (dv, resize_fill_value ())
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
81 {
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
82 octave_idx_type n = sv.length ();
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
83
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
84 if (n > 0)
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
85 {
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
86 octave_idx_type m = numel ();
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
87
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
88 octave_idx_type len = n > m ? m : n;
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
89
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
90 for (octave_idx_type i = 0; i < len; i++)
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
91 {
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
92 std::string s = sv[i];
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
93
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
94 if (trim)
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
95 {
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
96 size_t pos = s.find_last_not_of (' ');
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
97
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
98 s = (pos == std::string::npos) ? "" : s.substr (0, pos+1);
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
99 }
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
100
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
101 elem(i) = s;
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
102 }
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
103 }
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
104 }
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
105
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
106 bool
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
107 Cell::is_cellstr (void) const
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
108 {
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
109 bool retval = true;
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
110
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
111 for (int i = 0; i < numel (); i++)
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
112 {
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
113 if (! elem(i).is_string ())
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
114 {
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
115 retval = false;
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
116 break;
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
117 }
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
118 }
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
119
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
120 return retval;
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
121 }
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
122
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
123 Cell
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4513
diff changeset
124 Cell::index (const octave_value_list& idx_arg, bool resize_ok) const
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
125 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
126 Cell retval;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
127
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
128 octave_idx_type n = idx_arg.length ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
129
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
130 switch (n)
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
131 {
5539
b800ae36fc6a [project @ 2005-11-16 18:45:32 by jwe]
jwe
parents: 5307
diff changeset
132 case 0:
b800ae36fc6a [project @ 2005-11-16 18:45:32 by jwe]
jwe
parents: 5307
diff changeset
133 retval = *this;
b800ae36fc6a [project @ 2005-11-16 18:45:32 by jwe]
jwe
parents: 5307
diff changeset
134 break;
b800ae36fc6a [project @ 2005-11-16 18:45:32 by jwe]
jwe
parents: 5307
diff changeset
135
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
136 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
137 {
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4513
diff changeset
138 idx_vector i = idx_arg(0).index_vector ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
139
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
140 if (! error_state)
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8579
diff changeset
141 retval = ArrayN<octave_value>::index (i, resize_ok);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
142 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
143 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
144
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
145 case 2:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
146 {
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4513
diff changeset
147 idx_vector i = idx_arg(0).index_vector ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
148
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
149 if (! error_state)
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
150 {
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
151 idx_vector j = idx_arg(1).index_vector ();
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
152
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
153 if (! error_state)
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8579
diff changeset
154 retval = ArrayN<octave_value>::index (i, j, resize_ok);
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
155 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
156 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
157 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
158
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
159 default:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
160 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
161 Array<idx_vector> iv (n);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
162
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
163 for (octave_idx_type i = 0; i < n; i++)
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
164 {
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
165 iv(i) = idx_arg(i).index_vector ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
166
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
167 if (error_state)
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
168 break;
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
169 }
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
170
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
171 if (!error_state)
8679
280fae940bb0 optimize scalar indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8579
diff changeset
172 retval = ArrayN<octave_value>::index (iv, resize_ok);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
173 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
174 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
175 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
176
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
177 return retval;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
178 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
179
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
180 Cell&
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4513
diff changeset
181 Cell::assign (const octave_value_list& idx_arg, const Cell& rhs,
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
182 const octave_value& fill_val)
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
183
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
184 {
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
185 octave_idx_type len = idx_arg.length ();
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
186
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
187 Array<idx_vector> ra_idx (len);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
188
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
189 for (octave_idx_type i = 0; i < len; i++)
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
190 ra_idx(i) = idx_arg(i).index_vector ();
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
191
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
192 Array<octave_value>::assign (ra_idx, rhs, fill_val);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
193
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
194 return *this;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
195 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
196
8175
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
197 Cell&
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
198 Cell::delete_elements (const octave_value_list& idx_arg)
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
199
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
200 {
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
201 octave_idx_type len = idx_arg.length ();
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
202
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
203 Array<idx_vector> ra_idx (len);
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
204
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
205 for (octave_idx_type i = 0; i < len; i++)
8175
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
206 ra_idx.xelem (i) = idx_arg(i).index_vector ();
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
207
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
208 Array<octave_value>::delete_elements (ra_idx);
8175
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
209
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
210 return *this;
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
211 }
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
212
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
213 octave_idx_type
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
214 Cell::nnz (void) const
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
215 {
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
216 gripe_wrong_type_arg ("nnz", "cell array");
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
217 return -1;
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
218 }
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
219
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
220 Cell
5570
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
221 Cell::column (octave_idx_type i) const
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
222 {
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
223 Cell retval;
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
224
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
225 if (ndims () < 3)
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
226 {
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
227 if (i < 0 || i >= cols ())
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
228 error ("invalid column selection");
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
229 else
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
230 {
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
231 octave_idx_type nr = rows ();
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
232
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
233 retval.resize (dim_vector (nr, 1));
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
234
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
235 for (octave_idx_type j = 0; j < nr; j++)
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
236 retval.xelem (j) = elem (j, i);
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
237 }
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
238 }
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
239 else
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
240 error ("Cell::column: requires 2-d cell array");
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
241
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
242 return retval;
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
243 }
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
244
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
245 Cell
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
246 Cell::concat (const Cell& rb, const Array<octave_idx_type>& ra_idx)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4625
diff changeset
247 {
5073
e71be9c548f2 [project @ 2004-11-09 18:31:25 by jwe]
jwe
parents: 4919
diff changeset
248 return insert (rb, ra_idx);
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
249 }
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
250
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
251 Cell&
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
252 Cell::insert (const Cell& a, octave_idx_type r, octave_idx_type c)
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
253 {
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
254 Array<octave_value>::insert (a, r, c);
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
255 return *this;
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
256 }
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
257
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
258 Cell&
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
259 Cell::insert (const Cell& a, const Array<octave_idx_type>& ra_idx)
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
260 {
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
261 Array<octave_value>::insert (a, ra_idx);
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
262 return *this;
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4625
diff changeset
263 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4625
diff changeset
264
7530
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
265 Cell
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
266 Cell::map (ctype_mapper fcn) const
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
267 {
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
268 Cell retval (dims ());
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
269 octave_value *r = retval.fortran_vec ();
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
270
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
271 const octave_value *p = data ();
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
272
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
273 for (octave_idx_type i = 0; i < numel (); i++)
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
274 r[i] = ((p++)->*fcn) ();
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
275
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
276 return retval;
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
277 }
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
278
7618
3209a584e1ac Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents: 7530
diff changeset
279 Cell
3209a584e1ac Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents: 7530
diff changeset
280 Cell::diag (octave_idx_type k) const
3209a584e1ac Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents: 7530
diff changeset
281 {
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
282 return ArrayN<octave_value>::diag (k);
7618
3209a584e1ac Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents: 7530
diff changeset
283 }
3209a584e1ac Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents: 7530
diff changeset
284
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
285 /*
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
286 ;;; Local Variables: ***
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
287 ;;; mode: C++ ***
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
288 ;;; End: ***
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
289 */