OOP load update

Robert T. Short octave at phaselockedsystems.com
Wed May 6 12:12:20 CDT 2009


Hmmm.  Seems that Judd is correct.  If the constructor is available and 
if it has no parameters, then the load works even if MATLAB doesn't have 
a current class structure.

Judd do you remember the attached emails?   The context was this: I had 
suggested that I should call the class constructor, John asked the 
question "what about constructors with parameters" so I went and played 
with it.  I need to remember what I did, but if you don't do things just 
right you get a nastygram like

Warning: Could not determine the fields for class Foo by calling the
         constructor with no input arguments.  The object a has been
         converted to a structure.  To eliminate the conversion create
         an object of class Foo before calling LOAD.

So, what were the conditions under which you got the message?



Whatever, I think this is pretty easy to fix and was already in the 
plan.  Basically the load algorithm goes like this

if there might be an inheritance issue then
  if there is no entry in the exemplar table then
     execute the class constructor to create an exemplar table entry
     if executing the class constructor failed, return the broken class

  use the exemplar table to reconstruct the inheritance
  if there is an inconsistency in the inheritance structure return the 
broken class

if there is no inheritance problem
  execute the user's loadobj method
  check the class for consistency with the exemplar table entry
  if inconsistent, return the broken class
  else return the class

The only difference between the above and what is done now is that I 
don't currently execute the class constructor.



MATLAB returns a struct, not the broken class but as of now I don't see 
how to return a struct without some kludge.  There is really no 
difference between the broken class and the correct class except a 
warning message and the fact that methods and inheritance may not work 
properly.  Once the struct(obj) function works properly the struct can 
be obtained from the broken class easily.  This isn't totally MATLAB 
compatible, but not bad, and fixing broken classes isn't something that 
is a normal activity.  The loadobj function is really designed to patch 
up inconsistencies between saved classes and the current class 
definitions.   I don't see any facilities in MATLAB for the loadobj 
function to fix inheritance issues, but I could make something like that 
in octave.

There are actually several items in the last set of emails that I need 
to absorb.  Hopefully this weekend....

Bob
--
Robert T. Short
PhaseLocked Systems
 


Judd Storrs wrote:
> I'm pretty sure the constructor is called if Matlab doesn't have a 
> class definition. Suppose:
>
> @FooBar/FooBar.m:
> function obj = FooBar()
>      disp('Hello!');
>      obj.data = 'Baz';
>      obj = class(obj, 'FooBar');
>
> Then at least in Matlab R14 (7.0.1) (I've edited whitespace):
>
> Matlab Session 1:
> >> obj1 = FooBar()
> Hello!
> obj1 = FooBar object: 1-by-1
> >> save('test.mat','obj1')
> >> obj2 = FooBar()        
> Hello!
> obj2 = FooBar object: 1-by-1
> >> save('test2.mat','obj2')
> >> exit
>
> Matlab Session 2:
> >> load test.mat
> Hello!
> >> load test2.mat
> >>
>
> As you see in the second session, matlab does execute the constructor 
> the first time it encounters the FooBar class, but once it knews the 
> class structure, it didn't need to call the constructor again.
>
> --judd
-------------- next part --------------
An embedded message was scrubbed...
From: Judd Storrs <storrsjm at email.uc.edu>
Subject: Re: OOP and load/save
Date: Thu, 23 Apr 2009 11:24:25 -0400
Size: 7391
Url: https://www-old.cae.wisc.edu/pipermail/octave-maintainers/attachments/20090506/311c0da1/attachment.eml 
-------------- next part --------------
An embedded message was scrubbed...
From: Judd Storrs <storrsjm at email.uc.edu>
Subject: Re: OOP and load/save
Date: Thu, 23 Apr 2009 11:46:23 -0400
Size: 4890
Url: https://www-old.cae.wisc.edu/pipermail/octave-maintainers/attachments/20090506/311c0da1/attachment-0001.eml 
-------------- next part --------------
An embedded message was scrubbed...
From: Judd Storrs <storrsjm at email.uc.edu>
Subject: Re: OOP and load/save
Date: Thu, 23 Apr 2009 12:01:54 -0400
Size: 8756
Url: https://www-old.cae.wisc.edu/pipermail/octave-maintainers/attachments/20090506/311c0da1/attachment-0002.eml 


More information about the Octave-maintainers mailing list