[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
improved get, set - to accept handle vectors
From: |
Kai Habel |
Subject: |
improved get, set - to accept handle vectors |
Date: |
Fri, 15 Jun 2007 18:58:39 +0000 |
User-agent: |
IceDove 1.5.0.10 (X11/20070329) |
Hello,
the following patch is supposed to allow handle-vectors as input
arguments for set and get.
Get returns in that case a cell array holding the property values. By
the way, what is the prefered way to construct a cell array. I am not
sure if the proposed patch uses the simplest way.
--- graphics.cc.orig 2007-06-14 22:24:05.000000000 +0000
+++ graphics.cc 2007-06-14 22:25:42.000000000 +0000
@@ -2129,8 +2125,8 @@
DEFUN (set, args, ,
"-*- texinfo -*-\n\
@deftypefn {Built-in Function} {} set (@var{h}, @var{p}, @var{v},
@dots{})\n\
-Set the named property @var{p} to the value @var{v} in the graphics\n\
-handle @var{h}.\n\
+Set the named property value or vector @var{p} to the value @var{v}\n\
+in the graphics handle @var{h}.\n\
@end deftypefn")
{
octave_value retval;
@@ -2139,23 +2135,26 @@
if (nargin > 0)
{
- double handle = args(0).double_value ();
+ ColumnVector hcv (args(0).vector_value());
if (! error_state)
- {
- graphics_object obj = gh_manager::get_object (handle);
-
- if (obj)
- {
- obj.set (args.splice (0, 1));
-
- feval ("__request_drawnow__");
- }
- else
- error ("set: invalid handle (= %g)", handle);
- }
+ {
+ for (octave_idx_type n = 0; n < hcv.length(); n++)
+ {
+ graphics_object obj = gh_manager::get_object (hcv(n));
+
+ if (obj)
+ {
+ obj.set (args.splice (0, 1));
+
+ feval ("__request_drawnow__");
+ }
+ else
+ error ("set: invalid handle (= %g)", hcv(n));
+ }
+ }
else
- error ("set: expecting graphics handle as first argument");
+ error ("set: expecting graphics handle as first argument");
}
else
print_usage ();
@@ -2168,43 +2167,56 @@
@deftypefn {Built-in Function} {} get (@var{h}, @var{p})\n\
Return the named property @var{p} from the graphics handle @var{h}.\n\
If @var{p} is omitted, return the complete property list for @var{h}.\n\
+If @var{h} is a vector, return a cell array including the property\n\
+values or lists respectively.\n\
@end deftypefn")
{
octave_value retval;
+ octave_value_list vlist;
int nargin = args.length ();
if (nargin == 1 || nargin == 2)
{
- double handle = args(0).double_value ();
-
+ ColumnVector hcv (args(0).vector_value());
if (! error_state)
- {
- graphics_object obj = gh_manager::get_object (handle);
-
- if (obj)
- {
- if (nargin == 1)
- retval = obj.get ();
- else
- {
- property_name property = args(1).string_value ();
-
- if (! error_state)
- retval = obj.get (property);
- else
- error ("get: expecting property name as second
argument");
- }
- }
- else
- error ("get: invalid handle (= %g)", handle);
- }
+ {
+ for (octave_idx_type n = 0; n < hcv.length(); n++)
+ {
+ graphics_object obj = gh_manager::get_object (hcv(n));
+
+ if (obj)
+ {
+ if (nargin == 1)
+ vlist(n) = obj.get ();
+ else
+ {
+ property_name property =
args(1).string_value ();
+
+ if (! error_state)
+ vlist(n) = obj.get (property);
+ else
+ error ("get: expecting property name as
second argument");
+ }
+ }
+ else
+ error ("get: invalid handle (= %g)", hcv(n));
+ }
+ }
else
- error ("get: expecting graphics handle as first argument");
+ error ("get: expecting graphics handle as first argument");
}
else
print_usage ();
+ if (vlist.length() > 1)
+ {
+ Cell c(vlist);
+ retval = c;
+ }
+ else
+ retval = vlist(0);
+
return retval;
}
- improved get, set - to accept handle vectors,
Kai Habel <=