comparison src/ov-struct.cc @ 6946:10c7a803b409

[project @ 2007-10-03 14:38:48 by jwe]
author jwe
date Wed, 03 Oct 2007 14:38:48 +0000
parents e8a18d380097
children 9e32bb109980
comparison
equal deleted inserted replaced
6945:6bbf56a9718a 6946:10c7a803b409
558 Singleton cells and non-cell values are repeated so that they fill\n\ 558 Singleton cells and non-cell values are repeated so that they fill\n\
559 the entire array. If the cells are empty, create an empty structure\n\ 559 the entire array. If the cells are empty, create an empty structure\n\
560 array with the specified field names.\n\ 560 array with the specified field names.\n\
561 @end deftypefn") 561 @end deftypefn")
562 { 562 {
563 octave_value_list retval; 563 octave_value retval;
564 564
565 int nargin = args.length (); 565 int nargin = args.length ();
566 566
567 // struct ([]) returns an empty struct. 567 // struct ([]) returns an empty struct.
568 568
570 // dimensions as the empty matrix. 570 // dimensions as the empty matrix.
571 571
572 // Note that struct () creates a 1x1 struct with no fields for 572 // Note that struct () creates a 1x1 struct with no fields for
573 // compatibility with Matlab. 573 // compatibility with Matlab.
574 574
575 if (nargin == 1 && args(0).is_empty () && args(0).is_real_matrix ()) 575 if ((nargin == 1 || nargin == 2)
576 return octave_value (Octave_map (args(0).dims ())); 576 && args(0).is_empty () && args(0).is_real_matrix ())
577 {
578 Cell fields;
579
580 if (nargin == 2)
581 {
582 if (args(1).is_cellstr ())
583 retval = Octave_map (args(0).dims (), args(1).cell_value ());
584 else
585 error ("struct: expecting cell array of field names as second argument");
586 }
587 else
588 retval = Octave_map (args(0).dims ());
589
590 return retval;
591 }
577 592
578 // Check for "field", VALUE pairs. 593 // Check for "field", VALUE pairs.
579 594
580 for (int i = 0; i < nargin; i += 2) 595 for (int i = 0; i < nargin; i += 2)
581 { 596 {
656 map.assign (key, Cell (dims, args(i+1))); 671 map.assign (key, Cell (dims, args(i+1)));
657 672
658 if (error_state) 673 if (error_state)
659 return retval; 674 return retval;
660 } 675 }
661 676
662 return octave_value (map); 677 return octave_value (map);
663 } 678 }
664 679
665 DEFUN (isstruct, args, , 680 DEFUN (isstruct, args, ,
666 "-*- texinfo -*-\n\ 681 "-*- texinfo -*-\n\