annotate libinterp/octave-value/ov-class.cc @ 23519:4fe410bd918d

use DEFMETHOD for some built-in functions * load-path.cc (Fcommand_line_path, Frestoredefaultpath, F__pathorig__, Fpath, Faddpath, Frmpath, F__dump_load_path__): Use DEFMETHOD. * utils.cc (Ffile_in_loadpath, Fdir_in_loadpath): Use DEFMETHOD. * ov-class.cc (Fismethod, F__methods__): Use DEFMETHOD.
author John W. Eaton <jwe@octave.org>
date Fri, 19 May 2017 16:05:03 -0400
parents 1ee4b394a687
children 14723784b9f2
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
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 2007-2017 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
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
9 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
10 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
11 (at your option) any later version.
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
12
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
13 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
14 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
16 GNU General Public License for more details.
7338
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
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
24 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21211
diff changeset
25 # include "config.h"
7338
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"
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents: 22028
diff changeset
36 #include "call-stack.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
37 #include "defun.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
38 #include "error.h"
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
39 #include "file-ops.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
40 #include "errwarn.h"
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
41 #include "interpreter-private.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22091
diff changeset
42 #include "interpreter.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
43 #include "load-path.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
44 #include "ls-hdf5.h"
20447
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20232
diff changeset
45 #include "ls-oct-text.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
46 #include "ls-oct-binary.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
47 #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
48 #include "mxarray.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
49 #include "oct-lvalue.h"
19863
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: 19697
diff changeset
50 #include "oct-hdf5.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
51 #include "ov-class.h"
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 "unwind-prot.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
58 #include "variables.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
59
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 int octave_class::t_id (-1);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
62
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
63 const std::string octave_class::t_name ("class");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
64
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
65 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
66 octave_class::register_type (void)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
67 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
68 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
69 (octave_class::t_name, "<unknown>",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
70 octave_value (new octave_class ()));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
71 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
72
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
73 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
74 const octave_value_list& parents)
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
75 : 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
76 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
77 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
78
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
79 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
80 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
81 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
82
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
83 if (! parent.is_object ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
84 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
85
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
86 std::string pcnm = parent.class_name ();
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
87
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
88 if (find_parent_class (pcnm))
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
89 error ("duplicate class in parent tree");
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
90
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
91 parent_list.push_back (pcnm);
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
92
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
93 octave_idx_type nel = map.numel ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
94 octave_idx_type p_nel = parent.numel ();
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
95
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
96 if (nel == 0)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
97 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
98 if (p_nel == 0)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
99 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
100 // No elements in MAP or the parent class object,
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
101 // so just add the field name.
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
102
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
103 map.assign (pcnm, Cell (map.dims ()));
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
104 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
105 else if (p_nel == 1)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
106 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
107 if (map.nfields () == 0)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
108 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
109 // No elements or fields in MAP, but the
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
110 // parent is class object with one element.
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
111 // Resize to match size of parent class and
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
112 // make the parent a field in MAP.
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
113
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
114 map.resize (parent.dims ());
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
115
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
116 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
117 }
c7fac37a2afc class: correctly handle parents when structure array has more than one element
John W. Eaton <jwe@octave.org>
parents: 13695
diff changeset
118 else
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
119 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
120 // No elements in MAP, but we have at least
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
121 // one field. So don't resize, just add the
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
122 // field name.
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
123
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
124 map.assign (pcnm, Cell (map.dims ()));
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
125 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
126 }
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
127 else if (map.nfields () == 0)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
128 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
129 // No elements or fields in MAP and more than one
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
130 // element in the parent class object, so we can
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
131 // resize MAP to match parent dimsenions, then
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
132 // distribute the elements of the parent object to
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
133 // the elements of MAP.
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
134
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
135 dim_vector parent_dims = parent.dims ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
136
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
137 map.resize (parent_dims);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
138
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
139 Cell c (parent_dims);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
140
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
141 octave_map pmap = parent.map_value ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
142
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
143 std::list<std::string> plist
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
144 = parent.parent_class_name_list ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
145
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
146 for (octave_idx_type i = 0; i < p_nel; i++)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
147 c(i) = octave_value (pmap.index (i), pcnm, plist);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
148
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
149 map.assign (pcnm, c);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
150 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
151 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
152 error ("class: parent class dimension mismatch");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
153 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
154 else if (nel == 1 && p_nel == 1)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
155 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
156 // Simple assignment.
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
157
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
158 map.assign (pcnm, parent);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
159 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
160 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
161 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
162 if (p_nel == 1)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
163 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
164 // Broadcast the scalar parent class object to
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
165 // each element of MAP.
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
166
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
167 Cell pcell (map.dims (), parent);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
168
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
169 map.assign (pcnm, pcell);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
170 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
171 else if (nel == p_nel)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
172 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
173 // FIXME: is there a better way to do this?
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
174
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
175 // The parent class object has the same number of
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
176 // elements as the map we are using to create the
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
177 // new object, so distribute those elements to
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
178 // each element of the new object by first
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
179 // splitting the elements of the parent class
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
180 // object into a cell array with one element per
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
181 // cell. Then do the assignment all at once.
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
182
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
183 Cell c (parent.dims ());
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
184
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
185 octave_map pmap = parent.map_value ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
186
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
187 std::list<std::string> plist
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
188 = parent.parent_class_name_list ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
189
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
190 for (octave_idx_type i = 0; i < p_nel; i++)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
191 c(i) = octave_value (pmap.index (i), pcnm, plist);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
192
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
193 map.assign (pcnm, c);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
194 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
195 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
196 error ("class: parent class dimension mismatch");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
197 }
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
198 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
199
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
200 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
201 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
202
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
203 octave_base_value *
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
204 octave_class::unique_clone (void)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
205 {
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
206 if (count == obsolete_copies)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
207 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21743
diff changeset
208 // All remaining copies are obsolete. We don't actually need to clone.
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
209 count++;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
210 return this;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
211 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
212 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
213 {
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
214 // 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
215 if (count < obsolete_copies)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
216 obsolete_copies = 0;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
217
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
218 return clone ();
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
219 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
220 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
221
10926
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
222 std::string
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
223 octave_class::get_current_method_class (void)
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
224 {
10926
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
225 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
226
12620
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
227 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
228 {
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
229 octave_function *fcn = octave::call_stack::current ();
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
230
12620
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
231 // 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
232 // 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
233 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
234 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
235 }
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
236
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
237 return retval;
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
238 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
239
21040
3e7cfee5f786 maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents: 21029
diff changeset
240 OCTAVE_NORETURN static
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21024
diff changeset
241 void
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
242 err_invalid_index1 (void)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
243 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
244 error ("invalid index for class");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
245 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
246
21040
3e7cfee5f786 maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents: 21029
diff changeset
247 OCTAVE_NORETURN static
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21024
diff changeset
248 void
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
249 err_invalid_index_for_assignment (void)
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
250 {
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
251 error ("invalid index for class assignment");
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
252 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
253
21040
3e7cfee5f786 maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents: 21029
diff changeset
254 OCTAVE_NORETURN static
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21024
diff changeset
255 void
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
256 err_invalid_index_type (const std::string& nm, char t)
9529
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 error ("%s cannot be indexed with %c", nm.c_str (), t);
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
259 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
260
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
261 Cell
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
262 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
263 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
264 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
265
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
266 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
267
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
268 // 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
269 // 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
270
10926
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
271 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
272
10926
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
273 if (obvp == 0)
20879
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
274 error ("malformed class");
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
275
10932
3a778233e4fb fix typo in 10926:f687bd17ce21
Jaroslav Hajek <highegg@gmail.com>
parents: 10926
diff changeset
276 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
277
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20681
diff changeset
278 std::string nm = idx(0).xstring_value ("invalid index for class");
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
279
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
280 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
281
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
282 if (p == my_map.end ())
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
283 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
284
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
285 return 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
286 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
287
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
288 Matrix
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
289 octave_class::size (void)
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
290 {
9792
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
291 if (in_class_method () || called_from_builtin ())
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
292 return octave_base_value::size ();
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
293
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
294 Matrix retval (1, 2, 1.0);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
295 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
296
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
297 if (meth.is_defined ())
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
298 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
299 count++;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
300 octave_value_list args (1, octave_value (this));
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
301
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
302 octave_value_list lv = octave::feval (meth.function_value (), args, 1);
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
303 if (lv.length () <= 0
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
304 || ! lv(0).is_matrix_type () || ! lv(0).dims ().is_vector ())
9775
9d9f858849c7 Allow and ignore extra outargs from user-defined size methods
David Grundberg <davidg@cs.umu.se>
parents: 9774
diff changeset
305 error ("@%s/size: invalid return value", class_name ().c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
306
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
307 retval = lv(0).matrix_value ();
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
308 }
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
309 else
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
310 {
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
311 dim_vector dv = dims ();
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
312
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21580
diff changeset
313 int nd = dv.ndims ();
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
314
13784
0bbe319bf26b octave_class::size: return matrix with correct dimensions
John W. Eaton <jwe@octave.org>
parents: 13781
diff changeset
315 retval.resize (1, nd);
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
316
13784
0bbe319bf26b octave_class::size: return matrix with correct dimensions
John W. Eaton <jwe@octave.org>
parents: 13781
diff changeset
317 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
318 retval(i) = dv(i);
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
319 }
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
320
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
321 return retval;
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
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
324 octave_idx_type
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
325 octave_class::numel (const octave_value_list& idx)
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
326 {
9792
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
327 if (in_class_method () || called_from_builtin ())
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
328 return octave_base_value::numel (idx);
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
329
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
330 octave_idx_type retval = -1;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
331 const std::string cn = class_name ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
332
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
333 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
334
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
335 if (meth.is_defined ())
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
336 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
337 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
338
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
339 count++;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
340 args(0) = octave_value (this);
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 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
343 args(i+1) = idx(i);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
344
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
345 octave_value_list lv = octave::feval (meth.function_value (), args, 1);
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
346 if (lv.length () != 1 || ! lv(0).is_scalar_type ())
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
347 error ("@%s/numel: invalid return value", cn.c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
348
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
349 retval = lv(0).idx_type_value (true);
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
350 }
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
351 else
10106
edbe47bc0f88 make numel query more matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
352 retval = octave_base_value::numel (idx);
9329
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 return retval;
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
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
357 octave_value_list
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
358 octave_class::subsref (const std::string& type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
359 const std::list<octave_value_list>& idx,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
360 int nargout)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
361 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
362 octave_value_list retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
363
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
364 if (in_class_method () || called_from_builtin ())
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
365 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
366 // 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
367 // octave_struct::subsref. Maybe it could be shared instead of
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
368 // duplicated.
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
369
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
370 int skip = 1;
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
371
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
372 switch (type[0])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
373 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
374 case '(':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
375 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
376 if (type.length () > 1 && type[1] == '.')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
377 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
378 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
379 octave_value_list key_idx = *++p;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
380
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
381 Cell tmp = dotref (key_idx);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
382
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
383 Cell t = tmp.index (idx.front ());
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
384
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
385 retval(0) = (t.numel () == 1 ? t(0)
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
386 : octave_value (t, true));
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
387
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
388 // We handled two index elements, so tell
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
389 // next_subsref to skip both of them.
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
390 skip++;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
391 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
392 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
393 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
394 c_name, parent_list);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
395 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
396 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
397
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
398 case '.':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
399 {
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
400 if (map.numel () > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
401 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
402 Cell t = dotref (idx.front ());
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
403
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
404 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
405 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
406 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
407 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
408
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
409 case '{':
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
410 err_invalid_index_type (type_name (), type[0]);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
411 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
412
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
413 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
414 panic_impossible ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
415 }
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
416
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
417 // FIXME: perhaps there should be an
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
418 // octave_value_list::next_subsref member function? See also
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
419 // octave_user_function::subsref.
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
420
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
421 if (idx.size () > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
422 retval = retval(0).next_subsref (nargout, type, idx, skip);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
423 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
424 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
425 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
426 octave_value meth = symbol_table::find_method ("subsref", class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
427
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
428 if (meth.is_defined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
429 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
430 octave_value_list args;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
431
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
432 args(1) = make_idx_args (type, idx, "subsref");
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
433
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
434 count++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
435 args(0) = octave_value (this);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
436
9691
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
437 // 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
438 // 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
439 // 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
440 // 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
441 // 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
442 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
443 || (type.length () > 1 && type[0] == '('
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
444 && type[1] == '.'));
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
445
9691
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
446 int true_nargout = nargout;
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
447
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
448 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
449 {
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
450 // 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
451 octave_value_list tmp;
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
452 if (type[0] != '.') tmp = idx.front ();
9691
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
453 true_nargout = numel (tmp);
9331
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
454 }
9691
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
455
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
456 retval = octave::feval (meth.function_value (), args, true_nargout);
9691
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
457
23352
778fdffc09df deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents: 23351
diff changeset
458 // Since we're handling subsref, if the list has more than one
778fdffc09df deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents: 23351
diff changeset
459 // element, return it as a comma-separated list so that we can
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23405
diff changeset
460 // pass it to the evaluator
9691
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
461 if (retval.length () > 1)
23352
778fdffc09df deprecate "octave_value (octave_value_list, bool)" constructor
John W. Eaton <jwe@octave.org>
parents: 23351
diff changeset
462 retval = octave_value (retval);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
463 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
464 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
465 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
466 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
467 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
468 parent_list);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
469 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
470 err_invalid_index1 ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
471 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
472 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
473
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
474 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
475 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
476
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
477 octave_value
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
478 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
479 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
480 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
481
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
482 if (val.numel () != 1)
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
483 err_invalid_index_for_assignment ();
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
484
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
485 retval = val(0);
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
486
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
487 if (type.length () > 0 && type[0] == '.' && ! retval.is_map ())
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
488 retval = octave_map ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
489
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
490 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
491 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
492
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
493 octave_value
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
494 octave_class::subsasgn (const std::string& type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
495 const std::list<octave_value_list>& idx,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
496 const octave_value& rhs)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
497 {
12171
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
498 count++;
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
499 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
500 }
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
501
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
502 octave_value
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
503 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
504 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
505 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
506 {
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
507 // 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
508 // 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
509 // undefined.
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
510
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
511 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
512 }
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
513
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
514 octave_value
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
515 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
516 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
517 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
518 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
519 {
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
520 octave_value retval;
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
521
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
522 if (! (in_class_method () || called_from_builtin ()))
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
523 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
524 octave_value meth = symbol_table::find_method ("subsasgn", class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
525
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
526 if (meth.is_defined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
527 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
528 octave_value_list args;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
529
9333
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
530 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
531 {
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
532 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
533 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
534 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
535 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
536 }
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
537 else
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
538 args(2) = rhs;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
539
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
540 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
541 args(0) = obj;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
542
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21743
diff changeset
543 // Now comes the magic. Count copies with me:
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
544 // 1. myself (obsolete)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
545 // 2. the copy inside args (obsolete)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
546 // 3. the copy in method's symbol table (working)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
547 // ... possibly more (not obsolete).
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
548 //
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
549 // 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
550 // 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
551 // to the optimization.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
552 // It is essential that the handling function doesn't store extra
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21743
diff changeset
553 // copies anywhere. If it does, things will not break but the
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
554 // optimization won't work.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
555
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
556 octave_value_list tmp;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
557
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
558 if (obsolete_copies == 0 && meth.is_user_function ()
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
559 && meth.user_function_value ()->subsasgn_optimization_ok ())
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
560 {
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
561 octave::unwind_protect frame;
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
562 frame.protect_var (obsolete_copies);
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
563 obsolete_copies = 2;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
564
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
565 tmp = octave::feval (meth.function_value (), args);
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
566 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
567 else
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
568 tmp = octave::feval (meth.function_value (), args);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
569
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20700
diff changeset
570 // FIXME: Should the subsasgn method be able to return
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20700
diff changeset
571 // more than one value?
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
572
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
573 if (tmp.length () > 1)
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20700
diff changeset
574 error ("@%s/subsasgn returned more than one value",
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
575 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
576
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
577 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
578 retval = tmp(0);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
579
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
580 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
581 }
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
582 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
583
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
584 // 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
585 // attempting to do the indexed assignment.
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
586
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
587 std::string method_class = get_current_method_class ();
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
588
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
589 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
590 if (obvp != this)
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
591 {
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
592
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
593 if (! obvp)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
594 error ("malformed class");
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
595
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
596 obvp->subsasgn (type, idx, rhs);
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
597
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
598 count++;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
599 retval = octave_value (this);
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
600
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
601 return retval;
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
602 }
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
603
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
604 // 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
605 // octave_struct::subsasgn. Maybe it could be shared instead of
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
606 // duplicated.
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
607
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
608 int n = type.length ();
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
609
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
610 octave_value t_rhs = rhs;
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
611
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
612 if (n > 1 && ! (type.length () == 2 && type[0] == '(' && type[1] == '.'))
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
613 {
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
614 switch (type[0])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
615 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
616 case '(':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
617 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
618 if (type.length () > 1 && type[1] == '.')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
619 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
620 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
621 octave_value_list t_idx = *p;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
622
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
623 octave_value_list key_idx = *++p;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
624
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
625 assert (key_idx.length () == 1);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
626
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20681
diff changeset
627 std::string key = key_idx(0).xstring_value ("invalid index for class assignment");
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
628
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
629 octave_value u;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
630
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
631 if (! map.contains (key))
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
632 u = octave_value::empty_conv (type.substr (2), rhs);
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
633 else
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
634 {
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
635 Cell map_val = map.contents (key);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
636
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
637 Cell map_elt = map_val.index (idx.front (), true);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
638
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
639 u = numeric_conv (map_elt, type.substr (2));
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
640 }
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
641
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
642 std::list<octave_value_list> next_idx (idx);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
643
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
644 // We handled two index elements, so subsasgn to
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
645 // needs to skip both of them.
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
646
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
647 next_idx.erase (next_idx.begin ());
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
648 next_idx.erase (next_idx.begin ());
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
649
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
650 u.make_unique ();
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
651
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
652 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
653 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
654 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
655 err_invalid_index_for_assignment ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
656 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
657 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
658
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
659 case '.':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
660 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
661 octave_value_list key_idx = idx.front ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
662
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
663 assert (key_idx.length () == 1);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
664
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
665 std::string key = key_idx(0).string_value ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
666
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
667 std::list<octave_value_list> next_idx (idx);
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
668
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
669 next_idx.erase (next_idx.begin ());
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
670
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
671 std::string next_type = type.substr (1);
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
672
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
673 Cell tmpc (1, 1);
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
674 octave_map::iterator pkey = map.seek (key);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
675 if (pkey != map.end ())
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
676 {
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
677 map.contents (pkey).make_unique ();
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
678 tmpc = map.contents (pkey);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
679 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
680
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
681 // FIXME: better code reuse?
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
682 if (tmpc.numel () != 1)
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
683 err_indexed_cs_list ();
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
684
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
685 octave_value& tmp = tmpc(0);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
686
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
687 if (! tmp.is_defined () || tmp.is_zero_by_zero ())
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
688 {
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
689 tmp = octave_value::empty_conv (next_type, rhs);
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
690 tmp.make_unique (); // probably a no-op.
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
691 }
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
692 else
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
693 // optimization: ignore copy still stored inside our map.
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
694 tmp.make_unique (1);
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
695
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
696 t_rhs = tmp.subsasgn (next_type, next_idx, rhs);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
697 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
698 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
699
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
700 case '{':
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
701 err_invalid_index_type (type_name (), type[0]);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
702 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
703
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
704 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
705 panic_impossible ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
706 }
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
707 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
708
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
709 switch (type[0])
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
710 {
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
711 case '(':
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
712 {
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
713 if (n > 1 && type[1] == '.')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
714 {
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
715 std::list<octave_value_list>::const_iterator p = idx.begin ();
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
716 octave_value_list key_idx = *++p;
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
717
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
718 assert (key_idx.length () == 1);
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
719
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
720 std::string key = key_idx(0).xstring_value ("assignment to class element failed");
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
721
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
722 map.assign (idx.front (), key, t_rhs);
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
723
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
724 count++;
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
725 retval = octave_value (this);
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
726 }
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
727 else
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
728 {
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
729 if (t_rhs.is_object () || t_rhs.is_map ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
730 {
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
731 octave_map rhs_map = t_rhs.xmap_value ("invalid class assignment");
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
732
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
733 map.assign (idx.front (), rhs_map);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
734
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
735 count++;
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
736 retval = octave_value (this);
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
737 }
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
738 else
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
739 {
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
740 if (! t_rhs.is_empty ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
741 error ("invalid class assignment");
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
742
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
743 map.delete_elements (idx.front ());
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
744
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
745 count++;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
746 retval = octave_value (this);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
747 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
748 }
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
749 }
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
750 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
751
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
752 case '.':
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
753 {
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
754 octave_value_list key_idx = idx.front ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
755
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
756 assert (key_idx.length () == 1);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
757
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
758 std::string key = key_idx(0).string_value ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
759
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
760 if (t_rhs.is_cs_list ())
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
761 {
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
762 Cell tmp_cell = Cell (t_rhs.list_value ());
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
763
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
764 // The shape of the RHS is irrelevant, we just want
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
765 // the number of elements to agree and to preserve the
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
766 // shape of the left hand side of the assignment.
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
767
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
768 if (numel () == tmp_cell.numel ())
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
769 tmp_cell = tmp_cell.reshape (dims ());
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
770
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
771 map.setfield (key, tmp_cell);
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
772 }
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
773 else
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
774 {
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
775 Cell tmp_cell(1, 1);
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
776 tmp_cell(0) = t_rhs.storable_value ();
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
777 map.setfield (key, tmp_cell);
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
778 }
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
779
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
780 count++;
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
781 retval = octave_value (this);
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
782 }
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
783 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
784
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
785 case '{':
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
786 err_invalid_index_type (type_name (), type[0]);
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
787 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
788
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
789 default:
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
790 panic_impossible ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
791 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
792
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
793 return retval;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
794 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
795
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
796 idx_vector
18130
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 18033
diff changeset
797 octave_class::index_vector (bool require_integers) const
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
798 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
799 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
800
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
801 if (! meth.is_defined ())
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
802 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
803 class_name ().c_str ());
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
804
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
805 octave_value_list args;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
806 args(0) = octave_value (new octave_class (map, c_name, parent_list));
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
807
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
808 octave_value_list tmp = octave::feval (meth.function_value (), args, 1);
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
809
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
810 if (tmp(0).is_object ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
811 error ("subsindex function must return a valid index vector");
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
812
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
813 // Index vector returned by subsindex is zero based
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
814 // (why this inconsistency Mathworks?), and so we must
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
815 // add one to the value returned as the index_vector method
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
816 // expects it to be one based.
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
817 return do_binary_op (octave_value::op_add, tmp (0),
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
818 octave_value (1.0)).index_vector (require_integers);
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
819 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
820
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
821 size_t
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
822 octave_class::byte_size (void) const
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
823 {
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
824 // Neglect the size of the fieldnames.
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
825
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
826 size_t retval = 0;
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
827
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
828 for (octave_map::const_iterator it = map.begin (); it != map.end (); it++)
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
829 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
830 std::string key = map.key (it);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
831
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
832 octave_value val = octave_value (map.contents (it));
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
833
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
834 retval += val.byte_size ();
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
835 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
836
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
837 return retval;
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
838 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
839
21725
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
840 bool
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
841 octave_class::is_true (void) const
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
842 {
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
843 bool retval = false;
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
844
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
845 octave_value meth = symbol_table::find_method ("logical", class_name ());
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
846
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
847 if (meth.is_defined ())
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
848 {
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
849 octave_value in = new octave_class (*this);
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
850
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
851 octave_value_list tmp = octave::feval (meth.function_value (), in, 1);
21725
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
852 retval = tmp(0).is_true ();
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
853 }
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
854
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
855 return retval;
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
856 }
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
857
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
858 string_vector
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
859 octave_class::map_keys (void) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
860 {
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
861 err_wrong_type_arg ("octave_class::map_keys()", type_name ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
862 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
863
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
864 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
865 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
866 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
867 octave_base_value *retval = nullptr;
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
868
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
869 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
870 retval = this;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
871 else
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
872 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
873 for (auto& par : parent_list)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
874 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
875 octave_map::const_iterator smap = map.seek (par);
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
876
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
877 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
878
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
879 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
880
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
881 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
882
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
883 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
884
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
885 if (retval)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
886 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
887 }
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
888 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
889
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
890 return retval;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
891 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
892
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
893 octave_base_value *
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
894 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
895 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
896 octave_base_value *retval = nullptr;
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
897
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
898 if (parent_class_name == class_name ())
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
899 retval = this;
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
900 else
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
901 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
902 for (auto& par : parent_list)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
903 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
904 octave_map::iterator smap = map.seek (par);
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
905
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
906 Cell& tmp = map.contents (smap);
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
907
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
908 octave_value& vtmp = tmp(0);
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
909
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
910 octave_base_value *obvp = vtmp.internal_rep ();
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
911
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
912 // 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
913 retval = obvp->find_parent_class (parent_class_name);
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
914
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
915 if (retval)
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
916 {
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
917 vtmp.make_unique ();
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
918 obvp = vtmp.internal_rep ();
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
919 retval = obvp->unique_parent_class (parent_class_name);
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
920
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
921 break;
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
922 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
923 }
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
924 }
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
925
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
926 return retval;
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
927 }
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
928
19103
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
929 bool
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
930 octave_class::is_instance_of (const std::string& cls_name) const
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
931 {
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
932 bool retval = false;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
933
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
934 if (cls_name == class_name ())
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
935 retval = true;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
936 else
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
937 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
938 for (auto& par : parent_list)
19103
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
939 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
940 octave_map::const_iterator smap = map.seek (par);
19103
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
941
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
942 const Cell& tmp = map.contents (smap);
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
943
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
944 const octave_value& vtmp = tmp(0);
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
945
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
946 retval = vtmp.is_instance_of (cls_name);
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
947
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
948 if (retval)
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
949 break;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
950 }
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
951 }
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
952
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
953 return retval;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
954 }
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
955
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
956 string_vector
20990
fc9cca99b2de Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents: 20979
diff changeset
957 octave_class::string_vector_value (bool pad) const
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
958 {
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
959 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
960
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
961 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
962
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
963 if (! meth.is_defined ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
964 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
965
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
966 octave_value_list args;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
967 args(0) = octave_value (new octave_class (map, c_name, parent_list));
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
968
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
969 octave_value_list tmp = octave::feval (meth.function_value (), args, 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
970
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
971 if (tmp.length () >= 1)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
972 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
973 if (! tmp(0).is_string ())
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
974 error ("cname/char method did not return a string");
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
975
20990
fc9cca99b2de Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents: 20979
diff changeset
976 retval = tmp(0).string_vector_value (pad);
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
977 }
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
978
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
979 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
980 }
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
981
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
982 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18409
diff changeset
983 octave_class::print (std::ostream& os, bool)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
984 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
985 print_raw (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
986 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
987
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
988 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
989 octave_class::print_raw (std::ostream& os, bool) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
990 {
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
991 octave::unwind_protect frame;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
992
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
993 indent (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
994 os << " <class " << class_name () << ">";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
995 newline (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
996 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
997
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
998 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
999 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
1000 {
23351
5ea6c6d0c2db Use octave_base_value::print_name_tag for old style classes (bug #50640).
Rik <rik@octave.org>
parents: 23220
diff changeset
1001 return octave_base_value::print_name_tag (os, name);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1002 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1003
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1004 void
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1005 octave_class::print_with_name (std::ostream& os, const std::string& name,
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22871
diff changeset
1006 bool print_padding)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1007 {
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22871
diff changeset
1008 octave_base_value::print_with_name (os, name, print_padding);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1009 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1010
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1011 // 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
1012 // 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
1013 // with no arguments.
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1014 bool
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1015 octave_class::reconstruct_exemplar (void)
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1016 {
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1017 bool retval = false;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1018
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1019 octave_class::exemplar_const_iterator it
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1020 = octave_class::exemplar_map.find (c_name);
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1021
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1022 if (it != octave_class::exemplar_map.end ())
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1023 retval = true;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1024 else
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1025 {
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1026 octave_value ctor = symbol_table::find_method (c_name, c_name);
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1027
12178
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1028 bool have_ctor = false;
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1029
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1030 if (ctor.is_defined () && ctor.is_function ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1031 {
12178
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1032 octave_function *fcn = ctor.function_value ();
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1033
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1034 if (fcn && fcn->is_class_constructor (c_name))
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1035 have_ctor = true;
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1036
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1037 // Something has gone terribly wrong if
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1038 // 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
1039 // a class constructor for the class c_name...
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1040 assert (have_ctor);
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1041 }
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1042
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1043 if (have_ctor)
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1044 {
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
1045 octave::unwind_protect frame;
17473
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1046
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1047 // 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
1048
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1049 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
1050
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1051 bool execution_error = false;
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1052
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1053 octave_value_list result;
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1054
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1055 try
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1056 {
23501
1ee4b394a687 use feval instead of do_multi_index_op
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
1057 result = octave::feval (ctor, ovl (), 1);
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1058 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1059 catch (const octave::execution_exception&)
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1060 {
23110
af48d8be62b3 move recover_from_exception and atexit functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23084
diff changeset
1061 octave::interpreter::recover_from_exception ();
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20747
diff changeset
1062
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1063 execution_error = true;
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1064 }
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1065
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1066 if (! execution_error && result.length () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1067 retval = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1068 }
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1069 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1070 warning ("no constructor for class %s", c_name.c_str ());
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1071 }
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1072
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1073 return retval;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1074 }
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1075
9240
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1076 void
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1077 octave_class::clear_exemplar_map (void)
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1078 {
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1079 exemplar_map.clear ();
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1080 }
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1081
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1082 // 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
1083 // class inheritance structure. reconstruct_parents () attempts to
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1084 // 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
1085 //
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1086 // 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
1087 // 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
1088 // to do its magic.
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1089 bool
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1090 octave_class::reconstruct_parents (void)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1091 {
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 18033
diff changeset
1092 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
1093 bool might_have_inheritance = false;
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1094 std::string dbgstr = "dork";
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1095
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1096 // First, check to see if there might be an issue with inheritance.
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
1097 for (octave_map::const_iterator it = map.begin (); it != map.end (); it++)
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1098 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
1099 std::string key = map.key (it);
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
1100 Cell val = map.contents (it);
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18637
diff changeset
1101 if (val(0).is_object ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1102 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1103 dbgstr = "blork";
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18637
diff changeset
1104 if (key == val(0).class_name ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1105 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1106 might_have_inheritance = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1107 dbgstr = "cork";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1108 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1109 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1110 }
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1111 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1112
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1113 if (might_have_inheritance)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1114 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1115 octave_class::exemplar_const_iterator it
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1116 = 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
1117
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1118 if (it == octave_class::exemplar_map.end ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1119 retval = false;
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1120 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1121 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1122 octave_class::exemplar_info exmplr = it->second;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1123 parent_list = exmplr.parents ();
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
1124 for (auto& par : parent_list)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1125 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
1126 dbgstr = par;
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
1127 bool dbgbool = map.contains (par);
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20939
diff changeset
1128 if (! dbgbool)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1129 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1130 retval = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1131 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1132 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1133 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1134 }
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1135 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1136
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1137 return retval;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1138 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1139
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1140 bool
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1141 octave_class::save_ascii (std::ostream& os)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1142 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1143 os << "# classname: " << class_name () << "\n";
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1144 octave_map m;
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1145
23445
8e310ef0fa97 move load_path class to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23438
diff changeset
1146 octave::load_path& lp = octave::__get_load_path__ ("octave_class::save_ascii");
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1147
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1148 if (lp.find_method (class_name (), "saveobj") != "")
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1149 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1150 octave_value in = new octave_class (*this);
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1151 octave_value_list tmp = octave::feval ("saveobj", in, 1);
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1152
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1153 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
1154 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1155 else
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1156 m = map_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1157
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1158 os << "# length: " << m.nfields () << "\n";
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1159
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1160 octave_map::iterator i = m.begin ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1161 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1162 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1163 octave_value val = map.contents (i);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1164
20447
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20232
diff changeset
1165 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
1166
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1167 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
1168 return ! os.fail ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1169
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1170 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1171 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1172
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1173 return true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1174 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1175
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1176 bool
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1177 octave_class::load_ascii (std::istream& is)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1178 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1179 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
1180 std::string classname;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1181
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1182 if (! extract_keyword (is, "classname", classname) || classname.empty ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1183 error ("load: failed to extract name of class");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1184
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1185 if (! extract_keyword (is, "length", len) || len < 0)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1186 error ("load: failed to extract number of elements in class");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1187
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1188 if (len > 0)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1189 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1190 octave_map m (map);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1191
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1192 for (octave_idx_type j = 0; j < len; j++)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1193 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1194 octave_value t2;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1195 bool dummy;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1196
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1197 // recurse to read cell elements
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1198 std::string nm
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20990
diff changeset
1199 = read_text_data (is, "", dummy, t2, j);
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1200
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1201 if (! is)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1202 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1203
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
1204 Cell tcell = (t2.is_cell () ? t2.xcell_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
1205
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1206 m.assign (nm, tcell);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1207 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1208
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1209 if (! is)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1210 error ("load: failed to load class");
17473
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1211
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1212 c_name = classname;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1213 reconstruct_exemplar ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1214
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1215 map = m;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1216
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1217 if (! reconstruct_parents ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1218 warning ("load: unable to reconstruct object inheritance");
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1219
23445
8e310ef0fa97 move load_path class to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23438
diff changeset
1220 octave::load_path& lp = octave::__get_load_path__ ("octave_class::load_ascii");
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1221
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1222 if (lp.find_method (classname, "loadobj") != "")
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1223 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1224 octave_value in = new octave_class (*this);
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1225 octave_value_list tmp = octave::feval ("loadobj", in, 1);
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1226
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1227 map = tmp(0).map_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1228 }
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1229 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1230 else if (len == 0)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1231 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1232 map = octave_map (dim_vector (1, 1));
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1233 c_name = classname;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1234 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1235 else
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1236 panic_impossible ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1237
20879
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
1238 return true;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1239 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1240
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1241 bool
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1242 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
1243 {
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
1244 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
1245
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1246 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
1247 os << class_name ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1248
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1249 octave_map m;
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1250
23445
8e310ef0fa97 move load_path class to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23438
diff changeset
1251 octave::load_path& lp = octave::__get_load_path__ ("octave_class::save_binary");
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1252
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1253 if (lp.find_method (class_name (), "saveobj") != "")
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1254 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1255 octave_value in = new octave_class (*this);
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1256 octave_value_list tmp = octave::feval ("saveobj", in, 1);
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1257
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1258 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
1259 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1260 else
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1261 m = map_value ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1262
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
1263 int32_t len = m.nfields ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1264 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
1265
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1266 octave_map::iterator i = m.begin ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1267 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1268 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1269 octave_value val = map.contents (i);
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 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
1272
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1273 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
1274 return ! os.fail ();
7338
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 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1277 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1278
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1279 return true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1280 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1281
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1282 bool
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1283 octave_class::load_binary (std::istream& is, bool swap,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21725
diff changeset
1284 octave::mach_info::float_format fmt)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1285 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1286 bool success = true;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1287
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1288 int32_t classname_len;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1289
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1290 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
1291 if (! is)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1292 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1293 else if (swap)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1294 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
1295
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1296 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1297 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
1298 classname[classname_len] = '\0';
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1299 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
1300 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1301 c_name = classname;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1302 }
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1303 reconstruct_exemplar ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1304
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1305 int32_t len;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1306 if (! is.read (reinterpret_cast<char *> (&len), 4))
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1307 return false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1308 if (swap)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1309 swap_bytes<4> (&len);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1310
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1311 if (len > 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1312 {
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1313 octave_map m (map);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1314
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1315 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
1316 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1317 octave_value t2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1318 bool dummy;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1319 std::string doc;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1320
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1321 // recurse to read cell elements
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20990
diff changeset
1322 std::string nm = read_binary_data (is, swap, fmt, "",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1323 dummy, t2, doc);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1324
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1325 if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1326 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1327
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
1328 Cell tcell = (t2.is_cell () ? t2.xcell_value ("load: internal error loading class elements") : Cell (t2));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1329
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1330 m.assign (nm, tcell);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1331 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1332
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1333 if (is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1334 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1335 map = m;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1336
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1337 if (! reconstruct_parents ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1338 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
1339
23445
8e310ef0fa97 move load_path class to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23438
diff changeset
1340 octave::load_path& lp = octave::__get_load_path__ ("octave_class::load_binary");
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1341
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1342 if (lp.find_method (c_name, "loadobj") != "")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1343 {
17473
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1344 octave_value in = new octave_class (*this);
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1345 octave_value_list tmp = octave::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
1346
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1347 map = tmp(0).map_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1348 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1349 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1350 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1351 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1352 warning ("load: failed to load class");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1353 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1354 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1355 }
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18637
diff changeset
1356 else if (len == 0)
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1357 map = octave_map (dim_vector (1, 1));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1358 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1359 panic_impossible ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1360
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1361 return success;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1362 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1363
19863
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: 19697
diff changeset
1364 bool
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1365 octave_class::save_hdf5 (octave_hdf5_id loc_id, const char *name,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1366 bool save_as_floats)
19863
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: 19697
diff changeset
1367 {
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1368 #if defined (HAVE_HDF5)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1369
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1370 hsize_t hdims[3];
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1371 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
1372 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
1373 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
1374 hid_t class_hid = -1;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1375 hid_t data_hid = -1;
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1376 octave_map m;
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1377 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
1378
23445
8e310ef0fa97 move load_path class to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23438
diff changeset
1379 octave::load_path& lp = octave::__get_load_path__ ("octave_class::save_hdf5");
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1380
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1381 #if defined (HAVE_HDF5_18)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1382 group_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT, octave_H5P_DEFAULT,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1383 octave_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
1384 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1385 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
1386 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1387 if (group_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1388 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1389
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1390 // 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
1391 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
1392 if (type_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1393 goto error_cleanup;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1394
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1395 hdims[0] = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1396 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
1397 if (space_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1398 goto error_cleanup;
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1399 #if defined (HAVE_HDF5_18)
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
1400 class_hid = H5Dcreate (group_hid, "classname", type_hid, space_hid,
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1401 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1402 octave_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
1403 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1404 class_hid = H5Dcreate (group_hid, "classname", type_hid, space_hid,
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
1405 octave_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
1406 #endif
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1407 if (class_hid < 0 || H5Dwrite (class_hid, type_hid, octave_H5S_ALL,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1408 octave_H5S_ALL, octave_H5P_DEFAULT,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1409 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
1410 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1411
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1412 #if defined (HAVE_HDF5_18)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1413 data_hid = H5Gcreate (group_hid, "value", octave_H5P_DEFAULT,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1414 octave_H5P_DEFAULT, octave_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
1415 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1416 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
1417 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1418 if (data_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1419 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1420
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1421 if (lp.find_method (class_name (), "saveobj") != "")
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1422 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1423 octave_value in = new octave_class (*this);
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1424 octave_value_list tmp = octave::feval ("saveobj", in, 1);
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1425
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1426 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
1427 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1428 else
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1429 m = map_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1430
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1431 // 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
1432 i = m.begin ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1433 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1434 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1435 octave_value val = map.contents (i);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1436
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1437 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
1438 save_as_floats);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1439
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1440 if (! retval2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1441 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1442
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1443 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1444 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1445
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1446 error_cleanup:
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1447
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1448 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1449 H5Gclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1450
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1451 if (class_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1452 H5Dclose (class_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1453
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1454 if (space_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1455 H5Sclose (space_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1456
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1457 if (type_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1458 H5Tclose (type_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1459
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1460 if (group_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1461 H5Gclose (group_hid);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1462
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1463 return true;
19863
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: 19697
diff changeset
1464
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: 19697
diff changeset
1465 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1466 octave_unused_parameter (loc_id);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1467 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1468 octave_unused_parameter (save_as_floats);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1469
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
1470 warn_save ("hdf5");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1471
19863
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: 19697
diff changeset
1472 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: 19697
diff changeset
1473 #endif
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1474 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1475
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1476 bool
19863
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: 19697
diff changeset
1477 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
1478 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1479 bool retval = false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1480
19863
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: 19697
diff changeset
1481 #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: 19697
diff changeset
1482
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1483 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
1484 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
1485 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
1486 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
1487 hid_t space_hid = -1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1488 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
1489 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
1490
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1491 hdf5_callback_data dsub;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1492
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1493 herr_t retval2 = 0;
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1494 octave_map m (dim_vector (1, 1));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1495 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
1496 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
1497 int slen = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1498 hsize_t rank = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1499
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1500 #if defined (HAVE_HDF5_18)
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
1501 group_hid = H5Gopen (loc_id, name, octave_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
1502 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1503 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
1504 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1505 if (group_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1506 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1507
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1508 #if defined (HAVE_HDF5_18)
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
1509 data_hid = H5Dopen (group_hid, "classname", octave_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
1510 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1511 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
1512 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1513
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1514 if (data_hid < 0)
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
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1517 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
1518
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1519 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
1520
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1521 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
1522 goto error_cleanup;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1523
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1524 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
1525 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
1526
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1527 if (rank != 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1528 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1529
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1530 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
1531 if (slen < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1532 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1533
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1534 // 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
1535 do
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1536 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1537 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
1538
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1539 // 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
1540 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
1541 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
1542
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1543 if (H5Dread (data_hid, st_id, octave_H5S_ALL, octave_H5S_ALL,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1544 octave_H5P_DEFAULT, classname)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1545 < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1546 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1547 H5Tclose (st_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1548 H5Dclose (data_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1549 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1550 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1551 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1552
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1553 H5Tclose (st_id);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1554 H5Dclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1555 data_hid = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1556
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1557 c_name = classname;
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 while (0);
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1560 reconstruct_exemplar ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1561
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1562 #if defined (HAVE_HDF5_18)
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
1563 subgroup_hid = H5Gopen (group_hid, name, octave_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
1564 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1565 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
1566 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1567 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
1568 H5Gclose (subgroup_hid);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1569
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1570 while (current_item < static_cast<int> (num_obj)
22028
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
1571 && (retval2 = hdf5_h5g_iterate (group_hid, name, &current_item,
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 22022
diff changeset
1572 &dsub)) > 0)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1573 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1574 octave_value t2 = dsub.tc;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1575
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
1576 Cell tcell = (t2.is_cell () ? t2.xcell_value ("load: internal error loading class elements") : Cell (t2));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1577
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1578 m.assign (dsub.name, tcell);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1579
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1580 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1581
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1582 if (retval2 >= 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1583 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1584 map = m;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1585
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20939
diff changeset
1586 if (! reconstruct_parents ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1587 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
1588
23445
8e310ef0fa97 move load_path class to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23438
diff changeset
1589 octave::load_path& lp = octave::__get_load_path__ ("octave_class::load_hdf5");
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1590
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1591 if (lp.find_method (c_name, "loadobj") != "")
17473
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1592 {
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1593 octave_value in = new octave_class (*this);
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23052
diff changeset
1594 octave_value_list tmp = octave::feval ("loadobj", in, 1);
17473
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1595
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1596 map = tmp(0).map_value ();
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1597 retval = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1598 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1599 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1600
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1601 error_cleanup:
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1602 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1603 H5Dclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1604
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1605 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1606 H5Gclose (group_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1607
19863
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: 19697
diff changeset
1608 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1609 octave_unused_parameter (loc_id);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1610 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1611
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
1612 warn_load ("hdf5");
19863
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: 19697
diff changeset
1613 #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: 19697
diff changeset
1614
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1615 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1616 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1617
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1618 mxArray *
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1619 octave_class::as_mxArray (void) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1620 {
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
1621 err_wrong_type_arg ("octave_class::as_mxArray ()", type_name ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1622 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1623
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1624 bool
9581
3d0d2bda3a0f fix previous change, avoid duplicate loads of methods in descendant classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9580
diff changeset
1625 octave_class::in_class_method (void)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1626 {
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
1627 octave_function *fcn = octave::call_stack::current ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1628
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1629 return (fcn
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1630 && (fcn->is_class_method ()
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1631 || fcn->is_class_constructor ()
13241
2a8dcb5b3a00 improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents: 13112
diff changeset
1632 || fcn->is_anonymous_function_of_class ()
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1633 || fcn->is_private_function_of_class (class_name ()))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1634 && find_parent_class (fcn->dispatch_class ()));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1635 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1636
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1637 octave_class::exemplar_info::exemplar_info (const octave_value& obj)
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1638 : field_names (), parent_class_names ()
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1639 {
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1640 if (! obj.is_object ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1641 error ("invalid call to exemplar_info constructor");
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1642
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1643 octave_map m = obj.map_value ();
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1644 field_names = m.keys ();
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1645
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1646 parent_class_names = obj.parent_class_name_list ();
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1647 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1648
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1649 // A map from class names to lists of fields.
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1650 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
1651
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1652 bool
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1653 octave_class::exemplar_info::compare (const octave_value& obj) const
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1654 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1655
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1656 if (! obj.is_object ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1657 error ("invalid comparison of class exemplar to non-class object");
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1658
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1659 if (nfields () != obj.nfields ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1660 error ("mismatch in number of fields");
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1661
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1662 octave_map obj_map = obj.map_value ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1663 string_vector obj_fnames = obj_map.keys ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1664 string_vector fnames = fields ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1665
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1666 for (octave_idx_type i = 0; i < nfields (); i++)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1667 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1668 if (obj_fnames[i] != fnames[i])
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1669 error ("mismatch in field names");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1670 }
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1671
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1672 if (nparents () != obj.nparents ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1673 error ("mismatch in number of parent classes");
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1674
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1675 std::list<std::string> obj_parents
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1676 = obj.parent_class_name_list ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1677 std::list<std::string> pnames = parents ();
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1678
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1679 std::list<std::string>::const_iterator p = obj_parents.begin ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1680 std::list<std::string>::const_iterator q = pnames.begin ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1681
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1682 while (p != obj_parents.end ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1683 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1684 if (*p++ != *q++)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1685 error ("mismatch in parent classes");
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1686 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1687
20879
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
1688 return true;
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1689 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1690
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1691 DEFUN (class, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1692 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1693 @deftypefn {} {@var{classname} =} class (@var{obj})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1694 @deftypefnx {} {} class (@var{s}, @var{id})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1695 @deftypefnx {} {} class (@var{s}, @var{id}, @var{p}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1696 Return the class of the object @var{obj}, or create a class with
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1697 fields from structure @var{s} and name (string) @var{id}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1698
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1699 Additional arguments name a list of parent classes from which the new class
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1700 is derived.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1701 @seealso{typeinfo, isa}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1702 @end deftypefn */)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1703 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1704 int nargin = args.length ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1705
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1706 if (nargin == 0)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1707 print_usage ();
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1708
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1709 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1710
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1711 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
1712 // 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
1713 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
1714 else
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1715 {
15811
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1716 // Called as class constructor
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20681
diff changeset
1717 std::string id = args(1).xstring_value ("class: ID (class name) must be a string");
20580
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20561
diff changeset
1718
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
1719 octave_function *fcn = octave::call_stack::caller ();
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1720
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1721 if (! fcn)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1722 error ("class: invalid call from outside class constructor or method");
20580
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20561
diff changeset
1723
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1724 if (! fcn->is_class_constructor (id) && ! fcn->is_class_method (id))
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1725 error ("class: '%s' is invalid as a class name in this context",
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1726 id.c_str ());
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1727
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1728 octave_map m = args(0).xmap_value ("class: S must be a valid structure");
11220
883b9308353c allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents: 10932
diff changeset
1729
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1730 if (nargin == 2)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1731 retval
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1732 = octave_value (new octave_class (m, id, std::list<std::string> ()));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1733 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1734 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1735 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
1736
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1737 retval = octave_value (new octave_class (m, id, parents));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1738 }
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1739
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1740 octave_class::exemplar_const_iterator it
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1741 = octave_class::exemplar_map.find (id);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1742
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1743 if (it == octave_class::exemplar_map.end ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1744 octave_class::exemplar_map[id] = octave_class::exemplar_info (retval);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1745 else if (! it->second.compare (retval))
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1746 error ("class: object of class '%s' does not match previously constructed objects",
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1747 id.c_str ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1748 }
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1749
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1750 return retval;
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1751 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1752
15811
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1753 /*
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1754 %!assert (class (1.1), "double")
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1755 %!assert (class (single (1.1)), "single")
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1756 %!assert (class (uint8 (1)), "uint8")
23405
32ec90068be5 use %!testif runtime tests to properly skip java tests
John W. Eaton <jwe@octave.org>
parents: 23352
diff changeset
1757 %!testif HAVE_JAVA; usejava ("jvm")
15811
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1758 %! 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
1759 %! 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
1760
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22497
diff changeset
1761 ## Test Input Validation
15811
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1762 %!error class ()
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1763 */
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1764
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1765 DEFUN (isa, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1766 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1767 @deftypefn {} {} isa (@var{obj}, @var{classname})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1768 Return true if @var{obj} is an object from the class @var{classname}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1769
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1770 @var{classname} may also be one of the following class categories:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1771
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1772 @table @asis
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1773 @item @qcode{"float"}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1774 Floating point value comprising classes @qcode{"double"} and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1775 @qcode{"single"}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1776
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1777 @item @qcode{"integer"}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1778 Integer value comprising classes (u)int8, (u)int16, (u)int32, (u)int64.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1779
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1780 @item @qcode{"numeric"}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1781 Numeric value comprising either a floating point or integer value.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1782 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1783
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1784 If @var{classname} is a cell array of string, a logical array of the same
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1785 size is returned, containing true for each class to which @var{obj}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1786 belongs to.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1787
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1788 @seealso{class, typeinfo}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1789 @end deftypefn */)
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1790 {
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1791 if (args.length () != 2)
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1792 print_usage ();
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1793
20495
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1794 octave_value obj = args(0); // not const because of find_parent_class ()
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1795 std::string obj_cls = obj.class_name ();
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20681
diff changeset
1796 Array<std::string> clsnames = args(1).xcellstr_value ("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
1797
20495
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1798 boolNDArray matches (clsnames.dims (), false);
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1799
20495
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1800 for (octave_idx_type idx = 0; idx < clsnames.numel (); idx++)
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1801 {
20495
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1802 std::string cls = clsnames(idx);
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1803 if (obj_cls == cls
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1804 || (cls == "float" && obj.is_float_type ())
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1805 || (cls == "integer" && obj.is_integer_type ())
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1806 || (cls == "numeric" && obj.is_numeric_type ())
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1807 || 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
1808 matches(idx) = true;
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1809 }
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1810
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1811 return ovl (matches);
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1812 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1813
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1814 /*
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1815 %!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
1816 %!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
1817 %!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
1818 %!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
1819 %!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
1820 %!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
1821 %!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
1822 %!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
1823 %!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
1824 %!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
1825 %!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
1826 %!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
1827 %!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
1828 %!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
1829 %!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
1830 %!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
1831 %!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
1832 %!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
1833 %!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
1834 %!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
1835 %!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
1836 %!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
1837 %!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
1838 %!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
1839 %!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
1840 %!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
1841 %!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
1842 %!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
1843
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1844 %!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
1845 %!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
1846 %!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
1847 %!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
1848 %!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
1849 %!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
1850 %!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
1851 %!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
1852 %!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
1853 %!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
1854 %!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
1855 %!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
1856 %!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
1857 %!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
1858 %!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
1859
23405
32ec90068be5 use %!testif runtime tests to properly skip java tests
John W. Eaton <jwe@octave.org>
parents: 23352
diff changeset
1860 %!testif HAVE_JAVA; usejava ("jvm")
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19864
diff changeset
1861 %! ## 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: 19864
diff changeset
1862 %! ## 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: 19864
diff changeset
1863 %! ## 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: 19864
diff changeset
1864 %! ## will fail). So we test this too.
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21562
diff changeset
1865 %! assert (isa (javaObject ("java.lang.Double", 10), "java.lang.Number"));
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21562
diff changeset
1866 %! assert (isa (javaObject ("java.lang.Double", 10), "not_a_class"), false);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21562
diff changeset
1867 %! assert (isa (javaObject ("java.lang.Double", 10), "java.lang.Number"));
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19864
diff changeset
1868
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1869 %!test
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1870 %! 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
1871 %! 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
1872 */
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1873
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1874 DEFUN (__parent_classes__, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1875 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1876 @deftypefn {} {} __parent_classes__ (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1877 Undocumented internal function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1878 @end deftypefn */)
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1879 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1880 if (args.length () != 1)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1881 print_usage ();
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1882
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1883 octave_value arg = args(0);
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1884
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1885 if (arg.is_object ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1886 return ovl (Cell (arg.parent_class_names ()));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1887 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1888 return ovl (Cell ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1889 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1890
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1891 DEFUN (isobject, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1892 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1893 @deftypefn {} {} isobject (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1894 Return true if @var{x} is a class object.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1895 @seealso{class, typeinfo, isa, ismethod, isprop}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1896 @end deftypefn */)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1897 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1898 if (args.length () != 1)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1899 print_usage ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1900
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1901 return ovl (args(0).is_object ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1902 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1903
23519
4fe410bd918d use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents: 23501
diff changeset
1904 DEFMETHOD (ismethod, interp, args, ,
4fe410bd918d use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents: 23501
diff changeset
1905 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1906 @deftypefn {} {} ismethod (@var{obj}, @var{method})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1907 @deftypefnx {} {} ismethod (@var{clsname}, @var{method})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1908 Return true if the string @var{method} is a valid method of the object
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1909 @var{obj} or of the class @var{clsname}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1910 @seealso{isprop, isobject}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1911 @end deftypefn */)
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1912 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1913 if (args.length () != 2)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1914 print_usage ();
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1915
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1916 octave_value arg = args(0);
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1917
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1918 std::string class_name;
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1919
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1920 if (arg.is_object ())
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1921 class_name = arg.class_name ();
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1922 else if (arg.is_string ())
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1923 class_name = arg.string_value ();
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1924 else
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1925 error ("ismethod: first argument must be object or class name");
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1926
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1927 std::string method = args(1).string_value ();
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1928
23519
4fe410bd918d use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents: 23501
diff changeset
1929 octave::load_path& lp = interp.get_load_path ();
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1930
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1931 if (lp.find_method (class_name, method) != "")
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1932 return ovl (true);
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1933 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1934 return ovl (false);
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1935 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1936
23519
4fe410bd918d use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents: 23501
diff changeset
1937 DEFMETHOD (__methods__, interp, args, ,
4fe410bd918d use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents: 23501
diff changeset
1938 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1939 @deftypefn {} {} __methods__ (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1940 @deftypefnx {} {} __methods__ ("classname")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1941 Internal function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1942
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1943 Implements @code{methods} for Octave class objects and classnames.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1944 @seealso{methods}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1945 @end deftypefn */)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1946 {
15785
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
1947 // 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
1948 octave_value arg = args(0);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1949
15785
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
1950 std::string class_name;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1951
15785
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
1952 if (arg.is_object ())
42cff4396de4 Add methods.m which extends methods() to work on Java objects.
Rik <rik@octave.org>
parents: 15467
diff changeset
1953 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
1954 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
1955 class_name = arg.string_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1956
23519
4fe410bd918d use DEFMETHOD for some built-in functions
John W. Eaton <jwe@octave.org>
parents: 23501
diff changeset
1957 octave::load_path& lp = interp.get_load_path ();
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1958
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1959 string_vector sv = lp.methods (class_name);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1960
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1961 return ovl (Cell (sv));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1962 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1963
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1964 static bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1965 is_built_in_class (const std::string& cn)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1966 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1967 static std::set<std::string> built_in_class_names;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1968
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1969 if (built_in_class_names.empty ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1970 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1971 built_in_class_names.insert ("double");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1972 built_in_class_names.insert ("single");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1973 built_in_class_names.insert ("cell");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1974 built_in_class_names.insert ("struct");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1975 built_in_class_names.insert ("logical");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1976 built_in_class_names.insert ("char");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1977 built_in_class_names.insert ("function handle");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1978 built_in_class_names.insert ("int8");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1979 built_in_class_names.insert ("uint8");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1980 built_in_class_names.insert ("int16");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1981 built_in_class_names.insert ("uint16");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1982 built_in_class_names.insert ("int32");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1983 built_in_class_names.insert ("uint32");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1984 built_in_class_names.insert ("int64");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1985 built_in_class_names.insert ("uint64");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1986 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1987
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1988 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
1989 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1990
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1991 DEFUN (superiorto, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1992 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1993 @deftypefn {} {} superiorto (@var{class_name}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1994 When called from a class constructor, mark the object currently constructed
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1995 as having a higher precedence than @var{class_name}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1996
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1997 More that one such class can be specified in a single call. This function
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1998 may @emph{only} be called from a class constructor.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1999 @seealso{inferiorto}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2000 @end deftypefn */)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2001 {
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
2002 octave_function *fcn = octave::call_stack::caller ();
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
2003 if (! fcn || ! fcn->is_class_constructor ())
20879
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
2004 error ("superiorto: invalid call from outside class constructor");
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2005
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2006 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
2007 {
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20700
diff changeset
2008 std::string inf_class = args(i).xstring_value ("superiorto: CLASS_NAME must be a string");
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2009
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2010 // 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
2011 // 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
2012 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
2013 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2014
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2015 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
2016 if (! symbol_table::set_class_relationship (sup_class, inf_class))
20879
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
2017 error ("superiorto: opposite precedence already set for %s and %s",
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
2018 sup_class.c_str (), inf_class.c_str ());
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2019 }
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2020
21125
8f76684324b5 maint: change "return octave_value ()" to "return ovl ()".
Rik <rik@octave.org>
parents: 21118
diff changeset
2021 return ovl ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2022 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2023
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2024 DEFUN (inferiorto, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2025 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2026 @deftypefn {} {} inferiorto (@var{class_name}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2027 When called from a class constructor, mark the object currently constructed
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2028 as having a lower precedence than @var{class_name}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2029
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2030 More that one such class can be specified in a single call. This function
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2031 may @emph{only} be called from a class constructor.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2032 @seealso{superiorto}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2033 @end deftypefn */)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2034 {
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
2035 octave_function *fcn = octave::call_stack::caller ();
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
2036 if (! fcn || ! fcn->is_class_constructor ())
20879
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
2037 error ("inferiorto: invalid call from outside class constructor");
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2038
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2039 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
2040 {
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20700
diff changeset
2041 std::string sup_class = args(i).xstring_value ("inferiorto: CLASS_NAME must be a string");
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2042
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2043 if (is_built_in_class (sup_class))
20879
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
2044 error ("inferiorto: cannot give user-defined class lower "
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
2045 "precedence than built-in class");
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2046
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2047 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
2048 if (! symbol_table::set_class_relationship (sup_class, inf_class))
20879
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
2049 error ("inferiorto: opposite precedence already set for %s and %s",
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
2050 inf_class.c_str (), sup_class.c_str ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2051 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2052
20879
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
2053 return octave_value();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2054 }