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