annotate libinterp/octave-value/ov-class.cc @ 20619:eef93a493ce3

use new cell_value method to handle value extraction errors * cellfun.cc, ov-class.cc, ov-struct.cc, ov-usr-fcn.cc: Use new cell_value method.
author John W. Eaton <jwe@octave.org>
date Fri, 09 Oct 2015 14:43:36 -0400
parents 729a85dafba8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1 /*
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19632
diff changeset
3 Copyright (C) 2007-2015 John W. Eaton
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
4 Copyright (C) 2009 VZLU Prague
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
5
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
7
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7444
1e1e2608da7b [project @ 2008-02-04 07:40:55 by jwe]
jwe
parents: 7338
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
1e1e2608da7b [project @ 2008-02-04 07:40:55 by jwe]
jwe
parents: 7338
diff changeset
11 option) any later version.
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
12
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
16 for more details.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
17
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7444
1e1e2608da7b [project @ 2008-02-04 07:40:55 by jwe]
jwe
parents: 7338
diff changeset
19 along with Octave; see the file COPYING. If not, see
1e1e2608da7b [project @ 2008-02-04 07:40:55 by jwe]
jwe
parents: 7338
diff changeset
20 <http://www.gnu.org/licenses/>.
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
21
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
22 */
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
23
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
26 #endif
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
27
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
28 #include <iostream>
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
29
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
30 #include "Array-util.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
31 #include "byte-swap.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8219
diff changeset
32 #include "oct-locbuf.h"
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
33 #include "lo-mappers.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
34
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
35 #include "Cell.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
36 #include "defun.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
37 #include "error.h"
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
38 #include "file-ops.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
39 #include "gripes.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
40 #include "load-path.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
41 #include "ls-hdf5.h"
20482
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20267
diff changeset
42 #include "ls-oct-text.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
43 #include "ls-oct-binary.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
44 #include "ls-utils.h"
15149
62a35ae7d6a2 use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents: 15057
diff changeset
45 #include "mxarray.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
46 #include "oct-lvalue.h"
19897
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
47 #include "oct-hdf5.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
48 #include "ov-class.h"
15812
83bf6fd9e46d ov-class.cc: Fix compilation when HAVE_JAVA is false.
Rik <rik@octave.org>
parents: 15811
diff changeset
49 #ifdef HAVE_JAVA
15811
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
50 #include "ov-java.h"
15812
83bf6fd9e46d ov-class.cc: Fix compilation when HAVE_JAVA is false.
Rik <rik@octave.org>
parents: 15811
diff changeset
51 #endif
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
52 #include "ov-fcn.h"
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
53 #include "ov-usr-fcn.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
54 #include "pager.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
55 #include "parse.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
56 #include "pr-output.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
57 #include "toplev.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
58 #include "unwind-prot.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
59 #include "variables.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
60
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
61
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
62 int octave_class::t_id (-1);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
63
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
64 const std::string octave_class::t_name ("class");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
65
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
66 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
67 octave_class::register_type (void)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
68 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
69 t_id = octave_value_typeinfo::register_type
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
70 (octave_class::t_name, "<unknown>",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
71 octave_value (new octave_class ()));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
72 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
73
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
74 octave_class::octave_class (const octave_map& m, const std::string& id,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
75 const octave_value_list& parents)
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
76 : octave_base_value (), map (m), c_name (id), obsolete_copies (0)
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
77 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
78 octave_idx_type n = parents.length ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
79
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
80 for (octave_idx_type idx = 0; idx < n; idx++)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
81 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
82 octave_value parent = parents(idx);
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
83
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
84 if (! parent.is_object ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
85 error ("parents must be objects");
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
86 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
87 {
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
88 std::string pcnm = parent.class_name ();
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
89
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
90 if (find_parent_class (pcnm))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
91 error ("duplicate class in parent tree");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
92 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
93 {
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
94 parent_list.push_back (pcnm);
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
95
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
96 octave_idx_type nel = map.numel ();
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
97 octave_idx_type p_nel = parent.numel ();
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
98
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
99 if (nel == 0)
13702
c7fac37a2afc class: correctly handle parents when structure array has more than one element
John W. Eaton <jwe@octave.org>
parents: 13695
diff changeset
100 {
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
101 if (p_nel == 0)
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
102 {
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
103 // No elements in MAP or the parent class object,
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
104 // so just add the field name.
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
105
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
106 map.assign (pcnm, Cell (map.dims ()));
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
107 }
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
108 else if (p_nel == 1)
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
109 {
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
110 if (map.nfields () == 0)
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
111 {
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
112 // No elements or fields in MAP, but the
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
113 // parent is class object with one element.
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
114 // Resize to match size of parent class and
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
115 // make the parent a field in MAP.
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
116
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
117 map.resize (parent.dims ());
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
118
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
119 map.assign (pcnm, parent);
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
120 }
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
121 else
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
122 {
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
123 // No elements in MAP, but we have at least
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
124 // one field. So don't resize, just add the
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
125 // field name.
13702
c7fac37a2afc class: correctly handle parents when structure array has more than one element
John W. Eaton <jwe@octave.org>
parents: 13695
diff changeset
126
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
127 map.assign (pcnm, Cell (map.dims ()));
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
128 }
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
129 }
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
130 else if (map.nfields () == 0)
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
131 {
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
132 // No elements or fields in MAP and more than one
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
133 // element in the parent class object, so we can
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
134 // resize MAP to match parent dimsenions, then
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
135 // distribute the elements of the parent object to
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
136 // the elements of MAP.
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
137
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
138 dim_vector parent_dims = parent.dims ();
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
139
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
140 map.resize (parent_dims);
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
141
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
142 Cell c (parent_dims);
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
143
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
144 octave_map pmap = parent.map_value ();
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
145
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
146 std::list<std::string> plist
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
147 = parent.parent_class_name_list ();
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
148
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
149 for (octave_idx_type i = 0; i < p_nel; i++)
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
150 c(i) = octave_value (pmap.index (i), pcnm, plist);
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
151
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
152 map.assign (pcnm, c);
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
153 }
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
154 else
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
155 error ("class: parent class dimension mismatch");
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
156 }
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
157 else if (nel == 1 && p_nel == 1)
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
158 {
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
159 // Simple assignment.
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
160
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
161 map.assign (pcnm, parent);
13702
c7fac37a2afc class: correctly handle parents when structure array has more than one element
John W. Eaton <jwe@octave.org>
parents: 13695
diff changeset
162 }
c7fac37a2afc class: correctly handle parents when structure array has more than one element
John W. Eaton <jwe@octave.org>
parents: 13695
diff changeset
163 else
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
164 {
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
165 if (p_nel == 1)
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
166 {
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
167 // Broadcast the scalar parent class object to
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
168 // each element of MAP.
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
169
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
170 Cell pcell (map.dims (), parent);
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
171
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
172 map.assign (pcnm, pcell);
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
173 }
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
174
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
175 else if (nel == p_nel)
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
176 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
177 // FIXME: is there a better way to do this?
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
178
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
179 // The parent class object has the same number of
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
180 // elements as the map we are using to create the
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
181 // new object, so distribute those elements to
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
182 // each element of the new object by first
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
183 // splitting the elements of the parent class
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
184 // object into a cell array with one element per
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
185 // cell. Then do the assignment all at once.
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
186
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
187 Cell c (parent.dims ());
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
188
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
189 octave_map pmap = parent.map_value ();
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
190
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
191 std::list<std::string> plist
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
192 = parent.parent_class_name_list ();
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
193
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
194 for (octave_idx_type i = 0; i < p_nel; i++)
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
195 c(i) = octave_value (pmap.index (i), pcnm, plist);
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
196
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
197 map.assign (pcnm, c);
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
198 }
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
199 else
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
200 error ("class: parent class dimension mismatch");
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
201 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
202 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
203 }
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
204 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
205
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
206 symbol_table::add_to_parent_map (id, parent_list);
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
207 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
208
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
209 octave_base_value *
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
210 octave_class::unique_clone (void)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
211 {
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
212 if (count == obsolete_copies)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
213 {
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
214 // All remaining copies are obsolete. We don't actually need to clone.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
215 count++;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
216 return this;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
217 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
218 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
219 {
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
220 // In theory, this shouldn't be happening, but it's here just in case.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
221 if (count < obsolete_copies)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
222 obsolete_copies = 0;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
223
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
224 return clone ();
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
225 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
226 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
227
10926
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
228 std::string
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
229 octave_class::get_current_method_class (void)
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
230 {
10926
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
231 std::string retval = class_name ();
9156
b2b8ed43b922 ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents: 9151
diff changeset
232
12620
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
233 if (nparents () > 0)
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
234 {
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
235 octave_function *fcn = octave_call_stack::current ();
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
236
12620
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
237 // Here we are just looking to see if FCN is a method or constructor
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
238 // for any class, not specifically this one.
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
239 if (fcn && (fcn->is_class_method () || fcn->is_class_constructor ()))
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
240 retval = fcn->dispatch_class ();
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
241 }
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
242
9156
b2b8ed43b922 ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents: 9151
diff changeset
243 return retval;
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
244 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
245
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
246 static void
10370
9c4daf174387 implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
247 gripe_invalid_index1 (void)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
248 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
249 error ("invalid index for class");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
250 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
251
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
252 static void
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
253 gripe_invalid_index_for_assignment (void)
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
254 {
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
255 error ("invalid index for class assignment");
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
256 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
257
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
258 static void
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
259 gripe_invalid_index_type (const std::string& nm, char t)
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
260 {
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
261 error ("%s cannot be indexed with %c", nm.c_str (), t);
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
262 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
263
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
264 static void
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
265 gripe_failed_assignment (void)
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
266 {
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
267 error ("assignment to class element failed");
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
268 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
269
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
270 Cell
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
271 octave_class::dotref (const octave_value_list& idx)
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
272 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
273 Cell retval;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
274
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
275 assert (idx.length () == 1);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
276
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
277 std::string method_class = get_current_method_class ();
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
278
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
279 // Find the class in which this method resides before attempting to access
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
280 // the requested field.
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
281
10926
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
282 octave_base_value *obvp = find_parent_class (method_class);
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
283
10926
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
284 if (obvp == 0)
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
285 {
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
286 error ("malformed class");
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
287 return retval;
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
288 }
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
289
10932
3a778233e4fb fix typo in 10926:f687bd17ce21
Jaroslav Hajek <highegg@gmail.com>
parents: 10926
diff changeset
290 octave_map my_map = (obvp != this) ? obvp->map_value () : map;
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
291
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
292 std::string nm = idx(0).string_value ();
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
293
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
294 if (! error_state)
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
295 {
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
296 octave_map::const_iterator p = my_map.seek (nm);
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
297
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
298 if (p != my_map.end ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
299 retval = my_map.contents (p);
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
300 else
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
301 error ("class has no member '%s'", nm.c_str ());
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
302 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
303 else
10370
9c4daf174387 implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
304 gripe_invalid_index1 ();
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
305
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
306 return retval;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
307 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
308
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
309 Matrix
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
310 octave_class::size (void)
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
311 {
9792
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
312 if (in_class_method () || called_from_builtin ())
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
313 return octave_base_value::size ();
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
314
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
315 Matrix retval (1, 2, 1.0);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
316 octave_value meth = symbol_table::find_method ("size", class_name ());
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
317
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
318 if (meth.is_defined ())
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
319 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
320 count++;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
321 octave_value_list args (1, octave_value (this));
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
322
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
323 octave_value_list lv = feval (meth.function_value (), args, 1);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
324 if (lv.length () > 0
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
325 && lv(0).is_matrix_type () && lv(0).dims ().is_vector ())
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
326 retval = lv(0).matrix_value ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
327 else
9775
9d9f858849c7 Allow and ignore extra outargs from user-defined size methods
David Grundberg <davidg@cs.umu.se>
parents: 9774
diff changeset
328 error ("@%s/size: invalid return value", class_name ().c_str ());
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
329 }
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
330 else
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
331 {
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
332 dim_vector dv = dims ();
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
333
13784
0bbe319bf26b octave_class::size: return matrix with correct dimensions
John W. Eaton <jwe@octave.org>
parents: 13781
diff changeset
334 int nd = dv.length ();
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
335
13784
0bbe319bf26b octave_class::size: return matrix with correct dimensions
John W. Eaton <jwe@octave.org>
parents: 13781
diff changeset
336 retval.resize (1, nd);
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
337
13784
0bbe319bf26b octave_class::size: return matrix with correct dimensions
John W. Eaton <jwe@octave.org>
parents: 13781
diff changeset
338 for (int i = 0; i < nd; i++)
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
339 retval(i) = dv(i);
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
340 }
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
341
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
342 return retval;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
343 }
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
344
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
345 octave_idx_type
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
346 octave_class::numel (const octave_value_list& idx)
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
347 {
9792
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
348 if (in_class_method () || called_from_builtin ())
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
349 return octave_base_value::numel (idx);
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
350
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
351 octave_idx_type retval = -1;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
352 const std::string cn = class_name ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
353
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
354 octave_value meth = symbol_table::find_method ("numel", cn);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
355
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
356 if (meth.is_defined ())
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
357 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
358 octave_value_list args (idx.length () + 1, octave_value ());
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
359
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
360 count++;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
361 args(0) = octave_value (this);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
362
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
363 for (octave_idx_type i = 0; i < idx.length (); i++)
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
364 args(i+1) = idx(i);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
365
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
366 octave_value_list lv = feval (meth.function_value (), args, 1);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
367 if (lv.length () == 1 && lv(0).is_scalar_type ())
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
368 retval = lv(0).idx_type_value (true);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
369 else
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
370 error ("@%s/numel: invalid return value", cn.c_str ());
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
371 }
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
372 else
10106
edbe47bc0f88 make numel query more matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
373 retval = octave_base_value::numel (idx);
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
374
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
375 return retval;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
376 }
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
377
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
378 octave_value_list
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
379 octave_class::subsref (const std::string& type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
380 const std::list<octave_value_list>& idx,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
381 int nargout)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
382 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
383 octave_value_list retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
384
9156
b2b8ed43b922 ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents: 9151
diff changeset
385 if (in_class_method () || called_from_builtin ())
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
386 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
387 // FIXME: this block of code is the same as the body of
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
388 // octave_struct::subsref. Maybe it could be shared instead of
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
389 // duplicated.
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
390
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
391 int skip = 1;
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
392
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
393 switch (type[0])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
394 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
395 case '(':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
396 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
397 if (type.length () > 1 && type[1] == '.')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
398 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
399 std::list<octave_value_list>::const_iterator p = idx.begin ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
400 octave_value_list key_idx = *++p;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
401
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
402 Cell tmp = dotref (key_idx);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
403
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
404 Cell t = tmp.index (idx.front ());
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
405
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
406 retval(0) = (t.numel () == 1) ? t(0)
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
407 : octave_value (t, true);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
408
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
409 // We handled two index elements, so tell
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
410 // next_subsref to skip both of them.
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
411
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
412 skip++;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
413 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
414 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
415 retval(0) = octave_value (map.index (idx.front ()),
13874
c1b754d93572 copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents: 13784
diff changeset
416 c_name, parent_list);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
417 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
418 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
419
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
420 case '.':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
421 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
422 if (map.numel () > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
423 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
424 Cell t = dotref (idx.front ());
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
425
20267
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20198
diff changeset
426 retval(0) = (t.numel () == 1) ? t(0) : octave_value (t, true);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
427 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
428 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
429 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
430
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
431 case '{':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
432 gripe_invalid_index_type (type_name (), type[0]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
433 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
434
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
435 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
436 panic_impossible ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
437 }
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
438
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
439 // FIXME: perhaps there should be an
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
440 // octave_value_list::next_subsref member function? See also
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
441 // octave_user_function::subsref.
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
442
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
443 if (idx.size () > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
444 retval = retval(0).next_subsref (nargout, type, idx, skip);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
445 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
446 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
447 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
448 octave_value meth = symbol_table::find_method ("subsref", class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
449
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
450 if (meth.is_defined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
451 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
452 octave_value_list args;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
453
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
454 args(1) = make_idx_args (type, idx, "subsref");
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
455
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
456 count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
457 args(0) = octave_value (this);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
458
9691
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
459 // FIXME: for Matlab compatibility, let us attempt to set up a proper
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
460 // value for nargout at least in the simple case where the
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
461 // cs-list-type expression - i.e., {} or ().x, is the leading one.
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
462 // Note that Octave does not actually need this, since it will
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
463 // be able to properly react to varargout a posteriori.
9331
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
464 bool maybe_cs_list_query = (type[0] == '.' || type[0] == '{'
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
465 || (type.length () > 1 && type[0] == '('
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
466 && type[1] == '.'));
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
467
9691
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
468 int true_nargout = nargout;
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
469
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
470 if (maybe_cs_list_query)
9331
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
471 {
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
472 // Set up a proper nargout for the subsref call by calling numel.
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
473 octave_value_list tmp;
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
474 if (type[0] != '.') tmp = idx.front ();
9691
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
475 true_nargout = numel (tmp);
9331
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
476 }
9691
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
477
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
478 retval = feval (meth.function_value (), args, true_nargout);
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
479
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
480 // Since we're handling subsref, return the list in the first value
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
481 // if it has more than one element, to be able to pass through
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
482 // rvalue1 calls.
9691
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
483 if (retval.length () > 1)
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
484 retval = octave_value (retval, true);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
485 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
486 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
487 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
488 if (type.length () == 1 && type[0] == '(')
13874
c1b754d93572 copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents: 13784
diff changeset
489 retval(0) = octave_value (map.index (idx.front ()), c_name,
c1b754d93572 copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents: 13784
diff changeset
490 parent_list);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
491 else
10370
9c4daf174387 implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
492 gripe_invalid_index1 ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
493 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
494 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
495
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
496 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
497 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
498
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
499 octave_value
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
500 octave_class::numeric_conv (const Cell& val, const std::string& type)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
501 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
502 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
503
20267
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20198
diff changeset
504 if (val.numel () == 1)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
505 {
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
506 retval = val(0);
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
507
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
508 if (type.length () > 0 && type[0] == '.' && ! retval.is_map ())
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
509 retval = octave_map ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
510 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
511 else
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
512 gripe_invalid_index_for_assignment ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
513
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
514 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
515 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
516
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
517 octave_value
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
518 octave_class::subsasgn (const std::string& type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
519 const std::list<octave_value_list>& idx,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
520 const octave_value& rhs)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
521 {
12171
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
522 count++;
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
523 return subsasgn_common (octave_value (this), type, idx, rhs);
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
524 }
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
525
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
526 octave_value
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
527 octave_class::undef_subsasgn (const std::string& type,
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
528 const std::list<octave_value_list>& idx,
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
529 const octave_value& rhs)
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
530 {
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
531 // For compatibility with Matlab, pass [] as the first argument to the
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
532 // the subsasgn function when the LHS of an indexed assignment is
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
533 // undefined.
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
534
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
535 return subsasgn_common (Matrix (), type, idx, rhs);
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
536 }
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
537
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
538 octave_value
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
539 octave_class::subsasgn_common (const octave_value& obj,
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
540 const std::string& type,
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
541 const std::list<octave_value_list>& idx,
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
542 const octave_value& rhs)
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
543 {
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
544 octave_value retval;
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
545
9156
b2b8ed43b922 ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents: 9151
diff changeset
546 if (! (in_class_method () || called_from_builtin ()))
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
547 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
548 octave_value meth = symbol_table::find_method ("subsasgn", class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
549
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
550 if (meth.is_defined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
551 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
552 octave_value_list args;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
553
9333
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
554 if (rhs.is_cs_list ())
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
555 {
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
556 octave_value_list lrhs = rhs.list_value ();
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
557 args.resize (2 + lrhs.length ());
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
558 for (octave_idx_type i = 0; i < lrhs.length (); i++)
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
559 args(2+i) = lrhs(i);
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
560 }
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
561 else
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
562 args(2) = rhs;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
563
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
564 args(1) = make_idx_args (type, idx, "subsasgn");
12171
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
565 args(0) = obj;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
566
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
567 // Now comes the magic. Count copies with me:
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
568 // 1. myself (obsolete)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
569 // 2. the copy inside args (obsolete)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
570 // 3. the copy in method's symbol table (working)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
571 // ... possibly more (not obsolete).
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
572 //
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
573 // So we mark 2 copies as obsolete and hold our fingers crossed.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
574 // But prior to doing that, check whether the routine is amenable
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
575 // to the optimization.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
576 // It is essential that the handling function doesn't store extra
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
577 // copies anywhere. If it does, things will not break but the
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
578 // optimization won't work.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
579
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
580 octave_value_list tmp;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
581
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
582 if (obsolete_copies == 0 && meth.is_user_function ()
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
583 && meth.user_function_value ()->subsasgn_optimization_ok ())
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
584 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
585 unwind_protect frame;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
586 frame.protect_var (obsolete_copies);
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
587 obsolete_copies = 2;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
588
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
589 tmp = feval (meth.function_value (), args);
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
590 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
591 else
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
592 tmp = feval (meth.function_value (), args);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
593
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
594 // FIXME: should the subsasgn method be able to return
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
595 // more than one value?
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
596
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
597 if (tmp.length () > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
598 error ("expecting single return value from @%s/subsasgn",
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
599 class_name ().c_str ());
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
600
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
601 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
602 retval = tmp(0);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
603
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
604 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
605 }
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
606 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
607
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
608 // Find the class in which this method resides before
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
609 // attempting to do the indexed assignment.
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
610
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
611 std::string method_class = get_current_method_class ();
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
612
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
613 octave_base_value *obvp = unique_parent_class (method_class);
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
614 if (obvp != this)
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
615 {
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
616
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
617 if (obvp)
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
618 {
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
619 obvp->subsasgn (type, idx, rhs);
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
620
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
621 if (! error_state)
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
622 {
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
623 count++;
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
624 retval = octave_value (this);
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
625 }
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
626 else
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
627 gripe_failed_assignment ();
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
628 }
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
629 else
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
630 error ("malformed class");
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
631
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
632 return retval;
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
633 }
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
634
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
635 // FIXME: this block of code is the same as the body of
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
636 // octave_struct::subsasgn. Maybe it could be shared instead of
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
637 // duplicated.
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
638
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
639 int n = type.length ();
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
640
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
641 octave_value t_rhs = rhs;
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
642
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
643 if (n > 1 && ! (type.length () == 2 && type[0] == '(' && type[1] == '.'))
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
644 {
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
645 switch (type[0])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
646 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
647 case '(':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
648 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
649 if (type.length () > 1 && type[1] == '.')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
650 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
651 std::list<octave_value_list>::const_iterator p = idx.begin ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
652 octave_value_list t_idx = *p;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
653
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
654 octave_value_list key_idx = *++p;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
655
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
656 assert (key_idx.length () == 1);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
657
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
658 std::string key = key_idx(0).string_value ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
659
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
660 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
661 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
662 octave_value u;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
663
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
664 if (! map.contains (key))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
665 u = octave_value::empty_conv (type.substr (2), rhs);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
666 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
667 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
668 Cell map_val = map.contents (key);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
669
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
670 Cell map_elt = map_val.index (idx.front (), true);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
671
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
672 u = numeric_conv (map_elt, type.substr (2));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
673 }
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
674
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
675 std::list<octave_value_list> next_idx (idx);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
676
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
677 // We handled two index elements, so subsasgn to
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
678 // needs to skip both of them.
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
679
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
680 next_idx.erase (next_idx.begin ());
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
681 next_idx.erase (next_idx.begin ());
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
682
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
683 u.make_unique ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
684
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
685 t_rhs = u.subsasgn (type.substr (2), next_idx, rhs);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
686 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
687 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
688 gripe_invalid_index_for_assignment ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
689 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
690 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
691 gripe_invalid_index_for_assignment ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
692 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
693 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
694
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
695 case '.':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
696 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
697 octave_value_list key_idx = idx.front ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
698
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
699 assert (key_idx.length () == 1);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
700
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
701 std::string key = key_idx(0).string_value ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
702
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
703 std::list<octave_value_list> next_idx (idx);
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
704
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
705 next_idx.erase (next_idx.begin ());
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
706
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
707 std::string next_type = type.substr (1);
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
708
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
709 Cell tmpc (1, 1);
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
710 octave_map::iterator pkey = map.seek (key);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
711 if (pkey != map.end ())
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
712 {
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
713 map.contents (pkey).make_unique ();
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
714 tmpc = map.contents (pkey);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
715 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
716
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
717 // FIXME: better code reuse?
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
718 if (tmpc.numel () == 1)
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
719 {
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
720 octave_value& tmp = tmpc(0);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
721
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
722 if (! tmp.is_defined () || tmp.is_zero_by_zero ())
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
723 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
724 tmp = octave_value::empty_conv (next_type, rhs);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
725 tmp.make_unique (); // probably a no-op.
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
726 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
727 else
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
728 // optimization: ignore copy still stored inside our map.
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
729 tmp.make_unique (1);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
730
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
731 t_rhs = tmp.subsasgn (next_type, next_idx, rhs);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
732 }
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
733 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
734 gripe_indexed_cs_list ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
735 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
736 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
737
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
738 case '{':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
739 gripe_invalid_index_type (type_name (), type[0]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
740 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
741
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
742 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
743 panic_impossible ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
744 }
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
745 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
746
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
747 if (! error_state)
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
748 {
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
749 switch (type[0])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
750 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
751 case '(':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
752 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
753 if (n > 1 && type[1] == '.')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
754 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
755 std::list<octave_value_list>::const_iterator p = idx.begin ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
756 octave_value_list key_idx = *++p;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
757
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
758 assert (key_idx.length () == 1);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
759
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
760 std::string key = key_idx(0).string_value ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
761
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
762 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
763 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
764 map.assign (idx.front (), key, t_rhs);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
765
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
766 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
767 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
768 count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
769 retval = octave_value (this);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
770 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
771 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
772 gripe_failed_assignment ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
773 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
774 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
775 gripe_failed_assignment ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
776 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
777 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
778 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
779 if (t_rhs.is_object () || t_rhs.is_map ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
780 {
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
781 octave_map rhs_map = t_rhs.map_value ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
782
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
783 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
784 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
785 map.assign (idx.front (), rhs_map);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
786
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
787 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
788 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
789 count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
790 retval = octave_value (this);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
791 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
792 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
793 gripe_failed_assignment ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
794 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
795 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
796 error ("invalid class assignment");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
797 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
798 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
799 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
800 if (t_rhs.is_empty ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
801 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
802 map.delete_elements (idx.front ());
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
803
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
804 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
805 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
806 count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
807 retval = octave_value (this);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
808 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
809 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
810 gripe_failed_assignment ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
811 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
812 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
813 error ("invalid class assignment");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
814 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
815 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
816 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
817 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
818
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
819 case '.':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
820 {
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
821 octave_value_list key_idx = idx.front ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
822
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
823 assert (key_idx.length () == 1);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
824
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
825 std::string key = key_idx(0).string_value ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
826
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
827 if (t_rhs.is_cs_list ())
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
828 {
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
829 Cell tmp_cell = Cell (t_rhs.list_value ());
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
830
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
831 // The shape of the RHS is irrelevant, we just want
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
832 // the number of elements to agree and to preserve the
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
833 // shape of the left hand side of the assignment.
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
834
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
835 if (numel () == tmp_cell.numel ())
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
836 tmp_cell = tmp_cell.reshape (dims ());
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
837
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
838 map.setfield (key, tmp_cell);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
839 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
840 else
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
841 {
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
842 Cell tmp_cell(1, 1);
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
843 tmp_cell(0) = t_rhs.storable_value ();
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
844 map.setfield (key, tmp_cell);
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
845 }
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
846
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
847 if (! error_state)
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
848 {
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
849 count++;
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
850 retval = octave_value (this);
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
851 }
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
852 else
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
853 gripe_failed_assignment ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
854 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
855 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
856
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
857 case '{':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
858 gripe_invalid_index_type (type_name (), type[0]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
859 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
860
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
861 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
862 panic_impossible ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
863 }
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
864 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
865 else
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
866 gripe_failed_assignment ();
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
867
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
868 return retval;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
869 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
870
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
871 idx_vector
18129
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 18033
diff changeset
872 octave_class::index_vector (bool require_integers) const
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
873 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
874 idx_vector retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
875
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
876 octave_value meth = symbol_table::find_method ("subsindex", class_name ());
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
877
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
878 if (meth.is_defined ())
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
879 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
880 octave_value_list args;
13874
c1b754d93572 copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents: 13784
diff changeset
881 args(0) = octave_value (new octave_class (map, c_name, parent_list));
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
882
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
883 octave_value_list tmp = feval (meth.function_value (), args, 1);
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
884
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
885 if (tmp(0).is_object ())
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
886 error ("subsindex function must return a valid index vector");
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
887 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
888 // Index vector returned by subsindex is zero based
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
889 // (why this inconsistency Mathworks?), and so we must
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
890 // add one to the value returned as the index_vector method
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
891 // expects it to be one based.
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
892 retval = do_binary_op (octave_value::op_add, tmp (0),
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
893 octave_value (1.0)).index_vector (require_integers);
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
894 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
895 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
896 error ("no subsindex method defined for class %s",
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
897 class_name ().c_str ());
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
898
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
899 return retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
900 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
901
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
902 size_t
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
903 octave_class::byte_size (void) const
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
904 {
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
905 // Neglect the size of the fieldnames.
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
906
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
907 size_t retval = 0;
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
908
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
909 for (octave_map::const_iterator p = map.begin (); p != map.end (); p++)
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
910 {
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
911 std::string key = map.key (p);
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
912
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
913 octave_value val = octave_value (map.contents (p));
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
914
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
915 retval += val.byte_size ();
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
916 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
917
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
918 return retval;
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
919 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
920
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
921 string_vector
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
922 octave_class::map_keys (void) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
923 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
924 string_vector retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
925 gripe_wrong_type_arg ("octave_class::map_keys()", type_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
926 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
927 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
928
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
929 octave_base_value *
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
930 octave_class::find_parent_class (const std::string& parent_class_name)
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
931 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
932 octave_base_value* retval = 0;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
933
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
934 if (parent_class_name == class_name ())
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
935 retval = this;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
936 else
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
937 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
938 for (std::list<std::string>::iterator pit = parent_list.begin ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
939 pit != parent_list.end ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
940 pit++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
941 {
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
942 octave_map::const_iterator smap = map.seek (*pit);
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
943
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
944 const Cell& tmp = map.contents (smap);
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
945
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
946 octave_value vtmp = tmp(0);
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
947
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
948 octave_base_value *obvp = vtmp.internal_rep ();
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
949
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
950 retval = obvp->find_parent_class (parent_class_name);
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
951
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
952 if (retval)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
953 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
954 }
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
955 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
956
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
957 return retval;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
958 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
959
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
960 octave_base_value *
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
961 octave_class::unique_parent_class (const std::string& parent_class_name)
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
962 {
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
963 octave_base_value* retval = 0;
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
964
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
965 if (parent_class_name == class_name ())
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
966 retval = this;
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
967 else
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
968 {
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
969 for (std::list<std::string>::iterator pit = parent_list.begin ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
970 pit != parent_list.end ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
971 pit++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
972 {
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
973 octave_map::iterator smap = map.seek (*pit);
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
974
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
975 Cell& tmp = map.contents (smap);
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
976
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
977 octave_value& vtmp = tmp(0);
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
978
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
979 octave_base_value *obvp = vtmp.internal_rep ();
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
980
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
981 // Use find_parent_class first to avoid uniquifying if not necessary.
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
982 retval = obvp->find_parent_class (parent_class_name);
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
983
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
984 if (retval)
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
985 {
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
986 vtmp.make_unique ();
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
987 obvp = vtmp.internal_rep ();
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
988 retval = obvp->unique_parent_class (parent_class_name);
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
989
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
990 break;
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
991 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
992 }
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
993 }
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
994
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
995 return retval;
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
996 }
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
997
19137
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
998 bool
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
999 octave_class::is_instance_of (const std::string& cls_name) const
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1000 {
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1001 bool retval = false;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1002
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1003 if (cls_name == class_name ())
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1004 retval = true;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1005 else
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1006 {
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1007 for (std::list<std::string>::const_iterator pit = parent_list.begin ();
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1008 pit != parent_list.end ();
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1009 pit++)
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1010 {
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1011 octave_map::const_iterator smap = map.seek (*pit);
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1012
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1013 const Cell& tmp = map.contents (smap);
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1014
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1015 const octave_value& vtmp = tmp(0);
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1016
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1017 retval = vtmp.is_instance_of (cls_name);
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1018
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1019 if (retval)
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1020 break;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1021 }
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1022 }
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1023
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1024 return retval;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1025 }
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18915
diff changeset
1026
13694
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1027 string_vector
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1028 octave_class::all_strings (bool pad) const
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1029 {
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1030 string_vector retval;
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1031
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1032 octave_value meth = symbol_table::find_method ("char", class_name ());
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1033
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1034 if (meth.is_defined ())
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1035 {
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1036 octave_value_list args;
13874
c1b754d93572 copy parent class info when performing operations on class objects
John W. Eaton <jwe@octave.org>
parents: 13784
diff changeset
1037 args(0) = octave_value (new octave_class (map, c_name, parent_list));
13694
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1038
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1039 octave_value_list tmp = feval (meth.function_value (), args, 1);
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1040
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
1041 if (tmp.length () >= 1)
13694
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1042 {
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1043 if (tmp(0).is_string ())
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1044 retval = tmp(0).all_strings (pad);
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1045 else
19437
03067dab10ca Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents: 19137
diff changeset
1046 error ("cname/char method did not return a string");
13694
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1047 }
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1048 }
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1049 else
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1050 error ("no char method defined for class %s", class_name ().c_str ());
13694
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1051
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1052 return retval;
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1053 }
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1054
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1055
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1056 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18409
diff changeset
1057 octave_class::print (std::ostream& os, bool)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1058 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1059 print_raw (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1060 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1061
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1062 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1063 octave_class::print_raw (std::ostream& os, bool) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1064 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
1065 unwind_protect frame;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1066
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1067 indent (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1068 os << " <class " << class_name () << ">";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1069 newline (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1070 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1071
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1072 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1073 octave_class::print_name_tag (std::ostream& os, const std::string& name) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1074 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1075 bool retval = false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1076
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1077 indent (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1078 os << name << " =";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1079 newline (os);
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12620
diff changeset
1080 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12620
diff changeset
1081 newline (os);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1082
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1083 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1084 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1085
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1086 void
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1087 octave_class::print_with_name (std::ostream& os, const std::string& name,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1088 bool)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1089 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
1090 octave_value fcn = symbol_table::find_method ("display", class_name ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1091
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
1092 if (fcn.is_defined ())
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
1093 {
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
1094 octave_value_list args;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1095
9521
e08d72bb988e simplify cloning
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
1096 count++;
e08d72bb988e simplify cloning
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
1097 args(0) = octave_value (this);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1098
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
1099 string_vector arg_names (1);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1100
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
1101 arg_names[0] = name;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1102
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
1103 args.stash_name_tags (arg_names);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1104
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
1105 feval (fcn.function_value (), args);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1106 }
10204
1d430a849f3c print class name for classes that don't define a display method
jstorrs@gmail.com
parents: 10160
diff changeset
1107 else
1d430a849f3c print class name for classes that don't define a display method
jstorrs@gmail.com
parents: 10160
diff changeset
1108 {
1d430a849f3c print class name for classes that don't define a display method
jstorrs@gmail.com
parents: 10160
diff changeset
1109 indent (os);
1d430a849f3c print class name for classes that don't define a display method
jstorrs@gmail.com
parents: 10160
diff changeset
1110 os << name << " = <class " << class_name () << ">";
1d430a849f3c print class name for classes that don't define a display method
jstorrs@gmail.com
parents: 10160
diff changeset
1111 newline (os);
1d430a849f3c print class name for classes that don't define a display method
jstorrs@gmail.com
parents: 10160
diff changeset
1112 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1113 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1114
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1115 // Loading a class properly requires an exemplar map entry for success.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1116 // If we don't have one, we attempt to create one by calling the constructor
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1117 // with no arguments.
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1118 bool
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1119 octave_class::reconstruct_exemplar (void)
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1120 {
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1121 bool retval = false;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1122
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1123 octave_class::exemplar_const_iterator it
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1124 = octave_class::exemplar_map.find (c_name);
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1125
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1126 if (it != octave_class::exemplar_map.end ())
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1127 retval = true;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1128 else
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1129 {
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1130 octave_value ctor = symbol_table::find_method (c_name, c_name);
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1131
12178
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1132 bool have_ctor = false;
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1133
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1134 if (ctor.is_defined () && ctor.is_function ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1135 {
12178
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1136 octave_function *fcn = ctor.function_value ();
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1137
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1138 if (fcn && fcn->is_class_constructor (c_name))
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1139 have_ctor = true;
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1140
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1141 // Something has gone terribly wrong if
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1142 // symbol_table::find_method (c_name, c_name) does not return
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1143 // a class constructor for the class c_name...
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1144 assert (have_ctor);
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1145 }
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1146
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1147 if (have_ctor)
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1148 {
17473
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1149 unwind_protect frame;
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1150
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1151 // Simulate try/catch.
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1152
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1153 interpreter_try (frame);
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1154
20569
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
1155 bool execution_error = false;
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
1156
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
1157 octave_value_list result;
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1158
20569
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
1159 try
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
1160 {
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
1161 result = ctor.do_multi_index_op (1, octave_value_list ());
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
1162 }
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
1163 catch (const octave_execution_exception&)
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
1164 {
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
1165 execution_error = true;
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
1166 }
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
1167
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20530
diff changeset
1168 if (! execution_error && result.length () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1169 retval = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1170 }
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1171 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1172 warning ("no constructor for class %s", c_name.c_str ());
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1173 }
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1174
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1175 return retval;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1176 }
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1177
9240
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1178 void
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1179 octave_class::clear_exemplar_map (void)
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1180 {
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1181 exemplar_map.clear ();
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1182 }
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1183
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1184 // Load/save does not provide enough information to reconstruct the
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1185 // class inheritance structure. reconstruct_parents () attempts to
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1186 // do so. If successful, a "true" value is returned.
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1187 //
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1188 // Note that we don't check the loaded object structure against the
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1189 // class structure here so the user's loadobj method has a chance
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1190 // to do its magic.
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1191 bool
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1192 octave_class::reconstruct_parents (void)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1193 {
18099
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 18033
diff changeset
1194 bool retval = true;
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 18033
diff changeset
1195 bool might_have_inheritance = false;
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1196 std::string dbgstr = "dork";
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1197
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1198 // First, check to see if there might be an issue with inheritance.
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1199 for (octave_map::const_iterator p = map.begin (); p != map.end (); p++)
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1200 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1201 std::string key = map.key (p);
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1202 Cell val = map.contents (p);
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18671
diff changeset
1203 if (val(0).is_object ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1204 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1205 dbgstr = "blork";
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18671
diff changeset
1206 if (key == val(0).class_name ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1207 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1208 might_have_inheritance = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1209 dbgstr = "cork";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1210 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1211 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1212 }
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1213 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1214
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1215 if (might_have_inheritance)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1216 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1217 octave_class::exemplar_const_iterator it
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1218 = octave_class::exemplar_map.find (c_name);
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1219
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1220 if (it == octave_class::exemplar_map.end ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1221 retval = false;
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1222 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1223 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1224 octave_class::exemplar_info exmplr = it->second;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1225 parent_list = exmplr.parents ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1226 for (std::list<std::string>::iterator pit = parent_list.begin ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1227 pit != parent_list.end ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1228 pit++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1229 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1230 dbgstr = *pit;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1231 bool dbgbool = map.contains (*pit);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1232 if (!dbgbool)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1233 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1234 retval = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1235 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1236 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1237 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1238 }
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1239 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1240
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1241 return retval;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1242 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1243
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1244 bool
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1245 octave_class::save_ascii (std::ostream& os)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1246 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1247 os << "# classname: " << class_name () << "\n";
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1248 octave_map m;
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1249 if (load_path::find_method (class_name (), "saveobj") != std::string ())
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1250 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1251 octave_value in = new octave_class (*this);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1252 octave_value_list tmp = feval ("saveobj", in, 1);
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
1253
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
1254 m = tmp(0).map_value ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1255 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1256 else
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1257 m = map_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1258
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1259 os << "# length: " << m.nfields () << "\n";
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1260
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1261 octave_map::iterator i = m.begin ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1262 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1263 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1264 octave_value val = map.contents (i);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1265
20482
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20267
diff changeset
1266 bool b = save_text_data (os, val, m.key (i), false, 0);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1267
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1268 if (! b)
18384
bd9d34f28b0f Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
1269 return ! os.fail ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1270
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1271 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1272 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1273
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1274 return true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1275 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1276
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1277 bool
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1278 octave_class::load_ascii (std::istream& is)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1279 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1280 octave_idx_type len = 0;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1281 std::string classname;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1282 bool success = true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1283
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1284 if (extract_keyword (is, "classname", classname) && classname != "")
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1285 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1286 if (extract_keyword (is, "length", len) && len >= 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1287 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1288 if (len > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1289 {
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1290 octave_map m (map);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1291
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1292 for (octave_idx_type j = 0; j < len; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1293 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1294 octave_value t2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1295 bool dummy;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1296
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1297 // recurse to read cell elements
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1298 std::string nm
20482
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20267
diff changeset
1299 = read_text_data (is, std::string (), dummy, t2, j);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1300
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1301 if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1302 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1303
20619
eef93a493ce3 use new cell_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20615
diff changeset
1304 Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading class elements") : Cell (t2);
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1305
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1306 m.assign (nm, tcell);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1307 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1308
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1309 if (is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1310 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1311 c_name = classname;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1312 reconstruct_exemplar ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1313
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1314 map = m;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1315
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1316 if (! reconstruct_parents ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1317 warning ("load: unable to reconstruct object inheritance");
17473
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1318
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1319 if (load_path::find_method (classname, "loadobj")
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1320 != std::string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1321 {
17473
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1322 octave_value in = new octave_class (*this);
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1323 octave_value_list tmp = feval ("loadobj", in, 1);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1324
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
1325 map = tmp(0).map_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1326 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1327 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1328 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1329 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1330 error ("load: failed to load class");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1331 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1332 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1333 }
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18671
diff changeset
1334 else if (len == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1335 {
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1336 map = octave_map (dim_vector (1, 1));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1337 c_name = classname;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1338 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1339 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1340 panic_impossible ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1341 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1342 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1343 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1344 error ("load: failed to extract number of elements in class");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1345 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1346 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1347 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1348 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1349 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1350 error ("load: failed to extract name of class");
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1351 success = false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1352 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1353
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1354 return success;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1355 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1356
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1357 bool
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1358 octave_class::save_binary (std::ostream& os, bool& save_as_floats)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1359 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1360 int32_t classname_len = class_name ().length ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1361
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1362 os.write (reinterpret_cast<char *> (&classname_len), 4);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1363 os << class_name ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1364
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1365 octave_map m;
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1366 if (load_path::find_method (class_name (), "saveobj") != std::string ())
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1367 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1368 octave_value in = new octave_class (*this);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1369 octave_value_list tmp = feval ("saveobj", in, 1);
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
1370
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
1371 m = tmp(0).map_value ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1372 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1373 else
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1374 m = map_value ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1375
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1376 int32_t len = m.nfields ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1377 os.write (reinterpret_cast<char *> (&len), 4);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1378
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1379 octave_map::iterator i = m.begin ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1380 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1381 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1382 octave_value val = map.contents (i);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1383
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1384 bool b = save_binary_data (os, val, m.key (i), "", 0, save_as_floats);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1385
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1386 if (! b)
18384
bd9d34f28b0f Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
1387 return ! os.fail ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1388
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1389 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1390 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1391
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1392 return true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1393 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1394
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1395 bool
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1396 octave_class::load_binary (std::istream& is, bool swap,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1397 oct_mach_info::float_format fmt)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1398 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1399 bool success = true;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1400
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1401 int32_t classname_len;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1402
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1403 is.read (reinterpret_cast<char *> (&classname_len), 4);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1404 if (! is)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1405 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1406 else if (swap)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1407 swap_bytes<4> (&classname_len);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1408
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1409 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1410 OCTAVE_LOCAL_BUFFER (char, classname, classname_len+1);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1411 classname[classname_len] = '\0';
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1412 if (! is.read (reinterpret_cast<char *> (classname), classname_len))
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1413 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1414 c_name = classname;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1415 }
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1416 reconstruct_exemplar ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1417
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1418 int32_t len;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1419 if (! is.read (reinterpret_cast<char *> (&len), 4))
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1420 return false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1421 if (swap)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1422 swap_bytes<4> (&len);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1423
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1424 if (len > 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1425 {
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1426 octave_map m (map);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1427
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1428 for (octave_idx_type j = 0; j < len; j++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1429 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1430 octave_value t2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1431 bool dummy;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1432 std::string doc;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1433
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1434 // recurse to read cell elements
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1435 std::string nm = read_binary_data (is, swap, fmt, std::string (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1436 dummy, t2, doc);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1437
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1438 if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1439 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1440
20619
eef93a493ce3 use new cell_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20615
diff changeset
1441 Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading class elements") : Cell (t2);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1442
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1443 m.assign (nm, tcell);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1444 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1445
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1446 if (is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1447 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1448 map = m;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1449
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1450 if (! reconstruct_parents ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1451 warning ("load: unable to reconstruct object inheritance");
17473
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1452
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1453 if (load_path::find_method (c_name, "loadobj") != std::string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1454 {
17473
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1455 octave_value in = new octave_class (*this);
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1456 octave_value_list tmp = feval ("loadobj", in, 1);
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1457
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
1458 map = tmp(0).map_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1459 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1460 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1461 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1462 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1463 warning ("load: failed to load class");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1464 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1465 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1466 }
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18671
diff changeset
1467 else if (len == 0)
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1468 map = octave_map (dim_vector (1, 1));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1469 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1470 panic_impossible ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1471
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1472 return success;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1473 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1474
19897
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1475 bool
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1476 octave_class::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats)
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1477 {
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1478 #if defined (HAVE_HDF5)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1479
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1480 hsize_t hdims[3];
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1481 hid_t group_hid = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1482 hid_t type_hid = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1483 hid_t space_hid = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1484 hid_t class_hid = -1;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1485 hid_t data_hid = -1;
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1486 octave_map m;
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1487 octave_map::iterator i;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1488
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1489 #if HAVE_HDF5_18
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1490 group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1491 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1492 group_hid = H5Gcreate (loc_id, name, 0);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1493 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1494 if (group_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1495 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1496
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1497 // Add the class name to the group
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1498 type_hid = H5Tcopy (H5T_C_S1); H5Tset_size (type_hid, c_name.length () + 1);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1499 if (type_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1500 goto error_cleanup;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1501
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1502 hdims[0] = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1503 space_hid = H5Screate_simple (0 , hdims, 0);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1504 if (space_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1505 goto error_cleanup;
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1506 #if HAVE_HDF5_18
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1507 class_hid = H5Dcreate (group_hid, "classname", type_hid, space_hid,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1508 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1509 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1510 class_hid = H5Dcreate (group_hid, "classname", type_hid, space_hid,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1511 H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1512 #endif
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1513 if (class_hid < 0 || H5Dwrite (class_hid, type_hid, H5S_ALL, H5S_ALL,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1514 H5P_DEFAULT, c_name.c_str ()) < 0)
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1515 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1516
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1517 #if HAVE_HDF5_18
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1518 data_hid = H5Gcreate (group_hid, "value", H5P_DEFAULT, H5P_DEFAULT,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1519 H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1520 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1521 data_hid = H5Gcreate (group_hid, "value", 0);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1522 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1523 if (data_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1524 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1525
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1526 if (load_path::find_method (class_name (), "saveobj") != std::string ())
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1527 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1528 octave_value in = new octave_class (*this);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1529 octave_value_list tmp = feval ("saveobj", in, 1);
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
1530
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
1531 m = tmp(0).map_value ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1532 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1533 else
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1534 m = map_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1535
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1536 // recursively add each element of the class to this group
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1537 i = m.begin ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1538 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1539 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1540 octave_value val = map.contents (i);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1541
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1542 bool retval2 = add_hdf5_data (data_hid, val, m.key (i), "", false,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1543 save_as_floats);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1544
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1545 if (! retval2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1546 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1547
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1548 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1549 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1550
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1551 error_cleanup:
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1552
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1553 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1554 H5Gclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1555
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1556 if (class_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1557 H5Dclose (class_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1558
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1559 if (space_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1560 H5Sclose (space_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1561
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1562 if (type_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1563 H5Tclose (type_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1564
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1565 if (group_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1566 H5Gclose (group_hid);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1567
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1568 return true;
19897
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1569
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1570 #else
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1571 gripe_save ("hdf5");
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1572 return false;
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1573 #endif
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1574 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1575
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1576 bool
19897
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1577 octave_class::load_hdf5 (octave_hdf5_id loc_id, const char *name)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1578 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1579 bool retval = false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1580
19897
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1581 #if defined (HAVE_HDF5)
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1582
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1583 hid_t group_hid = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1584 hid_t data_hid = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1585 hid_t type_hid = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1586 hid_t type_class_hid = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1587 hid_t space_hid = -1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1588 hid_t subgroup_hid = -1;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1589 hid_t st_id = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1590
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1591 hdf5_callback_data dsub;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1592
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1593 herr_t retval2 = 0;
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1594 octave_map m (dim_vector (1, 1));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1595 int current_item = 0;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1596 hsize_t num_obj = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1597 int slen = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1598 hsize_t rank = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1599
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1600 #if HAVE_HDF5_18
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1601 group_hid = H5Gopen (loc_id, name, H5P_DEFAULT);
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1602 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1603 group_hid = H5Gopen (loc_id, name);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1604 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1605 if (group_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1606 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1607
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1608 #if HAVE_HDF5_18
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1609 data_hid = H5Dopen (group_hid, "classname", H5P_DEFAULT);
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1610 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1611 data_hid = H5Dopen (group_hid, "classname");
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1612 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1613
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1614 if (data_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1615 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1616
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1617 type_hid = H5Dget_type (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1618
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1619 type_class_hid = H5Tget_class (type_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1620
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1621 if (type_class_hid != H5T_STRING)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1622 goto error_cleanup;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1623
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1624 space_hid = H5Dget_space (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1625 rank = H5Sget_simple_extent_ndims (space_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1626
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1627 if (rank != 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1628 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1629
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1630 slen = H5Tget_size (type_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1631 if (slen < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1632 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1633
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1634 // do-while loop here to prevent goto crossing initialization of classname
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1635 do
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1636 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1637 OCTAVE_LOCAL_BUFFER (char, classname, slen);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1638
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1639 // create datatype for (null-terminated) string to read into:
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1640 st_id = H5Tcopy (H5T_C_S1);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1641 H5Tset_size (st_id, slen);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1642
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1643 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1644 classname) < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1645 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1646 H5Tclose (st_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1647 H5Dclose (data_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1648 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1649 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1650 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1651
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1652 H5Tclose (st_id);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1653 H5Dclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1654 data_hid = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1655
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1656 c_name = classname;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1657 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1658 while (0);
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1659 reconstruct_exemplar ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1660
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1661 #if HAVE_HDF5_18
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1662 subgroup_hid = H5Gopen (group_hid, name, H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1663 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1664 subgroup_hid = H5Gopen (group_hid, name);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1665 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1666 H5Gget_num_objs (subgroup_hid, &num_obj);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1667 H5Gclose (subgroup_hid);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1668
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1669 while (current_item < static_cast<int> (num_obj)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1670 && (retval2 = H5Giterate (group_hid, name, &current_item,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1671 hdf5_read_next_data, &dsub)) > 0)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1672 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1673 octave_value t2 = dsub.tc;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1674
20619
eef93a493ce3 use new cell_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20615
diff changeset
1675 Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading class elements") : Cell (t2);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1676
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1677 m.assign (dsub.name, tcell);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1678
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1679 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1680
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1681 if (retval2 >= 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1682 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1683 map = m;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1684
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1685 if (!reconstruct_parents ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1686 warning ("load: unable to reconstruct object inheritance");
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1687
17473
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1688 if (load_path::find_method (c_name, "loadobj") != std::string ())
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1689 {
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1690 octave_value in = new octave_class (*this);
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1691 octave_value_list tmp = feval ("loadobj", in, 1);
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1692
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
1693 map = tmp(0).map_value ();
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
1694 retval = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1695 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1696 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1697
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1698 error_cleanup:
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1699 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1700 H5Dclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1701
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1702 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1703 H5Gclose (group_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1704
19897
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1705 #else
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1706 gripe_load ("hdf5");
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1707 #endif
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19731
diff changeset
1708
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1709 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1710 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1711
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1712 mxArray *
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1713 octave_class::as_mxArray (void) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1714 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1715 gripe_wrong_type_arg ("octave_class::as_mxArray ()", type_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1716
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1717 return 0;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1718 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1719
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1720 bool
9581
3d0d2bda3a0f fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9580
diff changeset
1721 octave_class::in_class_method (void)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1722 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1723 octave_function *fcn = octave_call_stack::current ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1724
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1725 return (fcn
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1726 && (fcn->is_class_method ()
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1727 || fcn->is_class_constructor ()
13241
2a8dcb5b3a00 improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents: 13112
diff changeset
1728 || fcn->is_anonymous_function_of_class ()
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1729 || fcn->is_private_function_of_class (class_name ()))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1730 && find_parent_class (fcn->dispatch_class ()));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1731 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1732
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1733 octave_class::exemplar_info::exemplar_info (const octave_value& obj)
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1734 : field_names (), parent_class_names ()
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1735 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1736 if (obj.is_object ())
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1737 {
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1738 octave_map m = obj.map_value ();
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1739 field_names = m.keys ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1740
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1741 parent_class_names = obj.parent_class_name_list ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1742 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1743 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 12178
diff changeset
1744 error ("invalid call to exemplar_info constructor");
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1745 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1746
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1747
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1748 // A map from class names to lists of fields.
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1749 std::map<std::string, octave_class::exemplar_info> octave_class::exemplar_map;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1750
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1751 bool
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1752 octave_class::exemplar_info::compare (const octave_value& obj) const
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1753 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1754 bool retval = true;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1755
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1756 if (obj.is_object ())
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1757 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1758 if (nfields () == obj.nfields ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1759 {
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1760 octave_map obj_map = obj.map_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1761 string_vector obj_fnames = obj_map.keys ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1762 string_vector fnames = fields ();
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1763
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1764 for (octave_idx_type i = 0; i < nfields (); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1765 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1766 if (obj_fnames[i] != fnames[i])
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1767 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1768 retval = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1769 error ("mismatch in field names");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1770 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1771 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1772 }
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1773
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1774 if (nparents () == obj.nparents ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1775 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1776 std::list<std::string> obj_parents
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1777 = obj.parent_class_name_list ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1778 std::list<std::string> pnames = parents ();
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1779
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1780 std::list<std::string>::const_iterator p = obj_parents.begin ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1781 std::list<std::string>::const_iterator q = pnames.begin ();
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1782
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1783 while (p != obj_parents.end ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1784 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1785 if (*p++ != *q++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1786 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1787 retval = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1788 error ("mismatch in parent classes");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1789 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1790 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1791 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1792 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1793 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1794 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1795 retval = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1796 error ("mismatch in number of parent classes");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1797 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1798 }
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1799 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1800 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1801 retval = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1802 error ("mismatch in number of fields");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1803 }
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1804 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1805 else
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1806 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1807 retval = false;
9206
5f36c6c9be13 Handle loading of objects with inheritance from MAT files.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9190
diff changeset
1808 error ("invalid comparison of class exemplar to non-class object");
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1809 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1810
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1811 return retval;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1812 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1813
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1814 DEFUN (class, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1815 "-*- texinfo -*-\n\
15811
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1816 @deftypefn {Function File} {@var{classname} =} class (@var{obj})\n\
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1817 @deftypefnx {Function File} {} class (@var{s}, @var{id})\n\
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1818 @deftypefnx {Function File} {} class (@var{s}, @var{id}, @var{p}, @dots{})\n\
20198
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20063
diff changeset
1819 Return the class of the object @var{obj}, or create a class with\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20063
diff changeset
1820 fields from structure @var{s} and name (string) @var{id}.\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20063
diff changeset
1821 \n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20063
diff changeset
1822 Additional arguments name a list of parent classes from which the new class\n\
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20063
diff changeset
1823 is derived.\n\
15811
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1824 @seealso{typeinfo, isa}\n\
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1825 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1826 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1827 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1828
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1829 int nargin = args.length ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1830
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1831 if (nargin == 0)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1832 print_usage ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1833 else if (nargin == 1)
15811
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1834 // Called for class of object
15813
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15812
diff changeset
1835 retval = args(0).class_name ();
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1836 else
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1837 {
15811
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1838 // Called as class constructor
10272
272179888089 Fclass: improve argument decoding
John W. Eaton <jwe@octave.org>
parents: 10204
diff changeset
1839 octave_function *fcn = octave_call_stack::caller ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1840
20615
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1841 std::string id = args(1).string_value ("class: ID (class name) must be a string");
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1842
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1843 if (fcn)
19438
c2f4f6eb5907 A few more instances of stricter input validation for strings (bug #42651).
Rik <rik@octave.org>
parents: 19437
diff changeset
1844 {
20615
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1845 if (fcn->is_class_constructor (id) || fcn->is_class_method (id))
11220
883b9308353c allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents: 10932
diff changeset
1846 {
20615
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1847 octave_map m = args(0).map_value ();
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1848
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1849 if (! error_state)
10272
272179888089 Fclass: improve argument decoding
John W. Eaton <jwe@octave.org>
parents: 10204
diff changeset
1850 {
20615
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1851 if (nargin == 2)
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1852 retval
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1853 = octave_value (new octave_class
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1854 (m, id, std::list<std::string> ()));
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1855 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1856 {
20615
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1857 octave_value_list parents = args.slice (2, nargin-2);
11220
883b9308353c allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents: 10932
diff changeset
1858
20615
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1859 retval
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1860 = octave_value (new octave_class (m, id, parents));
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1861 }
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1862
20615
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1863 octave_class::exemplar_const_iterator it
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1864 = octave_class::exemplar_map.find (id);
11220
883b9308353c allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents: 10932
diff changeset
1865
20615
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1866 if (it == octave_class::exemplar_map.end ())
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1867 octave_class::exemplar_map[id]
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1868 = octave_class::exemplar_info (retval);
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1869 else if (! it->second.compare (retval))
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1870 error ("class: object of class '%s' does not match previously constructed objects",
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1871 id.c_str ());
10272
272179888089 Fclass: improve argument decoding
John W. Eaton <jwe@octave.org>
parents: 10204
diff changeset
1872 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1873 else
20615
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1874 error ("class: expecting structure S as first argument");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1875 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1876 else
20615
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1877 error ("class: '%s' is invalid as a class name in this context",
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1878 id.c_str ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1879 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1880 else
20615
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
1881 error ("class: invalid call from outside class constructor or method");
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1882 }
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1883
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1884 return retval;
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1885 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1886
15811
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1887 /*
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1888 %!assert (class (1.1), "double");
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1889 %!assert (class (single (1.1)), "single");
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1890 %!assert (class (uint8 (1)), "uint8");
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1891 %!testif HAVE_JAVA
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1892 %! jobj = javaObject ("java.lang.StringBuffer");
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1893 %! assert (class (jobj), "java.lang.StringBuffer");
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1894
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1895 %% Test Input Validation
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1896 %!error class ()
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1897 */
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1898
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1899 DEFUN (isa, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1900 "-*- texinfo -*-\n\
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1901 @deftypefn {Function File} {} isa (@var{obj}, @var{classname})\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1902 Return true if @var{obj} is an object from the class @var{classname}.\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1903 \n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1904 @var{classname} may also be one of the following class categories:\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1905 \n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1906 @table @asis\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1907 @item @qcode{\"float\"}\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1908 Floating point value comprising classes @qcode{\"double\"} and\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1909 @qcode{\"single\"}.\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1910 \n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1911 @item @qcode{\"integer\"}\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1912 Integer value comprising classes (u)int8, (u)int16, (u)int32, (u)int64.\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1913 \n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1914 @item @qcode{\"numeric\"}\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1915 Numeric value comprising either a floating point or integer value.\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1916 @end table\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1917 \n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1918 If @var{classname} is a cell array of string, a logical array of the same\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1919 size is returned, containing true for each class to which @var{obj}\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1920 belongs to.\n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1921 \n\
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1922 @seealso{class, typeinfo}\n\
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1923 @end deftypefn")
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1924 {
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1925 octave_value retval;
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1926
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1927 if (args.length () != 2)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1928 {
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1929 print_usage ();
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1930 return retval;
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1931 }
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1932
20530
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20482
diff changeset
1933 octave_value obj = args(0); // not const because of find_parent_class ()
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20482
diff changeset
1934 std::string obj_cls = obj.class_name ();
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20482
diff changeset
1935 Array<std::string> clsnames = args(1).cellstr_value ();
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1936 if (error_state)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1937 {
18915
4cdab2973171 maint: Fix some spellings in error messages.
Rik <rik@octave.org>
parents: 18712
diff changeset
1938 error ("isa: CLASSNAME must be a string or cell array of strings");
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1939 return retval;
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1940 }
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1941
20530
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20482
diff changeset
1942 boolNDArray matches (clsnames.dims (), false);
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20482
diff changeset
1943 for (octave_idx_type idx = 0; idx < clsnames.numel (); idx++)
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1944 {
20530
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20482
diff changeset
1945 std::string cls = clsnames(idx);
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20482
diff changeset
1946 if (obj_cls == cls
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20482
diff changeset
1947 || (cls == "float" && obj.is_float_type ())
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20482
diff changeset
1948 || (cls == "integer" && obj.is_integer_type ())
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20482
diff changeset
1949 || (cls == "numeric" && obj.is_numeric_type ())
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20482
diff changeset
1950 || obj.is_instance_of (cls))
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1951 matches(idx) = true;
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1952 }
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1953 return octave_value (matches);
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1954 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1955
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1956 /*
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1957 %!assert (isa ("char", "float"), false)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1958 %!assert (isa (logical (1), "float"), false)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1959 %!assert (isa (double (13), "float"), true)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1960 %!assert (isa (single (13), "float"), true)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1961 %!assert (isa (int8 (13), "float"), false)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1962 %!assert (isa (int16 (13), "float"), false)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1963 %!assert (isa (int32 (13), "float"), false)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1964 %!assert (isa (int64 (13), "float"), false)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1965 %!assert (isa (uint8 (13), "float"), false)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1966 %!assert (isa (uint16 (13), "float"), false)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1967 %!assert (isa (uint32 (13), "float"), false)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1968 %!assert (isa (uint64 (13), "float"), false)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1969 %!assert (isa ("char", "numeric"), false)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1970 %!assert (isa (logical (1), "numeric"), false)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1971 %!assert (isa (double (13), "numeric"), true)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1972 %!assert (isa (single (13), "numeric"), true)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1973 %!assert (isa (int8 (13), "numeric"), true)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1974 %!assert (isa (int16 (13), "numeric"), true)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1975 %!assert (isa (int32 (13), "numeric"), true)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1976 %!assert (isa (int64 (13), "numeric"), true)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1977 %!assert (isa (uint8 (13), "numeric"), true)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1978 %!assert (isa (uint16 (13), "numeric"), true)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1979 %!assert (isa (uint32 (13), "numeric"), true)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1980 %!assert (isa (uint64 (13), "numeric"), true)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1981 %!assert (isa (uint8 (13), "integer"), true)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1982 %!assert (isa (double (13), "integer"), false)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1983 %!assert (isa (single (13), "integer"), false)
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1984 %!assert (isa (single (13), {"integer", "float", "single"}), [false true true])
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1985
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1986 %!assert (isa (double (13), "double"))
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1987 %!assert (isa (single (13), "single"))
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1988 %!assert (isa (int8 (13), "int8"))
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1989 %!assert (isa (int16 (13), "int16"))
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1990 %!assert (isa (int32 (13), "int32"))
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1991 %!assert (isa (int64 (13), "int64"))
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1992 %!assert (isa (uint8 (13), "uint8"))
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1993 %!assert (isa (uint16 (13), "uint16"))
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1994 %!assert (isa (uint32 (13), "uint32"))
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1995 %!assert (isa (uint64 (13), "uint64"))
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1996 %!assert (isa ("string", "char"))
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1997 %!assert (isa (true, "logical"))
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1998 %!assert (isa (false, "logical"))
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1999 %!assert (isa ({1, 2}, "cell"))
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
2000 %!assert (isa ({1, 2}, {"numeric", "integer", "cell"}), [false false true])
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
2001
20063
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19898
diff changeset
2002 %!testif HAVE_JAVA
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19898
diff changeset
2003 %! ## The first and last assert() are equal on purpose. The assert() in
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19898
diff changeset
2004 %! ## the middle with an invalid class name will cause the java code to
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19898
diff changeset
2005 %! ## throw exceptions which we then must clear properly (or all other calls
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19898
diff changeset
2006 %! ## will fail). So we test this too.
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19898
diff changeset
2007 %! assert (isa (javaObject ("java.lang.Double", 10), "java.lang.Number"))
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19898
diff changeset
2008 %! assert (isa (javaObject ("java.lang.Double", 10), "not_a_class"), false)
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19898
diff changeset
2009 %! assert (isa (javaObject ("java.lang.Double", 10), "java.lang.Number"))
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19898
diff changeset
2010
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
2011 %!test
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
2012 %! a.b = 1;
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
2013 %! assert (isa (a, "struct"));
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
2014 */
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
2015
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
2016 DEFUN (__parent_classes__, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2017 "-*- texinfo -*-\n\
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
2018 @deftypefn {Built-in Function} {} __parent_classes__ (@var{x})\n\
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
2019 Undocumented internal function.\n\
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
2020 @end deftypefn")
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
2021 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
2022 octave_value retval = Cell ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
2023
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
2024 if (args.length () == 1)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
2025 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
2026 octave_value arg = args(0);
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
2027
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
2028 if (arg.is_object ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
2029 retval = Cell (arg.parent_class_names ());
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
2030 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2031 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2032 print_usage ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2033
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2034 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2035 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2036
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2037 DEFUN (isobject, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2038 "-*- texinfo -*-\n\
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2039 @deftypefn {Built-in Function} {} isobject (@var{x})\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2040 Return true if @var{x} is a class object.\n\
18671
2631484789cf doc: Improve docstrings for isobject, ismethod, isprop.
Rik <rik@octave.org>
parents: 18537
diff changeset
2041 @seealso{class, typeinfo, isa, ismethod, isprop}\n\
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2042 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2043 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2044 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2045
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2046 if (args.length () == 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2047 retval = args(0).is_object ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2048 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2049 print_usage ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2050
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2051 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2052 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2053
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2054 DEFUN (ismethod, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2055 "-*- texinfo -*-\n\
18671
2631484789cf doc: Improve docstrings for isobject, ismethod, isprop.
Rik <rik@octave.org>
parents: 18537
diff changeset
2056 @deftypefn {Built-in Function} {} ismethod (@var{obj}, @var{method})\n\
2631484789cf doc: Improve docstrings for isobject, ismethod, isprop.
Rik <rik@octave.org>
parents: 18537
diff changeset
2057 Return true if @var{obj} is a class object and the string @var{method}\n\
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2058 is a method of this class.\n\
18533
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 18384
diff changeset
2059 @seealso{isprop, isobject}\n\
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2060 @end deftypefn")
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2061 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2062 octave_value retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2063
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2064 if (args.length () == 2)
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2065 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2066 octave_value arg = args(0);
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2067
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2068 std::string class_name;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2069
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2070 if (arg.is_object ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
2071 class_name = arg.class_name ();
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2072 else if (arg.is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
2073 class_name = arg.string_value ();
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2074 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
2075 error ("ismethod: expecting object or class name as first argument");
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2076
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
2077 std::string method = args(1).string_value ();
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2078
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
2079 if (load_path::find_method (class_name, method) != std::string ())
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
2080 retval = true;
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
2081 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
2082 retval = false;
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2083 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2084 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2085 print_usage ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2086
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2087 return retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2088 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
2089
15785
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
2090 DEFUN (__methods__, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2091 "-*- texinfo -*-\n\
15785
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
2092 @deftypefn {Built-in Function} {} __methods__ (@var{x})\n\
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
2093 @deftypefnx {Built-in Function} {} __methods__ (\"classname\")\n\
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
2094 Internal function.\n\
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
2095 \n\
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
2096 Implements @code{methods} for Octave class objects and classnames.\n\
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
2097 @seealso{methods}\n\
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2098 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2099 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2100 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2101
15785
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
2102 // Input validation has already been done in methods.m.
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
2103 octave_value arg = args(0);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2104
15785
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
2105 std::string class_name;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2106
15785
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
2107 if (arg.is_object ())
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
2108 class_name = arg.class_name ();
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
2109 else if (arg.is_string ())
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
2110 class_name = arg.string_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2111
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
2112 string_vector sv = load_path::methods (class_name);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20569
diff changeset
2113 retval = Cell (sv);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2114
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2115 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2116 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2117
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2118 static bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2119 is_built_in_class (const std::string& cn)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2120 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2121 static std::set<std::string> built_in_class_names;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2122
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2123 if (built_in_class_names.empty ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2124 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2125 built_in_class_names.insert ("double");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2126 built_in_class_names.insert ("single");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2127 built_in_class_names.insert ("cell");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2128 built_in_class_names.insert ("struct");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2129 built_in_class_names.insert ("logical");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2130 built_in_class_names.insert ("char");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2131 built_in_class_names.insert ("function handle");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2132 built_in_class_names.insert ("int8");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2133 built_in_class_names.insert ("uint8");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2134 built_in_class_names.insert ("int16");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2135 built_in_class_names.insert ("uint16");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2136 built_in_class_names.insert ("int32");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2137 built_in_class_names.insert ("uint32");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2138 built_in_class_names.insert ("int64");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2139 built_in_class_names.insert ("uint64");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2140 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2141
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2142 return built_in_class_names.find (cn) != built_in_class_names.end ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2143 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2144
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2145 DEFUN (superiorto, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2146 "-*- texinfo -*-\n\
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
2147 @deftypefn {Built-in Function} {} superiorto (@var{class_name}, @dots{})\n\
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2148 When called from a class constructor, mark the object currently\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2149 constructed as having a higher precedence than @var{class_name}.\n\
20198
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20063
diff changeset
2150 \n\
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
2151 More that one such class can be specified in a single call.\n\
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2152 This function may only be called from a class constructor.\n\
18533
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 18384
diff changeset
2153 @seealso{inferiorto}\n\
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2154 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2155 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2156 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2157
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2158 octave_function *fcn = octave_call_stack::caller ();
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2159 if ((! fcn) || (! fcn->is_class_constructor ()))
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2160 {
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2161 error ("superiorto: invalid call from outside class constructor");
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2162 return retval;
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2163 }
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2164
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2165 for (int i = 0; i < args.length (); i++)
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2166 {
20615
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
2167 std::string inf_class = args(i).string_value ("superiorto: expecting argument to be class name");
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2168
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2169 // User defined classes always have higher precedence
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2170 // than built-in classes
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2171 if (is_built_in_class (inf_class))
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2172 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2173
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2174 std::string sup_class = fcn->name ();
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2175 if (! symbol_table::set_class_relationship (sup_class, inf_class))
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2176 {
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2177 error ("superiorto: opposite precedence already set for %s and %s",
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2178 sup_class.c_str (), inf_class.c_str ());
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2179 break;
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2180 }
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2181 }
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2182
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2183 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2184 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2185
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2186 DEFUN (inferiorto, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2187 "-*- texinfo -*-\n\
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
2188 @deftypefn {Built-in Function} {} inferiorto (@var{class_name}, @dots{})\n\
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2189 When called from a class constructor, mark the object currently\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2190 constructed as having a lower precedence than @var{class_name}.\n\
20198
075a5e2e1ba5 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 20063
diff changeset
2191 \n\
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
2192 More that one such class can be specified in a single call.\n\
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2193 This function may only be called from a class constructor.\n\
18533
ea0d4dea1a17 doc: Update documentation for functions in octave-value dir.
Rik <rik@octave.org>
parents: 18384
diff changeset
2194 @seealso{superiorto}\n\
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2195 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2196 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2197 octave_value retval;
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2198
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2199 octave_function *fcn = octave_call_stack::caller ();
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2200 if ((! fcn) || (! fcn->is_class_constructor ()))
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2201 {
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2202 error ("inferiorto: invalid call from outside class constructor");
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2203 return retval;
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2204 }
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2205
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2206 for (int i = 0; i < args.length (); i++)
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2207 {
20615
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20593
diff changeset
2208 std::string sup_class = args(i).string_value ("inferiorto: expecting argument to be class name");
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2209
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2210 if (is_built_in_class (sup_class))
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2211 {
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2212 error ("inferiorto: cannot give user-defined class lower "
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2213 "precedence than built-in class");
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2214 break;
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2215 }
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2216
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2217 std::string inf_class = fcn->name ();
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2218 if (! symbol_table::set_class_relationship (sup_class, inf_class))
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2219 {
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2220 error ("inferiorto: opposite precedence already set for %s and %s",
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2221 inf_class.c_str (), sup_class.c_str ());
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2222 break;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
2223 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2224 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2225
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2226 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2227 }