comparison src/ov-list.cc @ 3202:44d82b369c78

[project @ 1998-10-29 20:27:57 by jwe]
author jwe
date Thu, 29 Oct 1998 20:28:02 +0000
parents 3ac3e8edc258
children 81738e630f57
comparison
equal deleted inserted replaced
3201:72bb6379d8a3 3202:44d82b369c78
52 { 52 {
53 octave_value retval; 53 octave_value retval;
54 54
55 if (idx.length () == 1) 55 if (idx.length () == 1)
56 { 56 {
57 double d = idx(0).double_value (); 57 int i = idx(0).int_value (true);
58 58
59 if (! error_state) 59 if (! error_state)
60 { 60 {
61 if (D_NINT (d) == d) 61 int n = lst.length ();
62 { 62
63 int n = lst.length (); 63 if (i > 0 && i <= n)
64 64 retval = lst(i-1);
65 int i = static_cast<int> (d);
66
67 if (i > 0 && i <= n)
68 retval = lst(i-1);
69 else
70 error ("list index = %d out of range", i);
71 }
72 else 65 else
73 error ("list index must be an integer"); 66 error ("list index = %d out of range", i);
74 } 67 }
68 else
69 error ("list index must be an integer");
75 } 70 }
76 else 71 else
77 error ("lists may only be indexed by a single scalar"); 72 error ("lists may only be indexed by a single scalar");
78 73
79 return retval; 74 return retval;
82 void 77 void
83 octave_list::assign (const octave_value_list& idx, const octave_value& rhs) 78 octave_list::assign (const octave_value_list& idx, const octave_value& rhs)
84 { 79 {
85 if (idx.length () == 1) 80 if (idx.length () == 1)
86 { 81 {
87 double d = idx(0).double_value (); 82 int i = idx(0).int_value (true);
88 83
89 if (! error_state) 84 if (! error_state)
90 { 85 {
91 if (D_NINT (d) == d) 86 int n = lst.length ();
92 { 87
93 int n = lst.length (); 88 if (i > 0 && (Vresize_on_range_error || i <= n))
94 89 lst(i-1) = rhs;
95 int i = static_cast<int> (d);
96
97 if (i > 0 && (Vresize_on_range_error || i <= n))
98 lst(i) = rhs;
99 else
100 error ("list index = %d out of range", i);
101 }
102 else 90 else
103 error ("list index must be an integer"); 91 error ("list index = %d out of range", i);
104 } 92 }
93 else
94 error ("list index must be an integer");
105 } 95 }
106 else 96 else
107 error ("lists may only be indexed by a single scalar"); 97 error ("lists may only be indexed by a single scalar");
108 } 98 }
109 99
242 { 232 {
243 octave_value_list list_1 = args(0).list_value (); 233 octave_value_list list_1 = args(0).list_value ();
244 234
245 if (! error_state) 235 if (! error_state)
246 { 236 {
247 double d_offset = args(1).double_value (); 237 int offset = args(1).int_value (true);
248 238
249 if (! error_state) 239 if (! error_state)
250 { 240 {
251 if (D_NINT (d_offset) == d_offset) 241 offset--;
242
243 int length = 0;
244
245 octave_value_list list_2;
246
247 if (nargin < 3)
248 length = list_1.length () - offset;
249 else
252 { 250 {
253 int offset = static_cast<int> (d_offset) - 1; 251 length = args(2).int_value (true);
254 252
255 int length = 0; 253 if (! error_state)
256
257 if (nargin < 3)
258 length = list_1.length () - offset;
259 else
260 { 254 {
261 double d_length = args(2).double_value (); 255 if (nargin == 4)
262
263 if (error_state)
264 return retval;
265 else
266 { 256 {
267 if (D_NINT (d_length) == d_length) 257 list_2 = args(3).list_value ();
268 length = static_cast<int> (d_length); 258
269 else 259 if (error_state)
270 error ("splice: LENGTH must be an integer"); 260 error ("splice: fourth argument must be a list");
271 } 261 }
272 } 262 }
273 263 else
274 octave_value_list list_2; 264 error ("splice: LENGTH must be an integer");
275
276 if (nargin == 4)
277 {
278 list_2 = args(3).list_value ();
279
280 if (error_state)
281 {
282 error ("splice: fourth argument must be a list");
283 return retval;
284 }
285 }
286
287 retval = list_1.splice (offset, length, list_2);
288 } 265 }
289 else 266
290 error ("splice: OFFSET must be an integer"); 267 if (! error_state)
268 retval = list_1.splice (offset, length, list_2);
291 } 269 }
292 else 270 else
293 error ("splice: OFFSET must be an integer"); 271 error ("splice: OFFSET must be an integer");
294 } 272 }
295 else 273 else