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 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
3353
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
4513
|
31 #include "idx-vector.h" |
|
32 |
3353
|
33 #include "Cell.h" |
4919
|
34 #include "error.h" |
3353
|
35 |
4216
|
36 Cell::Cell (const string_vector& sv) |
4513
|
37 : ArrayN<octave_value> () |
4216
|
38 { |
|
39 int n = sv.length (); |
|
40 |
|
41 if (n > 0) |
|
42 { |
4625
|
43 resize (dim_vector (n, 1)); |
4216
|
44 |
|
45 for (int i = 0; i < n; i++) |
|
46 elem(i,0) = sv[i]; |
|
47 } |
|
48 } |
3354
|
49 |
4513
|
50 Cell |
4587
|
51 Cell::index (const octave_value_list& idx_arg, bool resize_ok) const |
4513
|
52 { |
|
53 Cell retval; |
|
54 |
4587
|
55 int n = idx_arg.length (); |
4513
|
56 |
|
57 switch (n) |
|
58 { |
|
59 case 1: |
|
60 { |
4587
|
61 idx_vector i = idx_arg(0).index_vector (); |
4513
|
62 |
4919
|
63 if (! error_state) |
|
64 retval = index (i, resize_ok); |
4513
|
65 } |
|
66 break; |
|
67 |
|
68 case 2: |
|
69 { |
4587
|
70 idx_vector i = idx_arg(0).index_vector (); |
4513
|
71 |
4919
|
72 if (! error_state) |
|
73 { |
|
74 idx_vector j = idx_arg(1).index_vector (); |
|
75 |
|
76 if (! error_state) |
|
77 retval = index (i, j, resize_ok); |
|
78 } |
4513
|
79 } |
|
80 break; |
|
81 |
|
82 default: |
|
83 { |
|
84 Array<idx_vector> iv (n); |
|
85 |
|
86 for (int i = 0; i < n; i++) |
4919
|
87 { |
|
88 iv(i) = idx_arg(i).index_vector (); |
4513
|
89 |
4919
|
90 if (error_state) |
|
91 break; |
|
92 } |
|
93 |
|
94 if (!error_state) |
|
95 retval = index (iv, resize_ok); |
4513
|
96 } |
|
97 break; |
|
98 } |
|
99 |
|
100 return retval; |
|
101 } |
|
102 |
|
103 Cell& |
4587
|
104 Cell::assign (const octave_value_list& idx_arg, const Cell& rhs, |
4513
|
105 const octave_value& fill_val) |
|
106 |
|
107 { |
4587
|
108 for (int i = 0; i < idx_arg.length (); i++) |
|
109 set_index (idx_arg(i).index_vector ()); |
4513
|
110 |
|
111 ::assign (*this, rhs, fill_val); |
|
112 |
|
113 return *this; |
|
114 } |
|
115 |
4915
|
116 Cell |
5073
|
117 Cell::concat (const Cell& rb, const Array<int>& ra_idx) |
4806
|
118 { |
5073
|
119 return insert (rb, ra_idx); |
4915
|
120 } |
|
121 |
|
122 Cell& |
|
123 Cell::insert (const Cell& a, int r, int c) |
|
124 { |
|
125 Array<octave_value>::insert (a, r, c); |
|
126 return *this; |
|
127 } |
|
128 |
|
129 Cell& |
|
130 Cell::insert (const Cell& a, const Array<int>& ra_idx) |
|
131 { |
|
132 Array<octave_value>::insert (a, ra_idx); |
|
133 return *this; |
4806
|
134 } |
|
135 |
3353
|
136 /* |
|
137 ;;; Local Variables: *** |
|
138 ;;; mode: C++ *** |
|
139 ;;; End: *** |
|
140 */ |