changeset 28072:47238792de58 stable

provide default size method for classdef objects * ov-classdef.h, ov-classdef.cc (octave_classdef::size): New method, similar to octave_class::size method.
author John W. Eaton <jwe@octave.org>
date Fri, 14 Feb 2020 14:34:48 -0500
parents 564fe206b431
children a3b40e48c069
files libinterp/octave-value/ov-classdef.cc libinterp/octave-value/ov-classdef.h
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-classdef.cc	Mon Feb 17 12:42:15 2020 -0500
+++ b/libinterp/octave-value/ov-classdef.cc	Fri Feb 14 14:34:48 2020 -0500
@@ -204,6 +204,32 @@
   return octave_value ();
 }
 
+Matrix
+octave_classdef::size (void)
+{
+  octave::cdef_class cls = object.get_class ();
+
+  if (! in_class_method (cls) && ! called_from_builtin ())
+    {
+      octave::cdef_method meth = cls.find_method ("size");
+
+      if (meth.ok ())
+        {
+          count++;
+          octave_value_list args (1, octave_value (this));
+
+          octave_value_list lv = meth.execute (args, 1, true, "size");
+          if (lv.length () <= 0
+              || ! lv(0).is_matrix_type () || ! lv(0).dims ().isvector ())
+            error ("%s.size: invalid return value", class_name ().c_str ());
+
+          return lv(0).matrix_value ();
+        }
+    }
+
+  return octave_base_value::size ();
+}
+
 octave_idx_type
 octave_classdef::xnumel (const octave_value_list& idx)
 {
--- a/libinterp/octave-value/ov-classdef.h	Mon Feb 17 12:42:15 2020 -0500
+++ b/libinterp/octave-value/ov-classdef.h	Fri Feb 14 14:34:48 2020 -0500
@@ -113,6 +113,8 @@
                   const std::list<octave_value_list>& idx,
                   const octave_value& rhs);
 
+  Matrix size (void);
+
   octave_idx_type xnumel (const octave_value_list&);
 
   string_vector map_keys (void) const { return object.map_keys (); }