Mercurial > hg > octave-nkf
comparison src/ov-struct.cc @ 9529:8e5009334661
partially revert e79470be3ecb
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 17 Aug 2009 13:09:12 +0200 |
parents | e79470be3ecb |
children | f786dca09f79 |
comparison
equal
deleted
inserted
replaced
9528:ec066ba012c8 | 9529:8e5009334661 |
---|---|
91 gripe_invalid_index_type (const std::string& nm, char t) | 91 gripe_invalid_index_type (const std::string& nm, char t) |
92 { | 92 { |
93 error ("%s cannot be indexed with %c", nm.c_str (), t); | 93 error ("%s cannot be indexed with %c", nm.c_str (), t); |
94 } | 94 } |
95 | 95 |
96 void | 96 static void |
97 octave_struct::gripe_failed_assignment (void) | 97 gripe_failed_assignment (void) |
98 { | 98 { |
99 error ("assignment to structure element failed"); | 99 error ("assignment to structure element failed"); |
100 } | 100 } |
101 | 101 |
102 octave_value_list | 102 octave_value_list |
247 | 247 |
248 if (type.length () > 0 && type[0] == '.' && ! val.is_map ()) | 248 if (type.length () > 0 && type[0] == '.' && ! val.is_map ()) |
249 retval = Octave_map (); | 249 retval = Octave_map (); |
250 else | 250 else |
251 retval = val; | 251 retval = val; |
252 | |
253 return retval; | |
254 } | |
255 | |
256 octave_value | |
257 octave_struct::dotasgn (const octave_value_list& idx, const octave_value& rhs) | |
258 { | |
259 octave_value retval; | |
260 | |
261 assert (idx.length () == 1); | |
262 | |
263 std::string key = idx(0).string_value (); | |
264 | |
265 if (rhs.is_cs_list ()) | |
266 { | |
267 Cell tmp_cell = Cell (rhs.list_value ()); | |
268 | |
269 // The shape of the RHS is irrelevant, we just want | |
270 // the number of elements to agree and to preserve the | |
271 // shape of the left hand side of the assignment. | |
272 | |
273 if (numel () == tmp_cell.numel ()) | |
274 tmp_cell = tmp_cell.reshape (dims ()); | |
275 | |
276 map.assign (key, tmp_cell); | |
277 } | |
278 else | |
279 // Regularize a null matrix if stored into a struct component. | |
280 map.assign (key, rhs.storable_value ()); | |
281 | |
282 if (! error_state) | |
283 { | |
284 count++; | |
285 retval = octave_value (this); | |
286 } | |
287 else | |
288 gripe_failed_assignment (); | |
289 | 252 |
290 return retval; | 253 return retval; |
291 } | 254 } |
292 | 255 |
293 octave_value | 256 octave_value |
491 else | 454 else |
492 gripe_failed_assignment (); | 455 gripe_failed_assignment (); |
493 } | 456 } |
494 else | 457 else |
495 { | 458 { |
496 if (t_rhs.is_map() | 459 if (t_rhs.is_map()) |
497 || (is_object () && t_rhs.is_object ())) | |
498 { | 460 { |
499 Octave_map rhs_map = t_rhs.map_value (); | 461 Octave_map rhs_map = t_rhs.map_value (); |
500 | 462 |
501 if (! error_state) | 463 if (! error_state) |
502 { | 464 { |
534 } | 496 } |
535 break; | 497 break; |
536 | 498 |
537 case '.': | 499 case '.': |
538 { | 500 { |
539 retval = dotasgn (idx.front (), t_rhs); | 501 octave_value_list key_idx = idx.front (); |
502 | |
503 assert (key_idx.length () == 1); | |
504 | |
505 std::string key = key_idx(0).string_value (); | |
506 | |
507 if (t_rhs.is_cs_list ()) | |
508 { | |
509 Cell tmp_cell = Cell (t_rhs.list_value ()); | |
510 | |
511 // The shape of the RHS is irrelevant, we just want | |
512 // the number of elements to agree and to preserve the | |
513 // shape of the left hand side of the assignment. | |
514 | |
515 if (numel () == tmp_cell.numel ()) | |
516 tmp_cell = tmp_cell.reshape (dims ()); | |
517 | |
518 map.assign (key, tmp_cell); | |
519 } | |
520 else | |
521 // Regularize a null matrix if stored into a struct component. | |
522 map.assign (key, t_rhs.storable_value ()); | |
523 | |
524 if (! error_state) | |
525 { | |
526 count++; | |
527 retval = octave_value (this); | |
528 } | |
529 else | |
530 gripe_failed_assignment (); | |
540 } | 531 } |
541 break; | 532 break; |
542 | 533 |
543 case '{': | 534 case '{': |
544 gripe_invalid_index_type (type_name (), type[0]); | 535 gripe_invalid_index_type (type_name (), type[0]); |