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