Mercurial > hg > octave-avbm
changeset 6595:55586d763de1
[project @ 2007-04-27 15:31:10 by dbateman]
author | dbateman |
---|---|
date | Fri, 27 Apr 2007 15:31:10 +0000 |
parents | 5843c11b4006 |
children | 64a7b0bec331 |
files | ChangeLog doc/ChangeLog doc/interpreter/Makefile.in examples/Makefile.in examples/myprop.c src/ChangeLog src/Makefile.in src/graphics.cc src/graphics.h src/mex.cc |
diffstat | 10 files changed, 146 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -7,8 +7,8 @@ 2007-04-27 David Bateman <dbateman@free.fr> - * examples/mycell.c, examples/mypow2.c, examples/mystring.c: New - example mex files. + * examples/mycell.c, examples/mypow2.c, examples/mystring.c, + examples/myprop.c: New example mex files. 2007-04-26 Alex Zvoleff <azvoleff@sbcglobal.net>
--- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,8 @@ 2007-04-27 David Bateman <dbateman@free.fr> + * Makefile.in (EXAMPLE_FILES_NODIR): Add mycell.c, myfeval.c, + myfunc.c, mypow2.c, mysparse.c, mystring.c, mystruct.c and + paramdemo.cc. * interpreter.txi/dynamic.txi: Complete all but the section on the mex- and oct-file APIs.
--- a/doc/interpreter/Makefile.in +++ b/doc/interpreter/Makefile.in @@ -29,6 +29,14 @@ funcdemo.cc \ globaldemo.cc \ helloworld.cc \ + mycell.c \ + myfeval.c \ + myfunc.c \ + mypow2.c \ + mysparse.c \ + mystring.c \ + mystruct.c \ + paramdemo.cc \ stringdemo.cc \ structdemo.cc \ unwinddemo.cc
--- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -41,6 +41,7 @@ myfunc.c \ myhello.c \ mypow2.c \ + myprop.c \ myset.c \ mysparse.c \ mystring.c \
new file mode 100644 --- /dev/null +++ b/examples/myprop.c @@ -0,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"); +} + +
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2007-04-27 David Bateman <dbateman@free.fr> + + * graphic.cc (get_property_form_handle, set_property_in_handle): + New functions. + * grahics.h: New file. + * mex.cc (mexGet, mexSet): use the above to implement mexGet + and mexSet. + * Makefile.in (INCLUDES): Add graphics.h + 2007-04-26 John W. Eaton <jwe@octave.org> * ov-usr-fcn.cc (octave_user_function::do_multi_index_op):
--- a/src/Makefile.in +++ b/src/Makefile.in @@ -99,7 +99,7 @@ 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 \ + 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 \
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -40,6 +40,8 @@ #include <ov-fcn-handle.h> #include <parse.h> +#include "graphics.h" + static void gripe_set_invalid (const std::string& pname) { @@ -3661,6 +3663,44 @@ 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++ ***
new file mode 100644 --- /dev/null +++ b/src/graphics.h @@ -0,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: *** +*/
--- a/src/mex.cc +++ b/src/mex.cc @@ -27,6 +27,7 @@ #include "unwind-prot.h" #include "utils.h" #include "variables.h" +#include "graphics.h" // #define DEBUG 1 @@ -3294,11 +3295,14 @@ } const mxArray * -mexGet (double /*handle*/, const char */*property*/) +mexGet (double handle, const char *property) { - // FIXME - error ("mexGet: not implemented"); - return 0; + 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,11 +3345,12 @@ } int -mexSet (double /*handle*/, const char */*property*/, mxArray */*val*/) +mexSet (double handle, const char *property, mxArray *val) { - // FIXME - error ("mexSet: not implemented"); - return 0; + bool ret = + set_property_in_handle (handle, property, mxArray::as_octave_value (val), + "mexSet"); + return (ret ? 0 : 1); } void