Mercurial > hg > octave-lyh
annotate src/Cell.h @ 8290:7cbe01c21986
improve dense array indexing
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 20 Oct 2008 16:54:28 +0200 |
parents | 977d5204cf67 |
children | 9238637cb81c |
rev | line source |
---|---|
3353 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1999, 2002, 2003, 2004, 2005, 2006, 2007 John W. Eaton |
3353 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
3353 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
3353 | 20 |
21 */ | |
22 | |
23 #if !defined (Cell_h) | |
24 #define Cell_h 1 | |
25 | |
26 #include <string> | |
27 | |
4513 | 28 #include "ArrayN.h" |
3353 | 29 #include "oct-alloc.h" |
30 #include "str-vec.h" | |
31 | |
4055 | 32 #include "oct-obj.h" |
3353 | 33 |
34 class | |
6169 | 35 OCTINTERP_API |
4513 | 36 Cell : public ArrayN<octave_value> |
3353 | 37 { |
38 public: | |
39 | |
40 Cell (void) | |
4548 | 41 : ArrayN<octave_value> (dim_vector (0, 0)) { } |
3928 | 42 |
43 Cell (const octave_value& val) | |
4513 | 44 : ArrayN<octave_value> (dim_vector (1, 1), val) { } |
45 | |
46 Cell (const octave_value_list& ovl) | |
6833 | 47 : ArrayN<octave_value> (dim_vector (1, ovl.length ())) |
4513 | 48 { |
5275 | 49 for (octave_idx_type i = 0; i < ovl.length (); i++) |
4513 | 50 elem (i) = ovl (i); |
51 } | |
3353 | 52 |
7209 | 53 Cell (octave_idx_type n, octave_idx_type m, |
54 const octave_value& val = resize_fill_value ()) | |
4513 | 55 : ArrayN<octave_value> (dim_vector (n, m), val) { } |
3353 | 56 |
4587 | 57 Cell (const dim_vector& dv, const octave_value& val = resize_fill_value ()) |
58 : ArrayN<octave_value> (dv, val) { } | |
4563 | 59 |
4513 | 60 Cell (const ArrayN<octave_value>& c) |
61 : ArrayN<octave_value> (c) { } | |
3354 | 62 |
4567 | 63 Cell (const Array<octave_value>& c) |
64 : ArrayN<octave_value> (c) { } | |
65 | |
5275 | 66 Cell (const Array<octave_value>& c, octave_idx_type nr, octave_idx_type nc) |
4513 | 67 : ArrayN<octave_value> (c, dim_vector (nr, nc)) { } |
3933 | 68 |
5805 | 69 Cell (const string_vector& sv, bool trim = false); |
4216 | 70 |
6116 | 71 Cell (const dim_vector& dv, const string_vector& sv, bool trim = false); |
72 | |
3353 | 73 Cell (const Cell& c) |
4513 | 74 : ArrayN<octave_value> (c) { } |
75 | |
6116 | 76 bool is_cellstr (void) const; |
77 | |
4513 | 78 Cell index (const octave_value_list& idx, bool resize_ok = false) const; |
79 | |
80 Cell index (idx_vector& i, int resize_ok = 0, | |
81 const octave_value& rfv = resize_fill_value ()) const | |
4567 | 82 { return Cell (ArrayN<octave_value>::index (i, resize_ok, rfv)); } |
4513 | 83 |
84 Cell index (idx_vector& i, idx_vector& j, int resize_ok = 0, | |
85 const octave_value& rfv = resize_fill_value ()) const | |
4567 | 86 { return Cell (ArrayN<octave_value>::index (i, j, resize_ok, rfv)); } |
4513 | 87 |
88 Cell index (Array<idx_vector>& ra_idx, int resize_ok = 0, | |
89 const octave_value& rfv = resize_fill_value ()) const | |
4567 | 90 { return Cell (ArrayN<octave_value>::index (ra_idx, resize_ok, rfv)); } |
4513 | 91 |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8175
diff
changeset
|
92 // FIXME: This seems necessary for octave_base_mat<Cell>::delete_elements |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8175
diff
changeset
|
93 // to work, but I don't understand why. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8175
diff
changeset
|
94 void delete_elements (const Array<idx_vector>& ia) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8175
diff
changeset
|
95 { ArrayN<octave_value>::delete_elements (ia); } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8175
diff
changeset
|
96 |
8175
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
97 Cell& delete_elements (const octave_value_list& idx); |
977d5204cf67
fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents:
7620
diff
changeset
|
98 |
4513 | 99 Cell& assign (const octave_value_list& idx, const Cell& rhs, |
100 const octave_value& fill_val = octave_value ()); | |
101 | |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8175
diff
changeset
|
102 // FIXME: This seems necessary for octave_base_mat<Cell>::assign |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8175
diff
changeset
|
103 // to work, but I don't understand why. |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8175
diff
changeset
|
104 void assign (const Array<idx_vector>& ia, const Array<octave_value>& rhs, |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8175
diff
changeset
|
105 const octave_value& fill_val = octave_value ()) |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8175
diff
changeset
|
106 { ArrayN<octave_value>::assign (ia, rhs, fill_val); } |
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8175
diff
changeset
|
107 |
4901 | 108 Cell reshape (const dim_vector& new_dims) const |
109 { return ArrayN<octave_value>::reshape (new_dims); } | |
110 | |
5602 | 111 octave_idx_type nnz (void) const; |
112 | |
5570 | 113 Cell column (octave_idx_type i) const; |
114 | |
5775 | 115 // FIXME |
4932 | 116 boolMatrix all (int /* dim */ = 0) const { return boolMatrix (); } |
3933 | 117 |
5775 | 118 // FIXME |
4932 | 119 boolMatrix any (int /* dim */ = 0) const { return boolMatrix (); } |
3933 | 120 |
5275 | 121 Cell concat (const Cell& rb, const Array<octave_idx_type>& ra_idx); |
4915 | 122 |
5275 | 123 Cell& insert (const Cell& a, octave_idx_type r, octave_idx_type c); |
124 Cell& insert (const Cell& a, const Array<octave_idx_type>& ra_idx); | |
4806 | 125 |
5775 | 126 // FIXME |
3933 | 127 bool is_true (void) const { return false; } |
128 | |
4219 | 129 static octave_value resize_fill_value (void) { return Matrix (); } |
7530
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
130 |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
131 Cell diag (octave_idx_type k = 0) const; |
7618
3209a584e1ac
Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents:
7530
diff
changeset
|
132 |
7530
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
133 Cell xisalnum (void) const { return map (&octave_value::xisalnum); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
134 Cell xisalpha (void) const { return map (&octave_value::xisalpha); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
135 Cell xisascii (void) const { return map (&octave_value::xisascii); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
136 Cell xiscntrl (void) const { return map (&octave_value::xiscntrl); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
137 Cell xisdigit (void) const { return map (&octave_value::xisdigit); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
138 Cell xisgraph (void) const { return map (&octave_value::xisgraph); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
139 Cell xislower (void) const { return map (&octave_value::xislower); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
140 Cell xisprint (void) const { return map (&octave_value::xisprint); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
141 Cell xispunct (void) const { return map (&octave_value::xispunct); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
142 Cell xisspace (void) const { return map (&octave_value::xisspace); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
143 Cell xisupper (void) const { return map (&octave_value::xisupper); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
144 Cell xisxdigit (void) const { return map (&octave_value::xisxdigit); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
145 Cell xtoascii (void) const { return map (&octave_value::xtoascii); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
146 Cell xtolower (void) const { return map (&octave_value::xtolower); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
147 Cell xtoupper (void) const { return map (&octave_value::xtoupper); } |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
148 |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
149 private: |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
150 |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
151 typedef octave_value (octave_value::*ctype_mapper) (void) const; |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
152 |
bb0f2353cff5
new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
7209
diff
changeset
|
153 Cell map (ctype_mapper) const; |
3353 | 154 }; |
155 | |
156 #endif | |
157 | |
158 /* | |
159 ;;; Local Variables: *** | |
160 ;;; mode: C++ *** | |
161 ;;; End: *** | |
162 */ |