octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mexGet and mexSet


From: David Bateman
Subject: Re: mexGet and mexSet
Date: Fri, 27 Apr 2007 12:33:34 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

With the patch this time

D.

-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

*** ./examples/myprop.c.orig23  2007-04-27 12:18:16.564192277 +0200
--- ./examples/myprop.c 2007-04-27 12:15:49.631633838 +0200
***************
*** 0 ****
--- 1,25 ----
+ #include "mex.h"
+ 
+ void
+ mexFunction (int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
+ {
+   double handle;
+   char property[256];
+ 
+   if (nrhs < 2 || nrhs > 3)
+     mexErrMsgTxt ("incorrect number of arguments");
+   if (!mxIsDouble(prhs[0]))
+     mexErrMsgTxt ("handle expected to be a double scalar");
+   if (!mxIsChar (prhs[1]))
+     mexErrMsgTxt ("expected property to be a string");
+   
+   handle = mxGetScalar (prhs[0]);
+   mxGetString (prhs[1], property, 256);
+   plhs[0] = mxDuplicateArray (mexGet (handle, property));
+   
+   if (nrhs == 3)
+     if (mexSet (handle, property, mxDuplicateArray (prhs[2])))
+       mexErrMsgTxt ("failed to set property");
+ }
+   
+ 
*** ./src/graphics.cc.orig23    2007-04-27 12:17:09.063612862 +0200
--- ./src/graphics.cc   2007-04-27 11:44:29.892415026 +0200
***************
*** 40,45 ****
--- 40,47 ----
  #include <ov-fcn-handle.h>
  #include <parse.h>
  
+ #include "graphics.h"
+ 
  static void
  gripe_set_invalid (const std::string& pname)
  {
***************
*** 3661,3666 ****
--- 3663,3706 ----
    return octave_value (gh_manager::figure_handle_list ());
  }
  
+ octave_value
+ get_property_from_handle (double handle, const std::string &property,
+                         const std::string &func)
+ {
+   graphics_object obj = gh_manager::get_object (handle);
+   octave_value retval;
+ 
+   if (obj)
+     {
+       property_name p = std::string (property);
+       retval = obj.get (p);
+     }
+   else
+     error ("%s: invalid handle (= %g)", func.c_str(), handle);
+ 
+   return retval;
+ }
+ 
+ bool
+ set_property_in_handle (double handle, const std::string &property,
+                       const octave_value &arg, const std::string &func)
+ {
+   graphics_object obj = gh_manager::get_object (handle);
+   int ret = false;
+ 
+   if (obj)
+     {
+       property_name p = std::string (property);
+       obj.set (p, arg);
+       if (!error_state)
+       ret = true;
+     }
+   else
+     error ("%s: invalid handle (= %g)", func.c_str(), handle);
+ 
+   return ret;
+ }
+ 
  /*
  ;;; Local Variables: ***
  ;;; mode: C++ ***
*** ./src/graphics.h.orig23     2007-04-27 12:17:17.545183237 +0200
--- ./src/graphics.h    2007-04-27 12:17:17.545183237 +0200
***************
*** 0 ****
--- 1,44 ----
+ /*
+ 
+ Copyright (C) 2007 John W. Eaton
+ 
+ This file is part of Octave.
+ 
+ Octave is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+ 
+ Octave is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with Octave; see the file COPYING.  If not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+ 
+ */
+ 
+ #if !defined (graphics_h)
+ #define graphics_h 1
+ 
+ #include <string>
+ #include "ov.h"
+ 
+ extern bool
+ set_property_in_handle (double handle, const std::string &property,
+                       const octave_value &arg,
+                       const std::string &func = std::string());
+ 
+ extern octave_value
+ get_property_from_handle (double handle, const std::string &property,
+                         const std::string &func = std::string());
+ #endif
+ 
+ /*
+ ;; Local Variables: ***
+ ;; mode: C++ ***
+ ;; End: ***
+ */
*** ./src/Makefile.in.orig23    2007-04-27 12:17:24.943808426 +0200
--- ./src/Makefile.in   2007-04-27 11:41:04.618923444 +0200
***************
*** 99,105 ****
  
  INCLUDES := Cell.h base-list.h c-file-ptr-stream.h comment-list.h \
        defun-dld.h defun-int.h defun.h dirfns.h dynamic-ld.h \
!       error.h file-io.h gripes.h help.h input.h \
        lex.h load-path.h load-save.h ls-hdf5.h ls-mat-ascii.h ls-mat4.h \
        ls-mat5.h ls-oct-ascii.h ls-oct-binary.h ls-utils.h \
        mex.h mexproto.h mxarray.h \
--- 99,105 ----
  
  INCLUDES := Cell.h base-list.h c-file-ptr-stream.h comment-list.h \
        defun-dld.h defun-int.h defun.h dirfns.h dynamic-ld.h \
!       error.h file-io.h graphics.h gripes.h help.h input.h \
        lex.h load-path.h load-save.h ls-hdf5.h ls-mat-ascii.h ls-mat4.h \
        ls-mat5.h ls-oct-ascii.h ls-oct-binary.h ls-utils.h \
        mex.h mexproto.h mxarray.h \
*** ./src/mex.cc.orig23 2007-04-27 12:17:39.737058889 +0200
--- ./src/mex.cc        2007-04-27 11:40:39.765192865 +0200
***************
*** 27,32 ****
--- 27,33 ----
  #include "unwind-prot.h"
  #include "utils.h"
  #include "variables.h"
+ #include "graphics.h"
  
  // #define DEBUG 1
  
***************
*** 3294,3304 ****
  }
  
  const mxArray *
! mexGet (double /*handle*/, const char */*property*/)
  {
!   // FIXME
!   error ("mexGet: not implemented");
!   return 0;
  }
  
  int
--- 3295,3308 ----
  }
  
  const mxArray *
! mexGet (double handle, const char *property)
  {
!   mxArray *m = 0;
!   octave_value ret = get_property_from_handle (handle, property, "mexGet");
! 
!   if (!error_state && ret.is_defined())
!     m = ret.as_mxArray ();
!   return m;
  }
  
  int
***************
*** 3341,3351 ****
  }
  
  int
! mexSet (double /*handle*/, const char */*property*/, mxArray */*val*/)
  {
!   // FIXME
!   error ("mexSet: not implemented");
!   return 0;
  }
  
  void
--- 3345,3356 ----
  }
  
  int
! mexSet (double handle, const char *property, mxArray *val)
  {
!   bool ret = 
!     set_property_in_handle (handle, property, mxArray::as_octave_value (val),
!                           "mexSet");
!   return (ret ? 0 : 1);
  }
  
  void

reply via email to

[Prev in Thread] Current Thread [Next in Thread]