# HG changeset patch # User John W. Eaton # Date 1318436307 14400 # Node ID 80f7564a38496bba0268292f97e36c79a3be7f63 # Parent a2144dbc2f3a0efb2ae42cc6241856dbb78d4397 handle class objects in num2cell * cellfun.cc (Fnum2cell): Also handle class objects. * test_classes.m: New tests. diff -r a2144dbc2f3a -r 80f7564a3849 src/DLD-FUNCTIONS/cellfun.cc --- a/src/DLD-FUNCTIONS/cellfun.cc Wed Oct 12 09:06:58 2011 -0700 +++ b/src/DLD-FUNCTIONS/cellfun.cc Wed Oct 12 12:18:27 2011 -0400 @@ -45,6 +45,7 @@ #include "gripes.h" #include "utils.h" +#include "ov-class.h" #include "ov-scalar.h" #include "ov-float.h" #include "ov-complex.h" @@ -1800,10 +1801,26 @@ retval = do_num2cell (array.array_value (), dimv); } } - else if (array.is_map ()) - retval = do_num2cell (array.map_value (), dimv); + else if (array.is_map () || array.is_object ()) + { + Cell tmp = do_num2cell (array.map_value (), dimv); + + if (array.is_object ()) + { + std::string cname = array.class_name (); + std::list parents = array.parent_class_name_list (); + + for (octave_idx_type i = 0; i < tmp.numel (); i++) + tmp(i) = octave_value (new octave_class (tmp(i).map_value (), + cname, parents)); + } + + retval = tmp; + } else if (array.is_cell ()) retval = do_num2cell (array.cell_value (), dimv); + else if (array.is_object ()) + retval = do_num2cell (array.cell_value (), dimv); else gripe_wrong_type_arg ("num2cell", array); } diff -r a2144dbc2f3a -r 80f7564a3849 test/classes/test_classes.m --- a/test/classes/test_classes.m Wed Oct 12 09:06:58 2011 -0700 +++ b/test/classes/test_classes.m Wed Oct 12 12:18:27 2011 -0400 @@ -199,3 +199,14 @@ %! assert(isa(grk,'Blork')) %! assert(isa(grk,'Snork')) %! assert(isa(grk,'Spork')) + +%!test +%! d = Dork (); +%! x = [d,d]; +%! assert (size (x), [1, 2]) +%! assert (class (x), "Dork") + +%!test +%! d = Dork (); +%! x = [d,d]; +%! assert (num2cell (x), {d, d});