3353
|
1 /* |
|
2 |
|
3 Copyright (C) 1999 John W. Eaton |
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (Cell_h) |
|
24 #define Cell_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
3353
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <string> |
|
31 |
4513
|
32 #include "ArrayN.h" |
3353
|
33 #include "oct-alloc.h" |
|
34 #include "str-vec.h" |
|
35 |
4055
|
36 #include "oct-obj.h" |
3353
|
37 |
|
38 class |
4513
|
39 Cell : public ArrayN<octave_value> |
3353
|
40 { |
|
41 public: |
|
42 |
|
43 Cell (void) |
4548
|
44 : ArrayN<octave_value> (dim_vector (0, 0)) { } |
3928
|
45 |
|
46 Cell (const octave_value& val) |
4513
|
47 : ArrayN<octave_value> (dim_vector (1, 1), val) { } |
|
48 |
|
49 Cell (const octave_value_list& ovl) |
|
50 : ArrayN<octave_value> (dim_vector (ovl.length (), 1)) |
|
51 { |
|
52 for (int i = 0; i < ovl.length (); i++) |
|
53 elem (i) = ovl (i); |
|
54 } |
3353
|
55 |
4219
|
56 Cell (int n, int m, const octave_value& val = resize_fill_value ()) |
4513
|
57 : ArrayN<octave_value> (dim_vector (n, m), val) { } |
3353
|
58 |
4563
|
59 Cell (const dim_vector& dims, const octave_value& val = resize_fill_value ()) |
|
60 : ArrayN<octave_value> (dims, val) { } |
|
61 |
4513
|
62 Cell (const ArrayN<octave_value>& c) |
|
63 : ArrayN<octave_value> (c) { } |
3354
|
64 |
3933
|
65 Cell (const Array<octave_value>& c, int nr, int nc) |
4513
|
66 : ArrayN<octave_value> (c, dim_vector (nr, nc)) { } |
3933
|
67 |
4216
|
68 Cell (const string_vector& sv); |
|
69 |
3353
|
70 Cell (const Cell& c) |
4513
|
71 : ArrayN<octave_value> (c) { } |
|
72 |
|
73 Cell index (const octave_value_list& idx, bool resize_ok = false) const; |
|
74 |
|
75 Cell index (idx_vector& i, int resize_ok = 0, |
|
76 const octave_value& rfv = resize_fill_value ()) const |
|
77 { return ArrayN<octave_value>::index (i, resize_ok, rfv); } |
|
78 |
|
79 Cell index (idx_vector& i, idx_vector& j, int resize_ok = 0, |
|
80 const octave_value& rfv = resize_fill_value ()) const |
|
81 { return ArrayN<octave_value>::index (i, j, resize_ok, rfv); } |
|
82 |
|
83 Cell index (Array<idx_vector>& ra_idx, int resize_ok = 0, |
|
84 const octave_value& rfv = resize_fill_value ()) const |
|
85 { return ArrayN<octave_value>::index (ra_idx, resize_ok, rfv); } |
|
86 |
|
87 Cell& assign (const octave_value_list& idx, const Cell& rhs, |
|
88 const octave_value& fill_val = octave_value ()); |
|
89 |
|
90 octave_value& operator () (int i) { return elem_internal (i); } |
|
91 |
|
92 octave_value operator () (int i) const { return elem_internal (i); } |
|
93 |
|
94 octave_value& operator () (int i, int j) |
|
95 { return ArrayN<octave_value>::operator () (i, j); } |
|
96 |
|
97 octave_value operator () (int i, int j) const |
|
98 { return ArrayN<octave_value>::operator () (i, j); } |
3353
|
99 |
3933
|
100 // XXX FIXME XXX |
4015
|
101 boolMatrix all (int dim = 0) const { return boolMatrix (); } |
3933
|
102 |
|
103 // XXX FIXME XXX |
4015
|
104 boolMatrix any (int dim = 0) const { return boolMatrix (); } |
3933
|
105 |
|
106 // XXX FIXME XXX |
|
107 bool is_true (void) const { return false; } |
|
108 |
4219
|
109 static octave_value resize_fill_value (void) { return Matrix (); } |
4513
|
110 |
|
111 private: |
|
112 |
|
113 // XXX FIXME XXX -- we need to do something intelligent if there is |
|
114 // more than one dimension, but for now this is all we need... |
|
115 |
|
116 void maybe_resize (int n) |
|
117 { |
|
118 if (n >= rows ()) |
|
119 resize (dim_vector (n + 1, 1), octave_value ()); |
|
120 } |
|
121 |
|
122 octave_value& elem_internal (int n) |
|
123 { |
|
124 maybe_resize (n); |
|
125 return elem (n); |
|
126 } |
|
127 |
|
128 octave_value elem_internal (int n) const |
|
129 { |
|
130 return elem (n); |
|
131 } |
3353
|
132 }; |
|
133 |
|
134 #endif |
|
135 |
|
136 /* |
|
137 ;;; Local Variables: *** |
|
138 ;;; mode: C++ *** |
|
139 ;;; End: *** |
|
140 */ |