changeset 23884:bd9e719f04cc

new mxGetProperty function for MEX API * mexproto.h, mex.cc (mxGetProperty): New function. * mxarray.in.h (mxArray::get_property): New function. (mxArray_base::get_property): New virtual function. * mex.cc (mxArray_octave_value::get_property): New function.
author Piotr Held <pjheld@gmail.com>
date Tue, 08 Aug 2017 16:25:44 -0700
parents b3b136bc7ce2
children 86a49caa5100
files libinterp/corefcn/mex.cc libinterp/corefcn/mexproto.h libinterp/corefcn/mxarray.in.h
diffstat 3 files changed, 40 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/mex.cc	Fri Aug 11 09:43:02 2017 -0400
+++ b/libinterp/corefcn/mex.cc	Tue Aug 08 16:25:44 2017 -0700
@@ -377,6 +377,31 @@
   // Not allowed.
   void set_class_name (const char * /*name_arg*/) { request_mutation (); }
 
+  mxArray * get_property (mwIndex idx, const char *name) const
+  {
+    mxArray *retval = nullptr;
+
+    if (val.is_classdef_object ())
+      {
+        octave_classdef *ov_cdef = val.classdef_object_value ();
+
+        if (ov_cdef)
+          {
+            cdef_object& cdef = ov_cdef->get_object_ref ();
+
+            if (cdef.is_array ())
+              cdef = cdef.array_value ().elem (idx);
+
+            octave_value prop_val = cdef.get (name);
+
+            if (prop_val.is_defined())
+              retval = new mxArray (prop_val);
+          }
+      }
+
+    return retval;
+  }
+
   mxArray * get_cell (mwIndex /*idx*/) const
   {
     request_mutation ();
@@ -2950,6 +2975,11 @@
   ptr->set_class_name (name);
 }
 
+mxArray *mxGetProperty (const mxArray *ptr, mwIndex idx, const char *propertyName)
+{
+  return ptr->get_property (idx, propertyName);
+}
+
 // Cell support.
 mxArray *
 mxGetCell (const mxArray *ptr, mwIndex idx)
--- a/libinterp/corefcn/mexproto.h	Fri Aug 11 09:43:02 2017 -0400
+++ b/libinterp/corefcn/mexproto.h	Tue Aug 08 16:25:44 2017 -0700
@@ -242,8 +242,9 @@
 /* Classes.  */
 extern OCTINTERP_API mxClassID mxGetClassID (const mxArray *ptr);
 extern OCTINTERP_API const char * mxGetClassName (const mxArray *ptr);
-
 extern OCTINTERP_API void mxSetClassName (mxArray *ptr, const char *name);
+extern OCTINTERP_API mxArray * mxGetProperty(const mxArray *ptr, mwIndex idx,
+                                             const char *propertName);
 
 /* Cell support.  */
 extern OCTINTERP_API mxArray * mxGetCell (const mxArray *ptr, mwIndex idx);
--- a/libinterp/corefcn/mxarray.in.h	Fri Aug 11 09:43:02 2017 -0400
+++ b/libinterp/corefcn/mxarray.in.h	Tue Aug 08 16:25:44 2017 -0700
@@ -224,6 +224,11 @@
 
   virtual void set_class_name (const char *name_arg) = 0;
 
+  virtual mxArray * get_property (mwIndex /*idx*/, const char */*name*/) 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 mxArray * get_cell (mwIndex /*idx*/) const
@@ -440,6 +445,9 @@
   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); }
 
   void set_class_name (const char *name_arg)
   { DO_VOID_MUTABLE_METHOD (set_class_name (name_arg)); }