octave-maintainers
[Top][All Lists]
Advanced

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

Re: How to use the OO features of Octave


From: John W. Eaton
Subject: Re: How to use the OO features of Octave
Date: Tue, 23 Sep 2008 13:53:17 -0400

On 23-Sep-2008, David Bateman wrote:

| John W. Eaton wrote:
| > On 23-Sep-2008, David Bateman wrote:
| >
| > | octave:14> ver
| > | ----------------------------------------------------------------------
| > | GNU Octave Version 3.1.51+
| > | GNU Octave License: GNU General Public License
| > | Operating System: Linux 2.6.22.19-laptop-2mdv #1 SMP Mon May 5 21:45:32 
| > | EDT 2008 x86_64
| > | ----------------------------------------------------------------------
| > | 
| > | So I'm use the tip as of yesterday. Maybe there is an issue of synchro 
| > | between our repositories.. What was the change that addressed this?
| >
| > I don't know precisely which change it was, but it would have been
| > related to the octave_call_stack mechanism in toplev.cc, and the way
| > it is used in functions like Fclass.
| >
| > jwe
| >
| >   
| Ok, I think I've found another bug. Attached is a toy galois field 
| GF(2^M) class that duplicates some of the features of the equivalent 
| octave-forge class. The subsref method has an issue in that
| 
| a = gf(0:3, 2);
| a(2:end)
| 
| returns nothing. The issue is that in the subsref method the s.subs 
| field is empty when it should contain (2:4). Doing
| 
| a(2:4)
| 
| however works correctly.

First, I think you'll need to provide a @gf/end.m method.  Something
like

  function r = end (obj, index_pos, num_indices)
    ## FIXME -- may want to check index_pos and num_indices and issue
    ## error message if out of range.
    r = numel (obj.x);
  endfunction

Second, Octave needs to handle dispatching for this function, so
something like the following patch is needed.

Thanks,

jwe

# HG changeset patch
# User John W. Eaton <address@hidden>
# Date 1222192154 14400
# Node ID 2b2ca62f8ab6616307125175b81a18e25bc9dce0
# Parent  170ff7258b31f28c791e105a36aaab3775d5948f
dispatch to user-defined end function for classes if one is defined

diff --git a/src/ChangeLog b/src/ChangeLog
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2008-09-23  John W. Eaton  <address@hidden>
+
+       * pt-arg-list.cc (F__end__): Dispatch to user-defined end
+       function for classes if one is defined.
+       * lex.l (is_keyword_token): Allow "end" as a functon name.
+
 2008-09-23  David Bateman  <address@hidden>
 
        * variables.cc (static octave_value do_who (int, const string_vector&,
diff --git a/src/lex.l b/src/lex.l
--- a/src/lex.l
+++ b/src/lex.l
@@ -1057,7 +1057,10 @@
          break;
 
        case end_kw:
-         if (lexer_flags.looking_at_object_index)
+         if (lexer_flags.looking_at_object_index
+             || (lexer_flags.defining_func
+                 && ! (lexer_flags.looking_at_return_list
+                       || lexer_flags.parsed_function_name)))
            return 0;
          else
            {
diff --git a/src/pt-arg-list.cc b/src/pt-arg-list.cc
--- a/src/pt-arg-list.cc
+++ b/src/pt-arg-list.cc
@@ -36,6 +36,7 @@
 #include "oct-obj.h"
 #include "ov.h"
 #include "ov-usr-fcn.h"
+#include "parse.h"
 #include "pt-arg-list.h"
 #include "pt-exp.h"
 #include "pt-pr-code.h"
@@ -103,6 +104,22 @@
 
   if (indexed_object)
     {
+      if (indexed_object->is_object ())
+       {
+         octave_value_list args;
+
+         args(2) = num_indices;
+         args(1) = index_position;
+         args(0) = *indexed_object;
+
+         std::string class_name = indexed_object->class_name ();
+
+         octave_value meth = symbol_table::find_method ("end", class_name);
+
+         if (meth.is_defined ())
+           return feval (meth.function_value (), args, 1);
+       }
+
       dim_vector dv = indexed_object->dims ();
       int ndims = dv.length ();
 

reply via email to

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