octave-maintainers
[Top][All Lists]
Advanced

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

Re: Octave_value class hierachy


From: Paul Thomas
Subject: Re: Octave_value class hierachy
Date: Sun, 02 May 2004 11:37:58 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225

Thanks for this correspondence, fellas. John's simplified examples came just in time, as I was trying to come to grips with the octave-value hierarchy. I wonder if the examples should be posted in the Wiki or some other indexed locatation?

Paul T

Jens Ruecknagel wrote:

Thanks for you answer.

your foo.cc is exactly what i was thinking about except one line:

diff foo.orig.cc foo.cc
32c32
<   value fun (void) const
---
>   virtual value fun (void) const

in foo you cannot do what you can do in bar:
value crash = type_one () ; // you know I cannot write "value crash( type_one())" because in c++ this is a forward declaration of a function crash

and in octave_value you can write:

octave_value crash (octave_scalar(1));

Because the of the union {count, rep} the copy constructor cannot find out whether it is a value or a base_value.

Or because of base_value : public value and base_value is NOT a value, value is just a a pointer to a base_value. Or maybe it is even a proxy [Gama, Helm, Johnson, Vlissidis, Design Patterns] to a base_value. If one wants, they may both (value and base_value) share the same interface: inherit both from the abstract class value_interface.

But what the big deal: octave_value works: just don't call functions of octave_base_value or its descendants. But it took me one week to find this out.


John W. Eaton wrote:

On 22-Apr-2004, Jens Ruecknagel <address@hidden> wrote:

| Why is count a attribute of octave_value? Why is ref  *octave_value?
| Shouldn't it be: count attribute of octave_base_value and | octave_value::ref* octave_base_value? | Wouldn't it be better to make octave_value the proxy class and | octave_base_value the referenced class? It is used this way anyway?
| | I'm just curios? Does anybody know the reason, I did not think of?

I think I followed the structure of the Number class hierarchy in
Coplien's "Advanced C++; Programming Styles and Idioms" book from
1992.  I must admit that at the time, that code seemed quite complex
to me, so probably I copied a lot more than I really understood.

Looking at the code now, I think the rep object must be a pointer to
an octave_value object so that the virtual functions in the
octave_value class work properly.

If you see another way to do this that is better, then please submit a
complete working example that demonstrates your ideas.  It can be
greatly simplified compared to the octave_value classes (for example,
just two derived types and one or two operations on them).  You could
start with the code in the first attachment below, and fix it so that
it works correctly.  Currently, both calls to the functions in main
end up in the methods of base_value class when only the one for
type_two should.  When you are done, I think you will probably end up
with something much like what is in the second attachment, which is a
simplified version of the current octave_value hierarchy.  But maybe
there is a simpler and better way that I'm not seeing.  In any case,
going through the exercise yourself will probably help you to
understand why things are the way they are.

jwe

------------------------------------------------------------------------








reply via email to

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