octave-maintainers
[Top][All Lists]
Advanced

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

Re: [unclassified] patch for color_properties assignment


From: Kai Habel
Subject: Re: [unclassified] patch for color_properties assignment
Date: Sat, 01 Sep 2007 22:09:36 +0000
User-agent: IceDove 1.5.0.12 (X11/20070607)

kahacjde schrieb:
kahacjde wrote:
John W. Eaton schrieb:
I'm now confused about the patches in this thread and the "problem with radio values in color_property" thread. Which ones are
needed?  Am I missing any other patches for graphics?

Thanks,

jwe

I think there is still one problem unsolved. Here is the relevant part of the discussion
(http://www.nabble.com/patch-for-color_properties-assignment-tf4041176.html)

Another problem is the radio_values::validate method. In your patch you
check first for valid radio values:

          if (radio_val.validate (s))
+           {
+             current_val = s;
+             current_type = radio_t;
+           }
+           else
+           {
+             color_values col (s);
+             if (! error_state)
+               {
+                 color_val = col;
+                 current_type = color_t;
+               }
+             else
+               error ("invalid color specification");
+           }



but if 's' is a string color value (e.g. 'r' or 'red')  validate calls
the error function and sets the error flag. This causes an error message
and octave terminates. I have turned off the error call in
radio_values::validate for test purposes. Then the creation of a line
object with:
h=__go_line__ (gca);

works as expected.
I think the issue here is that validate raises an error. I will send a
patch which will overcome this (e,g, replace radio_val.validate (s)
with

radio_val.possible_vals.find (val) != radio_val.possible_vals.end ()
I have tried to replace "radio_val.validate (s)" with "radio_val.possible_vals.find (val) != radio_val.possible_vals.end ()" for the operator

color_property&
color_property::operator = (const octave_value& val)

(line 187 of graphics.cc), but this causes an compilation error:

g++ -c -fPIC -I. -I.. -I../liboctave -I../src -I../libcruft/misc -DHAVE_CONFIG_H -mieee-fp -Wall -W -Wshadow -Wold-style-cast -g -O2 graphics.cc -o pic/graphics.o graphics.h: In member function 'color_property& color_property::operator=(const octave_value&)': graphics.h:112: error: 'std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > radio_values::possible_vals' is private (Please note I use a modified graphics.h, the line 112 refers to std::set<std::string> possible_vals;)

I don't know if some 'friend' magic would help here. Another solution is to have an addtional radio_values::__validate__() function without this error() call.

I don't know how to proceed here, any suggestions?

Kai




O.k. I propose the following patches to make the color assigment work again.
As you might have noticed currently something like:
plot([0 1],'Color','blue') is not possible because "color_property::operator = (const octave_value& val)" is to restrictive.
If you look at the code of this operator (around line 179 of graphics.cc) if
's' is an string the assigment must fail because either "validate(s)" or
later "color_values col (s);" raise an error.
I have introduced a __validate__ function which just checks for valid
entries.

Here is the respective Changelog:

2007-09-01  Kai Habel  <address@hidden>

        * graphics.h (radio_values::__validate__): New function.
        * graphics.cc (color_property::operator =): Use __validate__ instead of
validate.

Kai

P.S. I send this email via nabble so I hope the attachments are correct.

http://www.nabble.com/file/p12443384/graphics.h.patch graphics.h.patch http://www.nabble.com/file/p12443384/graphics.cc.patch graphics.cc.patch
O.k. since the patches are not attached, I attach them here

Kai
--- graphics.cc.orig    2007-09-01 20:52:06.000000000 +0000
+++ graphics.cc 2007-09-01 20:52:58.000000000 +0000
@@ -184,7 +184,7 @@
 
       if (! s.empty ())
        {
-         if (radio_val.validate (s))
+         if (radio_val.__validate__ (s))
            {
              current_val = s;
              current_type = radio_t;
--- graphics.h.orig     2007-09-01 20:52:09.000000000 +0000
+++ graphics.h  2007-09-01 20:54:18.000000000 +0000
@@ -79,7 +79,7 @@
   {
     bool retval = true;
 
-    if (possible_vals.find (val) == possible_vals.end ())
+    if (!__validate__ (val))
       {
        error ("invalid value = %s", val.c_str ());
        retval = false;
@@ -87,6 +87,12 @@
 
     return retval;
   }
+  
+  bool __validate__ (const std::string& val)
+  {
+    return (possible_vals.find (val) != possible_vals.end ());
+  }
+
 
 private:
   // Might also want to cache

reply via email to

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