[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Class Objects Usage
From: |
David Bateman |
Subject: |
Re: Class Objects Usage |
Date: |
Tue, 08 Jul 2008 10:31:49 +0200 |
User-agent: |
Thunderbird 2.0.0.12 (X11/20080306) |
Hi Fred,
Its great that you are using this part of the Octave code. However, this
part of the code is recent and under active development. At this point I
think you'll need to wait till John come back online to answer any
questions about this code..
Regards
David
Fred Schuld wrote:
> I have compiled Octave from the latest 3.0.0+ source off HG with MSVC2005.
> Michael G has helped (thanks) with many questions I had with getting a
> successful build with MSVC2005.
>
> Anyways, I was interested in trying the support for class objects.
> Entering "help class" returns:
>
> -- Built-in Function: class (EXPR)
> -- Built-in Function: class (S, ID)
> Return the class of the expression EXPR, as a string or create a
> class object from the structure S with name ID.
>
>
> Using a simple example I create a file with filename "polynom.m" with
> the @file convention: current address@hidden
>
> Script code:
>
> % Polynom script
> function p = polynom(a)
> % Polynom constructor
> if nargin == 0
> p.c = [];
> p = class(p, 'polynom');
> elseif isa(a,'polynom')
> p = a;
> else
> p.c = a(:).';
> p = class(p, 'polynom');
> end
>
> If the polynom constructor is called with: p = Polynom([1 0 3])
>
> I get the following error:
>
> error: class: invalid call from outside class constructor
> error: evaluating assignment expression near line 11, column 6
>
> If I use the "methods" octave command: methods("polynom")
>
> It returns:
>
> Methods for class polynom:
>
> polynom
>
> Which is what I expect since it only has one method so far: the
> constructor.
>
>
> I looked at the code starting at line 967 in ov-class.cc:
>
> DEFUN (class, args, ,
> "-*- texinfo -*-\n\
> @deftypefn {Built-in Function} {} class (@var{expr})\n\
> @deftypefnx {Built-in Function} {} class (@var{s}, @var{id})\n\
> \n\
> Return the class of the expression @var{expr}, as a string or\n\
> create a class object from the structure @var{s} with name @var{id}.\n\
> @end deftypefn")
> {
> octave_value retval;
>
> int nargin = args.length ();
>
> if (nargin == 1)
> retval = args(0).class_name ();
> else if (nargin == 2)
> {
> Octave_map m = args(0).map_value ();
>
> if (! error_state)
> {
> std::string id = args(1).string_value ();
>
> if (! error_state)
> {
> octave_function *fcn = octave_call_stack::caller ();
>
> if (fcn && fcn->is_class_constructor ())
> retval = octave_value (new octave_class (m, id));
> else
> error ("class: invalid call from outside class constructor");
> ...
>
> I checked on the "is_class_constructor()" method and it is set to
> return FALSE on line 77 of ov-fcn.h:
>
> virtual bool is_class_constructor (void) const { return false; }
>
>
> Perhaps the "octave_class::in_class_method" would be better to call?
>
> In summary it looks like the code is configured to return the output
> "error: class: invalid call from outside class constructor" for all cases.
>
>
> Is this expected operation or is there something wrong with my example
> script use of class objects?
> ------------------------------------------------------------------------
> Use video conversation to talk face-to-face with Windows Live
> Messenger. Get started.
> <http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_video_072008>
--
David Bateman address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax)
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary