Mercurial > hg > octave-nkf
comparison src/ov-struct.cc @ 5592:61d6cebd243b
[project @ 2006-01-12 17:55:22 by dbateman]
author | dbateman |
---|---|
date | Thu, 12 Jan 2006 17:55:22 +0000 |
parents | 6bf56668b01a |
children | 86cd3d260b42 |
comparison
equal
deleted
inserted
replaced
5591:e7e45fe274f1 | 5592:61d6cebd243b |
---|---|
131 } | 131 } |
132 break; | 132 break; |
133 | 133 |
134 case '.': | 134 case '.': |
135 { | 135 { |
136 Cell t = dotref (idx.front ()); | 136 if (map.numel() > 0) |
137 | 137 { |
138 retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); | 138 Cell t = dotref (idx.front ()); |
139 | |
140 retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); | |
141 } | |
139 } | 142 } |
140 break; | 143 break; |
141 | 144 |
142 case '{': | 145 case '{': |
143 gripe_invalid_index_type (type_name (), type[0]); | 146 gripe_invalid_index_type (type_name (), type[0]); |
305 else | 308 else |
306 gripe_failed_assignment (); | 309 gripe_failed_assignment (); |
307 } | 310 } |
308 else | 311 else |
309 { | 312 { |
310 Octave_map rhs_map = t_rhs.map_value (); | 313 if (t_rhs.is_map()) |
311 | |
312 if (! error_state) | |
313 { | 314 { |
314 map.assign (idx.front (), rhs_map); | 315 Octave_map rhs_map = t_rhs.map_value (); |
315 | 316 |
316 if (! error_state) | 317 if (! error_state) |
317 retval = octave_value (this, count + 1); | 318 { |
319 map.assign (idx.front (), rhs_map); | |
320 | |
321 if (! error_state) | |
322 retval = octave_value (this, count + 1); | |
323 else | |
324 gripe_failed_assignment (); | |
325 } | |
318 else | 326 else |
319 gripe_failed_assignment (); | 327 error ("invalid structure assignment"); |
320 } | 328 } |
321 else | 329 else |
322 error ("invalid structure assignment"); | 330 { |
331 if (t_rhs.is_empty()) | |
332 { | |
333 map.maybe_delete_elements (idx.front()); | |
334 | |
335 if (! error_state) | |
336 retval = octave_value (this, count + 1); | |
337 else | |
338 gripe_failed_assignment (); | |
339 } | |
340 else | |
341 error ("invalid structure assignment"); | |
342 } | |
323 } | 343 } |
324 } | 344 } |
325 break; | 345 break; |
326 | 346 |
327 case '.': | 347 case '.': |
391 | 411 |
392 unwind_protect_int (Vstruct_levels_to_print); | 412 unwind_protect_int (Vstruct_levels_to_print); |
393 | 413 |
394 if (Vstruct_levels_to_print >= 0) | 414 if (Vstruct_levels_to_print >= 0) |
395 { | 415 { |
396 bool print_keys_only = (Vstruct_levels_to_print == 0); | 416 bool print_keys_only = (Vstruct_levels_to_print == 0 || |
417 map.numel() == 0); | |
397 | 418 |
398 Vstruct_levels_to_print--; | 419 Vstruct_levels_to_print--; |
399 | 420 |
400 indent (os); | 421 indent (os); |
401 os << "{"; | 422 os << "{"; |
402 newline (os); | 423 newline (os); |
403 | 424 |
404 increment_indent_level (); | 425 increment_indent_level (); |
405 | 426 |
406 octave_idx_type n = map.numel (); | 427 octave_idx_type n = map_keys().length(); |
407 | 428 |
408 if (n > 1 && print_keys_only) | 429 if (n > 1 && print_keys_only) |
409 { | 430 { |
410 indent (os); | 431 indent (os); |
411 dim_vector dv = dims (); | 432 dim_vector dv = dims (); |
480 scalar (const dim_vector& dims) | 501 scalar (const dim_vector& dims) |
481 { | 502 { |
482 return dims.length () == 2 && dims (0) == 1 && dims (1) == 1; | 503 return dims.length () == 2 && dims (0) == 1 && dims (1) == 1; |
483 } | 504 } |
484 | 505 |
485 // XXX FIXME XXX -- move these tests to the test directory? | |
486 /* | 506 /* |
487 %!shared x | 507 %!shared x |
488 %! x(1).a=1; x(2).a=2; x(1).b=3; x(2).b=3; | 508 %! x(1).a=1; x(2).a=2; x(1).b=3; x(2).b=3; |
489 %!assert(struct('a',1,'b',3),x(1)) | 509 %!assert(struct('a',1,'b',3),x(1)) |
490 %!assert(struct('a',{},'b',{}),x([])) | 510 %!assert(isempty(x([]))) |
511 %!assert(isempty(struct('a',{},'b',{}))) | |
491 %!assert(struct('a',{1,2},'b',{3,3}),x) | 512 %!assert(struct('a',{1,2},'b',{3,3}),x) |
492 %!assert(struct('a',{1,2},'b',3),x) | 513 %!assert(struct('a',{1,2},'b',3),x) |
493 %!assert(struct('a',{1,2},'b',{3}),x) | 514 %!assert(struct('a',{1,2},'b',{3}),x) |
494 %!assert(struct('b',3,'a',{1,2}),x) | 515 %!assert(struct('b',3,'a',{1,2}),x) |
495 %!assert(struct('b',{3},'a',{1,2}),x) | 516 %!assert(struct('b',{3},'a',{1,2}),x) |