comparison libinterp/octave-value/ov-cell.cc @ 20590:1a0a433c8263

eliminate more simple uses of error_state * dirfns.cc, oct-map.cc, oct-stream.cc, regexp.cc, ov-base-mat.cc, ov-cell.cc, pt-idx.cc, pt-mat.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Mon, 05 Oct 2015 21:13:12 -0400
parents df4165dfc676
children
comparison
equal deleted inserted replaced
20589:b10432a40432 20590:1a0a433c8263
150 150
151 case '{': 151 case '{':
152 { 152 {
153 octave_value tmp = do_index_op (idx.front ()); 153 octave_value tmp = do_index_op (idx.front ());
154 154
155 if (! error_state) 155 Cell tcell = tmp.cell_value ();
156 { 156
157 Cell tcell = tmp.cell_value (); 157 if (tcell.numel () == 1)
158 158 retval(0) = tcell(0,0);
159 if (tcell.numel () == 1) 159 else
160 retval(0) = tcell(0,0); 160 retval = octave_value (octave_value_list (tcell), true);
161 else
162 retval = octave_value (octave_value_list (tcell), true);
163 }
164 } 161 }
165 break; 162 break;
166 163
167 case '.': 164 case '.':
168 { 165 {
202 199
203 case '{': 200 case '{':
204 { 201 {
205 octave_value tmp = do_index_op (idx.front (), auto_add); 202 octave_value tmp = do_index_op (idx.front (), auto_add);
206 203
207 if (! error_state) 204 const Cell tcell = tmp.cell_value ();
208 { 205
209 const Cell tcell = tmp.cell_value (); 206 if (tcell.numel () == 1)
210 207 retval = tcell(0,0);
211 if (tcell.numel () == 1) 208 else
212 retval = tcell(0,0); 209 retval = octave_value (octave_value_list (tcell), true);
213 else
214 retval = octave_value (octave_value_list (tcell), true);
215 }
216 } 210 }
217 break; 211 break;
218 212
219 case '.': 213 case '.':
220 { 214 {
278 octave_value tmp = do_index_op (idx.front (), true); 272 octave_value tmp = do_index_op (idx.front (), true);
279 273
280 if (! tmp.is_defined ()) 274 if (! tmp.is_defined ())
281 tmp = octave_value::empty_conv (type.substr (1), rhs); 275 tmp = octave_value::empty_conv (type.substr (1), rhs);
282 276
283 if (! error_state) 277 std::list<octave_value_list> next_idx (idx);
284 { 278
285 std::list<octave_value_list> next_idx (idx); 279 next_idx.erase (next_idx.begin ());
286 280
287 next_idx.erase (next_idx.begin ()); 281 tmp.make_unique ();
288 282
289 tmp.make_unique (); 283 t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs);
290
291 t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs);
292 }
293 } 284 }
294 } 285 }
295 break; 286 break;
296 287
297 case '{': 288 case '{':
298 { 289 {
299 matrix.make_unique (); 290 matrix.make_unique ();
300 Cell tmpc = matrix.index (idx.front (), true); 291 Cell tmpc = matrix.index (idx.front (), true);
301 292
302 if (! error_state) 293 std::list<octave_value_list> next_idx (idx);
294
295 next_idx.erase (next_idx.begin ());
296
297 std::string next_type = type.substr (1);
298
299 if (tmpc.numel () == 1)
303 { 300 {
304 std::list<octave_value_list> next_idx (idx); 301 octave_value tmp = tmpc(0);
305 302 tmpc = Cell ();
306 next_idx.erase (next_idx.begin ()); 303
307 304 if (! tmp.is_defined () || tmp.is_zero_by_zero ())
308 std::string next_type = type.substr (1);
309
310 if (tmpc.numel () == 1)
311 { 305 {
312 octave_value tmp = tmpc(0); 306 tmp = octave_value::empty_conv (type.substr (1), rhs);
313 tmpc = Cell (); 307 tmp.make_unique (); // probably a no-op.
314
315 if (! tmp.is_defined () || tmp.is_zero_by_zero ())
316 {
317 tmp = octave_value::empty_conv (type.substr (1), rhs);
318 tmp.make_unique (); // probably a no-op.
319 }
320 else
321 // optimization: ignore copy still stored inside array.
322 tmp.make_unique (1);
323
324 if (! error_state)
325 t_rhs = tmp.subsasgn (next_type, next_idx, rhs);
326 } 308 }
327 else 309 else
328 gripe_indexed_cs_list (); 310 // optimization: ignore copy still stored inside array.
311 tmp.make_unique (1);
312
313 t_rhs = tmp.subsasgn (next_type, next_idx, rhs);
329 } 314 }
315 else
316 gripe_indexed_cs_list ();
330 } 317 }
331 break; 318 break;
332 319
333 case '.': 320 case '.':
334 { 321 {
347 default: 334 default:
348 panic_impossible (); 335 panic_impossible ();
349 } 336 }
350 } 337 }
351 338
352 if (! error_state) 339 switch (type[0])
353 { 340 {
354 switch (type[0]) 341 case '(':
355 { 342 {
356 case '(': 343 octave_value_list i = idx.front ();
344
345 if (t_rhs.is_cell ())
346 octave_base_matrix<Cell>::assign (i, t_rhs.cell_value ());
347 else if (t_rhs.is_null_value ())
348 octave_base_matrix<Cell>::delete_elements (i);
349 else
350 octave_base_matrix<Cell>::assign (i, Cell (t_rhs));
351
352 if (! error_state)
357 { 353 {
358 octave_value_list i = idx.front (); 354 count++;
359 355 retval = octave_value (this);
360 if (t_rhs.is_cell ())
361 octave_base_matrix<Cell>::assign (i, t_rhs.cell_value ());
362 else if (t_rhs.is_null_value ())
363 octave_base_matrix<Cell>::delete_elements (i);
364 else
365 octave_base_matrix<Cell>::assign (i, Cell (t_rhs));
366
367 if (! error_state)
368 {
369 count++;
370 retval = octave_value (this);
371 }
372 else
373 gripe_failed_assignment ();
374 } 356 }
375 break; 357 else
376 358 gripe_failed_assignment ();
377 case '{': 359 }
360 break;
361
362 case '{':
363 {
364 octave_value_list idxf = idx.front ();
365
366 if (t_rhs.is_cs_list ())
378 { 367 {
379 octave_value_list idxf = idx.front (); 368 Cell tmp_cell = Cell (t_rhs.list_value ());
380 369
381 if (t_rhs.is_cs_list ()) 370 // Inquire the proper shape of the RHS.
382 { 371
383 Cell tmp_cell = Cell (t_rhs.list_value ()); 372 dim_vector didx = dims ().redim (idxf.length ());
384 373 for (octave_idx_type k = 0; k < idxf.length (); k++)
385 // Inquire the proper shape of the RHS. 374 if (! idxf(k).is_magic_colon ()) didx(k) = idxf(k).numel ();
386 375
387 dim_vector didx = dims ().redim (idxf.length ()); 376 if (didx.numel () == tmp_cell.numel ())
388 for (octave_idx_type k = 0; k < idxf.length (); k++) 377 tmp_cell = tmp_cell.reshape (didx);
389 if (! idxf(k).is_magic_colon ()) didx(k) = idxf(k).numel (); 378
390 379
391 if (didx.numel () == tmp_cell.numel ()) 380 octave_base_matrix<Cell>::assign (idxf, tmp_cell);
392 tmp_cell = tmp_cell.reshape (didx);
393
394
395 octave_base_matrix<Cell>::assign (idxf, tmp_cell);
396 }
397 else if (idxf.all_scalars ()
398 || do_index_op (idxf, true).numel () == 1)
399 // Regularize a null matrix if stored into a cell.
400 octave_base_matrix<Cell>::assign (idxf,
401 Cell (t_rhs.storable_value ()));
402 else if (! error_state)
403 gripe_nonbraced_cs_list_assignment ();
404
405 if (! error_state)
406 {
407 count++;
408 retval = octave_value (this);
409 }
410 else
411 gripe_failed_assignment ();
412 } 381 }
413 break; 382 else if (idxf.all_scalars ()
414 383 || do_index_op (idxf, true).numel () == 1)
415 case '.': 384 // Regularize a null matrix if stored into a cell.
385 octave_base_matrix<Cell>::assign (idxf,
386 Cell (t_rhs.storable_value ()));
387 else
388 gripe_nonbraced_cs_list_assignment ();
389
390 if (! error_state)
416 { 391 {
417 if (is_empty ()) 392 count++;
418 { 393 retval = octave_value (this);
419 // Allow conversion of empty cell array to some other
420 // type in cases like
421 //
422 // x = {}; x.f = rhs
423
424 octave_value tmp = octave_value::empty_conv (type, rhs);
425
426 return tmp.subsasgn (type, idx, rhs);
427 }
428 else
429 {
430 std::string nm = type_name ();
431 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
432 }
433 } 394 }
434 break; 395 else
435 396 gripe_failed_assignment ();
436 default: 397 }
437 panic_impossible (); 398 break;
438 } 399
400 case '.':
401 {
402 if (is_empty ())
403 {
404 // Allow conversion of empty cell array to some other
405 // type in cases like
406 //
407 // x = {}; x.f = rhs
408
409 octave_value tmp = octave_value::empty_conv (type, rhs);
410
411 return tmp.subsasgn (type, idx, rhs);
412 }
413 else
414 {
415 std::string nm = type_name ();
416 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
417 }
418 }
419 break;
420
421 default:
422 panic_impossible ();
439 } 423 }
440 424
441 return retval; 425 return retval;
442 } 426 }
443 427
611 std::queue<string_vector> strvec_queue; 595 std::queue<string_vector> strvec_queue;
612 596
613 for (octave_idx_type i = 0; i < nel; i++) 597 for (octave_idx_type i = 0; i < nel; i++)
614 { 598 {
615 string_vector s = matrix(i).all_strings (); 599 string_vector s = matrix(i).all_strings ();
616
617 if (error_state)
618 return retval;
619 600
620 octave_idx_type s_len = s.numel (); 601 octave_idx_type s_len = s.numel ();
621 602
622 n_elts += s_len ? s_len : 1; 603 n_elts += s_len ? s_len : 1;
623 604
1339 } 1320 }
1340 } 1321 }
1341 break; 1322 break;
1342 } 1323 }
1343 1324
1344 if (! error_state) 1325 dims.chop_trailing_singletons ();
1345 { 1326
1346 dims.chop_trailing_singletons (); 1327 check_dimensions (dims, "cell");
1347 1328
1348 check_dimensions (dims, "cell"); 1329 retval = Cell (dims, Matrix ());
1349
1350 if (! error_state)
1351 retval = Cell (dims, Matrix ());
1352 }
1353 1330
1354 return retval; 1331 return retval;
1355 } 1332 }
1356 1333
1357 DEFUN (iscellstr, args, , 1334 DEFUN (iscellstr, args, ,