diff libinterp/corefcn/mxarray.in.h @ 23893:75eff5b667b3

new mxSetProperty function for MEX API * mex.cc, mexproto.h (mxSetProperty): New function. * mex.cc (mxArray_octave_value::get_property): Forward to octave_classdef::get_property to do the real work. * mxarray.in.h, mex.cc (mxArray_octave_value::set_property): New function. * mxarray.in.h (mxArray::set_property): New virtual function. * mxarray.in.h (mxArray::as_octave_value): Now public. * ov-classdef.h (cdef_object::set_property, cdef_object::set_property, cdef_object_array::set_property, cdef_object_array::set_property, cdef_object_scalar::set_property, cdef_object_scalar::set_property): New functions. (cdef_object_rep::set_property, cdef_object_rep::set_property): New virtual functions.
author John W. Eaton <jwe@octave.org>
date Fri, 11 Aug 2017 17:26:38 -0400
parents 142a9c7e403a
children 194eb4bd202b
line wrap: on
line diff
--- a/libinterp/corefcn/mxarray.in.h	Fri Aug 11 11:39:40 2017 -0700
+++ b/libinterp/corefcn/mxarray.in.h	Fri Aug 11 17:26:38 2017 -0400
@@ -224,13 +224,23 @@
 
   virtual void set_class_name (const char *name_arg) = 0;
 
-  virtual mxArray * get_property (mwIndex /*idx*/, const char * /*name*/) const
+  // The following functions aren't pure virtual becuase they are only
+  // valid for one type.  Making them pure virtual would mean tha they
+  // have to be implemented for all derived types, and all of those
+  // would need to throw errors instead of just doing it once here.
+
+  virtual mxArray *
+  get_property (mwIndex /*idx*/, const char * /*pname*/) const
   {
     return nullptr;
   }
 
-  // FIXME: Why not just have this '= 0' as the others?
-  // Could then eliminate err_invalid_type function and #include "error.h".
+  virtual void set_property (mwIndex /*idx*/, const char * /*pname*/,
+                             const mxArray * /*pval*/)
+  {
+    err_invalid_type ();
+  }
+
   virtual mxArray * get_cell (mwIndex /*idx*/) const
   {
     err_invalid_type ();
@@ -445,9 +455,12 @@
   mxClassID get_class_id (void) const { return rep->get_class_id (); }
 
   const char * get_class_name (void) const { return rep->get_class_name (); }
-  
-  mxArray * get_property (mwIndex idx, const char * propNm) const
-  { return rep->get_property (idx, propNm); }
+
+  mxArray * get_property (mwIndex idx, const char *pname) const
+  { return rep->get_property (idx, pname); }
+
+  void set_property (mwIndex idx, const char *pname, const mxArray *pval)
+  { rep->set_property (idx, pname, pval); }
 
   void set_class_name (const char *name_arg)
   { DO_VOID_MUTABLE_METHOD (set_class_name (name_arg)); }
@@ -534,8 +547,6 @@
 
   static octave_value as_octave_value (const mxArray *ptr);
 
-protected:
-
   octave_value as_octave_value (void) const;
 
 private: