octave-maintainers
[Top][All Lists]
Advanced

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

Re: [unclassified] improved get, set - to accept handle vectors


From: Kai Habel
Subject: Re: [unclassified] improved get, set - to accept handle vectors
Date: Fri, 15 Jun 2007 19:50:34 +0000
User-agent: IceDove 1.5.0.10 (X11/20070329)

John W. Eaton schrieb:
On 15-Jun-2007, Kai Habel wrote:

| 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.

Can you please send your patch again as a text/plain attachment?  The
one you just sent arrived with lines wrapped.  Also, the indentation
seems a bit jumbled.  Are you using non-standard tab stops in your
editor?  If so, please turn that feature off when editing code for
Octave, or configure your editor to always insert the appropriate
number of spaces instead of TAB characters.

Thanks,

jwe


O.k. after setting tabstop to 8, I get the following patch. The indentation looks better now. Does this work for you?

Kai
--- graphics.cc.orig    2007-06-15 19:32:29.000000000 +0000
+++ graphics.cc 2007-06-15 19:37:00.000000000 +0000
@@ -2132,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;
@@ -2142,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 ();
@@ -2171,49 +2167,62 @@
 @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;
 }
 
 static octave_value
 make_graphics_object (const std::string& go_name,
-                     const octave_value_list& args)
+          const octave_value_list& args)
 {
   octave_value retval;
 

reply via email to

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