From maintainers-request at octave dot org Thu Nov 17 00:03:08 2005 Subject: Re: Octave_value class hierachy From: "John W. Eaton" To: octave-maintainers-list cc: Jens Ruecknagel Date: Thu, 17 Nov 2005 01:03:00 -0500 On 16-Nov-2005, John W. Eaton wrote: | We would need to make the following changes: | | * octave_value::rep becomes a pointer to octave_base_value instead of | octave_value | | * The octave_base_value class is no longer derived from octave_value. | | * All other value classes must be derived from octave_base_value (I | think this is already true, but it would become a requirement). | | * Functions in the octave_value class would not need to be declared | virtual, but the functions in octave_base_value would be virtual. | | * In addition to changing the type of octave_value::rep, we would | also have | | typedef octave_base_value * (*type_conv_fcn) (const octave_value&); | octave_value (octave_base_value *new_rep, int count = 1); | octave_base_value *clone (void) const; | octave_base_value *empty_clone (void) const; | octave_base_value *try_narrowing_conversion (void); | octave_base_value *internal_rep (void) const; | | in the octave_value class instead of | | typedef octave_value * (*type_conv_fcn) (const octave_value&); | octave_value (octave_value *new_rep, int count = 1); | virtual octave_value *clone (void) const; | virtual octave_value *empty_clone (void) const; | virtual octave_value *try_narrowing_conversion (void); | octave_value *internal_rep (void) const; | | and the nil_rep function could be moved to the octave_base_value | class. These changes would affect all derived types, but should | only require a change in the declaration, with no change in the | way the functions actually work. | | * There would be no need for the octave_xvalue struct (which is just | confusing anyway). | | * The rep could be assumed to always be non-null. | | * As Jens suggested, we could move count to the octave_base_value | class. OK, I spent some time making this change (not checked in yet; I may put it on a separate branch). It turned up some bugs (for example, inappropriately casting an octave_value object to a derived type) and some questionable design (the numeric_conversion_function method, for one). Changes needed in derived types are * The empty_clone, clone, try_narrowing_conversion functions return a pointer to octave_base_value instead of a pointer to octave_value. The body of the function will probably not need to change. * The type_conv_fcn typedef is now declared inside octave_base_value class, so numeric_conversion_function declaration must change. This may change * The type_conv_fcn typedef changes from octave_value* (*) (const octave_value& a) to octave_base_value* (*) (const octave_base_value& a) (this may change so that the derived classes simply attempt the conversion and return 0 if they are unable to do anything). * The int argument has been removed from the octave_value (octave_value *, int) constructor. You must increment the reference count (if needed) of the derived class, then construct the octave_value object. For example, in a derived class method, you can return an octave_value object containing a copy of the current object using count++; return octave_value (this); (this may change because it seems complex and likely to cause confusion and trouble). * The get_rep function now returns a reference to an octave_base_value object instead of a reference to an octave_value object. All uses must change. Perhaps with a little more cleaning up, this will be a good change to make. It would also be a good time to fully document the octave_value and octave_base_value classes and remove any unnecessary functions. jwe