[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: OOP load update
From: |
Robert T. Short |
Subject: |
Re: OOP load update |
Date: |
Tue, 05 May 2009 17:22:23 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.21) Gecko/20090402 SeaMonkey/1.1.16 |
John W. Eaton wrote:
On 5-May-2009, Robert T. Short wrote:
| MATLAB actually can reconstruct all of the
| fields of the underlying struct from the mat file, but it is not able to
| reconstruct inheritance from the mat file. Calling the constructor
| seems like a natural way to do it, but MATLAB doesn't seem to ever call
| the constructor when loading from a mat file.
Are you sure about that? Try creating and saving an object of a class
then make the constructor for that class unavailable in smoe way
(rename the @NAME directory that contains the constructor, for
example). Then restart Matlab and try loading the file. Does it
complain about not being able to find the constructor? Or that it
can't create the class, so it is converting it to a structure instead?
Not 100%, but reasonably. I haven't tried what you said, but I did (a)
put a breakpoint in the constructor and (b) put some output statement in
the constructor, and (c) making a constructor that failed without an
argument. None of these things happen. I have thought of some more
conclusive experiments and will try them.
I need to experiment more just to try to characterize this thing. Right
now octave works pretty much just like MATLAB. If you have a class
FooBar that has inheritance and do
> fubar=FooBar()
> save foobarfile fubar
> exit
(start {MATLAB,octave} again)
> load foobarfile
error: (some error message about not being able to do this)
but if you do
> FooBar()
> load foobarfile
everything works.
| In order to load a class with parent classes, you first need to
| instantiate an object from the class constructor and then load the mat
| file. This is now the way things work in octave, but I have been
| thinking about invoking the class constructor to fill in the class
| structure. As long as the constructor doesn't require arguments it
| should work, but I haven't really thought it out that far yet.
It should not be necessary to call the constructor unless an object of
the class has not yet been created at the point where you need to
know something about the class layout.
See the example above for what I meant. If you save a class in a file,
exit {MATLAB,octave} you have to instantiate an object before the load
will work. If I called the class constructor it would work fine, but if
the constructor HAD to have an argument, it would fail. Then you would
still have to instantiate an object. On the other hand, if there is
already an entry in the examplar table, there is no reason to do any of
the above. I think that is what I do - This makes me think that I had
best have another look, but I think this is what I do.
I think this is really quite a good approach and will probably play with
this.
Bob
--
Robert T. Short, Ph.D.
PhaseLocked Systems
- OOP load update, Robert T. Short, 2009/05/05
- OOP load update, John W. Eaton, 2009/05/05
- Re: OOP load update, Robert T. Short, 2009/05/05
- Re: OOP load update, WMennerich, 2009/05/05
- Re: OOP load update, Robert T. Short, 2009/05/05
- Re: OOP load update, John W. Eaton, 2009/05/05
- Re: OOP load update,
Robert T. Short <=
- Re: OOP load update, John W. Eaton, 2009/05/05
- Re: OOP load update, Judd Storrs, 2009/05/05
- Re: OOP load update, Judd Storrs, 2009/05/05