octave-maintainers
[Top][All Lists]
Advanced

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

Re: error function


From: Shai Ayal
Subject: Re: error function
Date: Tue, 15 May 2007 06:13:57 +0300

On 5/14/07, John W. Eaton <address@hidden> wrote:
On 14-May-2007, Shai Ayal wrote:

| I am trying to implement a color_property which can aslo have
| radio_values, i.e. it can be a rgb triplet or "auto" or "none".
|
| let's say I want to get the rgb value from the color_property. first I
| want to check that the value is not "auto". I thight of something
| along the lines of
|
|   const double* color_property::rgb (void) const
|   {
|     if (current_type != color)
|       error ("color has no rgb value");
|
|     return color.rgb ();
|   }
|
| where current_type determines if the color_property's value is a color
| or radio_value and color is the internal color_value object which has
| a rgb () method.
|
| so in a code using these properties, I would do:
|
| const double* lc = linecolor.rgb ();
| if (!error_state)
|   glColor3d(lc);
| ...
| this is similar to checking the input argument type in a DLD function.
| Does this seem OK?

If this error condition is a real error that you can't recover from,
then I think this approach is fine.  If it is something you can
recover from, then I think you need to find a way to avoid calling
the error function.

This is of course recoverable. How about using the approach taken by
octave_value when trying to extract a wrong type? The following code
is used in many places:

void somefunc ( octave_value& val)
        std::string c = val.string_value ();
        
        if (! error_state )

does octave_value set the error_state directly or does it call a function?

BTW, if the value is "auto" then shouldn't your rgb function compute
the RGB value and return a valid RGB triplet?  What is supposed to
happen if the value is "none"?


When the value is "none", then the relevant element shouldn't be drawn
at all -- an eample is line.markeredgecolor which can be none and than
the markers will ot have the edge drawn, only the face.
The "auto" value is a bit contrived -- an example doesn't spring to
mind, but it is conceiveable that then the color would have to be
computed based on the value of other properties as well, so it can't
be computed by the rgb function.

jwe



reply via email to

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