annotate libinterp/octave-value/ov-class.cc @ 32633:4b601ca024d5

maint: merge stable to default
author John W. Eaton <jwe@octave.org>
date Fri, 22 Dec 2023 12:14:08 -0500
parents ae4e19c0a2b1 2e484f9f1f18
children 2949b89f9711
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 32589
diff changeset
3 // Copyright (C) 2007-2024 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21211
diff changeset
27 # include "config.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
28 #endif
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
29
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
30 #include <istream>
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
31 #include <memory>
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
32 #include <ostream>
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
33
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
34 #include "Array-util.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
35 #include "byte-swap.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8219
diff changeset
36 #include "oct-locbuf.h"
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
37 #include "lo-mappers.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
38
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
39 #include "Cell.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
40 #include "defun.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
41 #include "error.h"
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
42 #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
43 #include "errwarn.h"
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
44 #include "interpreter-private.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22091
diff changeset
45 #include "interpreter.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
46 #include "load-path.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
47 #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
48 #include "ls-oct-text.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
49 #include "ls-oct-binary.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
50 #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
51 #include "mxarray.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
52 #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
53 #include "oct-hdf5.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
54 #include "ov-class.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
55 #include "ov-fcn.h"
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
56 #include "ov-typeinfo.h"
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
57 #include "ov-usr-fcn.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
58 #include "pager.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
59 #include "pr-output.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
60 #include "unwind-prot.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
61 #include "variables.h"
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
31845
2da025d5e98d maint: Use 's_' prefix for static private class variables.
Rik <rik@octave.org>
parents: 31838
diff changeset
64 int octave_class::s_t_id (-1);
2da025d5e98d maint: Use 's_' prefix for static private class variables.
Rik <rik@octave.org>
parents: 31838
diff changeset
65
2da025d5e98d maint: Use 's_' prefix for static private class variables.
Rik <rik@octave.org>
parents: 31838
diff changeset
66 const std::string octave_class::s_t_name ("class");
7338
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 void
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
69 octave_class::register_type (octave::type_info& ti)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
70 {
31845
2da025d5e98d maint: Use 's_' prefix for static private class variables.
Rik <rik@octave.org>
parents: 31838
diff changeset
71 s_t_id = ti.register_type (octave_class::s_t_name, "<unknown>",
32589
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 32410
diff changeset
72 octave_value (new octave_class ()));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
73 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
74
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
75 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
76 const octave_value_list& parents)
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
77 : octave_base_value (), m_map (m), m_c_name (id), m_obsolete_copies (0)
9010
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 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
80
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
81 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
82 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
83 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
84
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
85 if (! parent.isobject ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
86 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
87
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
88 std::string pcnm = parent.class_name ();
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
89
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
90 if (find_parent_class (pcnm))
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
91 error ("duplicate class in parent tree");
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
92
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
93 m_parent_list.push_back (pcnm);
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
94
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
95 octave_idx_type nel = m_map.numel ();
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
96 octave_idx_type p_nel = parent.numel ();
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
97
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
98 if (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 if (p_nel == 0)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
101 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
102 // 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
103 // so just add the field name.
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
104
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
105 m_map.assign (pcnm, Cell (m_map.dims ()));
20979
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 else if (p_nel == 1)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
108 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
109 if (m_map.nfields () == 0)
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
110 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
111 // 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
112 // parent is class object with one element.
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
113 // 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
114 // make the parent a field in MAP.
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
115
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
116 m_map.resize (parent.dims ());
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
117
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
118 m_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
119 }
c7fac37a2afc class: correctly handle parents when structure array has more than one element
John W. Eaton <jwe@octave.org>
parents: 13695
diff changeset
120 else
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
121 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
122 // 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
123 // 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
124 // field name.
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
125
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
126 m_map.assign (pcnm, Cell (m_map.dims ()));
13781
1cb3ae93578d correctly distribute parent classes
John W. Eaton <jwe@octave.org>
parents: 13711
diff changeset
127 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
128 }
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
129 else if (m_map.nfields () == 0)
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
130 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
131 // 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
132 // 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
133 // resize MAP to match parent dimsenions, then
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
134 // 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
135 // the elements of MAP.
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
136
32598
2f3b54f81947 avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents: 32589
diff changeset
137 const dim_vector& parent_dims = parent.dims ();
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
138
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
139 m_map.resize (parent_dims);
20979
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 Cell c (parent_dims);
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 octave_map pmap = parent.map_value ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
144
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
145 std::list<std::string> plist
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
146 = parent.parent_class_name_list ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
147
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
148 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
149 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
150
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
151 m_map.assign (pcnm, c);
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
152 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
153 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
154 error ("class: parent class dimension mismatch");
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 else if (nel == 1 && p_nel == 1)
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 // Simple assignment.
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
159
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
160 m_map.assign (pcnm, parent);
20979
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 else
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 if (p_nel == 1)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
165 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
166 // Broadcast the scalar parent class object to
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
167 // each element of MAP.
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
168
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
169 Cell pcell (m_map.dims (), parent);
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
170
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
171 m_map.assign (pcnm, pcell);
20979
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 else if (nel == p_nel)
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 // 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
176
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
177 // 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
178 // 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
179 // new object, so distribute those elements to
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
180 // 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
181 // splitting the elements of the parent class
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
182 // 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
183 // 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
184
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
185 Cell c (parent.dims ());
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 octave_map pmap = parent.map_value ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
188
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
189 std::list<std::string> plist
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
190 = parent.parent_class_name_list ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
191
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
192 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
193 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
194
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
195 m_map.assign (pcnm, c);
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
196 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
197 else
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
198 error ("class: parent class dimension mismatch");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
199 }
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
200 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
201
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 30888
diff changeset
202 octave::symbol_table& symtab = octave::__get_symbol_table__ ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
203
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
204 symtab.add_to_parent_map (id, m_parent_list);
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
205 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
206
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
207 octave_base_value *
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
208 octave_class::unique_clone ()
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
209 {
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31771
diff changeset
210 if (m_count == m_obsolete_copies)
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
211 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21743
diff changeset
212 // All remaining copies are obsolete. We don't actually need to clone.
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31771
diff changeset
213 m_count++;
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
214 return this;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
215 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
216 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
217 {
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
218 // In theory, this shouldn't be happening, but it's here just in case.
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31771
diff changeset
219 if (m_count < m_obsolete_copies)
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
220 m_obsolete_copies = 0;
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
221
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
222 return clone ();
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
223 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
224 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
225
10926
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
226 std::string
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
227 octave_class::get_current_method_class ()
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
228 {
10926
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
229 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
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 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
232 {
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 30888
diff changeset
233 octave::tree_evaluator& tw = octave::__get_evaluator__ ();
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23519
diff changeset
234
27210
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 26922
diff changeset
235 octave_function *fcn = tw.current_function ();
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
236
12620
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
237 // Here we are just looking to see if FCN is a method or constructor
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
238 // for any class, not specifically this one.
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
239 if (fcn && (fcn->is_class_method () || fcn->is_class_constructor ()))
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
240 retval = fcn->dispatch_class ();
6f3f18957851 ov-class.cc: Fix segfault when assigning class to struct object (bug #33014)
David Bateman <dbateman@free.fr>
parents: 12483
diff changeset
241 }
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
242
9156
b2b8ed43b922 ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents: 9151
diff changeset
243 return retval;
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
244 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
245
21040
3e7cfee5f786 maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents: 21029
diff changeset
246 OCTAVE_NORETURN static
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21024
diff changeset
247 void
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
248 err_invalid_index1 ()
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
249 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
250 error ("invalid index for class");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
251 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
252
21040
3e7cfee5f786 maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents: 21029
diff changeset
253 OCTAVE_NORETURN static
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21024
diff changeset
254 void
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
255 err_invalid_index_for_assignment ()
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
256 {
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
257 error ("invalid index for class assignment");
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
258 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
259
21040
3e7cfee5f786 maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents: 21029
diff changeset
260 OCTAVE_NORETURN static
21029
e3b3bb522d62 maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents: 21024
diff changeset
261 void
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
262 err_invalid_index_type (const std::string& nm, char t)
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
263 {
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
264 error ("%s cannot be indexed with %c", nm.c_str (), t);
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
265 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
266
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
267 void
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
268 octave_class::break_closure_cycles (const std::shared_ptr<octave::stack_frame>& frame)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
269 {
29478
e88444be8468 maint: merge stable to default.
John W. Eaton <jwe@octave.org>
parents: 29466 29476
diff changeset
270 for (octave_idx_type j = 0; j < m_map.nfields (); j++)
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
271 {
29478
e88444be8468 maint: merge stable to default.
John W. Eaton <jwe@octave.org>
parents: 29466 29476
diff changeset
272 Cell& c = m_map.contents (j);
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
273
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
274 for (octave_idx_type i = 0; i < c.numel (); i++)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
275 c(i).break_closure_cycles (frame);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
276 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
277 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
278
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
279 Cell
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
280 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
281 {
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
282 panic_if (idx.length () != 1);
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
283
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
284 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
285
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
286 // 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
287 // 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
288
10926
f687bd17ce21 fix field assignment from private class methods
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
289 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
290
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23693
diff changeset
291 if (obvp == nullptr)
20879
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
292 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
293
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
294 octave_map my_map = (obvp != this) ? obvp->map_value () : m_map;
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
295
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20681
diff changeset
296 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
297
25342
416856765a55 be more careful with using auto in place of explicit const iterator decls
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
298 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
299
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
300 if (p == my_map.end ())
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
301 error ("class has no member '%s'", nm.c_str ());
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
302
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
303 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
304 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
305
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
306 Matrix
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
307 octave_class::size ()
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
308 {
26525
0d3eca5955dc Backed out changeset 920a4ad8043b (bug #54995)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
309 if (in_class_method () || called_from_builtin ())
9792
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
310 return octave_base_value::size ();
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
311
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
312 Matrix retval (1, 2, 1.0);
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
313
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
314 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
315
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
316 octave::symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
317
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
318 octave_value meth = symtab.find_method ("size", class_name ());
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
319
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
320 if (meth.is_defined ())
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
321 {
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31771
diff changeset
322 m_count++;
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
323 octave_value_list args (1, octave_value (this));
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
324
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
325 octave_value_list lv = interp.feval (meth.function_value (), args, 1);
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
326 if (lv.length () <= 0
23592
80e3bfb7bd5a maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents: 23587
diff changeset
327 || ! lv(0).is_matrix_type () || ! lv(0).dims ().isvector ())
9775
9d9f858849c7 Allow and ignore extra outargs from user-defined size methods
David Grundberg <davidg@cs.umu.se>
parents: 9774
diff changeset
328 error ("@%s/size: invalid return value", class_name ().c_str ());
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
329
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
330 retval = lv(0).matrix_value ();
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
331 }
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
332 else
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
333 {
32598
2f3b54f81947 avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents: 32589
diff changeset
334 const dim_vector& dv = dims ();
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
335
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21580
diff changeset
336 int nd = dv.ndims ();
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
337
13784
0bbe319bf26b octave_class::size: return matrix with correct dimensions
John W. Eaton <jwe@octave.org>
parents: 13781
diff changeset
338 retval.resize (1, nd);
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
339
13784
0bbe319bf26b octave_class::size: return matrix with correct dimensions
John W. Eaton <jwe@octave.org>
parents: 13781
diff changeset
340 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
341 retval(i) = dv(i);
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13694
diff changeset
342 }
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
343
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
344 return retval;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
345 }
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
346
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
347 octave_idx_type
26922
072d0610cc56 avoid some overloaded virtual warnings (bug #55741)
John W. Eaton <jwe@octave.org>
parents: 26745
diff changeset
348 octave_class::xnumel (const octave_value_list& idx)
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
349 {
26525
0d3eca5955dc Backed out changeset 920a4ad8043b (bug #54995)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
350 if (in_class_method () || called_from_builtin ())
26922
072d0610cc56 avoid some overloaded virtual warnings (bug #55741)
John W. Eaton <jwe@octave.org>
parents: 26745
diff changeset
351 return octave_base_value::xnumel (idx);
9792
384616240a8f fix internal numel on classes
Jaroslav Hajek <highegg@gmail.com>
parents: 9775
diff changeset
352
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
353 octave_idx_type retval = -1;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
354 const std::string cn = class_name ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
355
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
356 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
357
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
358 octave::symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
359
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
360 octave_value meth = symtab.find_method ("numel", cn);
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
361
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
362 if (meth.is_defined ())
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
363 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
364 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
365
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31771
diff changeset
366 m_count++;
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
367 args(0) = octave_value (this);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
368
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
369 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
370 args(i+1) = idx(i);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
371
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
372 octave_value_list lv = interp.feval (meth.function_value (), args, 1);
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
373 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
374 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
375
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
376 retval = lv(0).idx_type_value (true);
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
377 }
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
378 else
26922
072d0610cc56 avoid some overloaded virtual warnings (bug #55741)
John W. Eaton <jwe@octave.org>
parents: 26745
diff changeset
379 retval = octave_base_value::xnumel (idx);
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
380
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
381 return retval;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
382 }
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
383
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
384 octave_value_list
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
385 octave_class::subsref (const std::string& type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
386 const std::list<octave_value_list>& idx,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
387 int nargout)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
388 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
389 octave_value_list retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
390
26525
0d3eca5955dc Backed out changeset 920a4ad8043b (bug #54995)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
391 if (in_class_method () || called_from_builtin ())
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
392 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
393 // 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
394 // octave_struct::subsref. Maybe it could be shared instead of
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
395 // duplicated.
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
396
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
397 int skip = 1;
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
398
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
399 switch (type[0])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
400 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
401 case '(':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
402 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
403 if (type.length () > 1 && type[1] == '.')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
404 {
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
405 auto p = idx.begin ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
406 octave_value_list key_idx = *++p;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
407
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
408 Cell tmp = dotref (key_idx);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
409
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
410 Cell t = tmp.index (idx.front ());
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
411
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
412 retval(0) = (t.numel () == 1 ? t(0)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
413 : octave_value (t, true));
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
414
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
415 // 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
416 // 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
417 skip++;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
418 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
419 else
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
420 retval(0) = octave_value (m_map.index (idx.front ()),
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
421 m_c_name, m_parent_list);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
422 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
423 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
424
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
425 case '.':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
426 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
427 if (m_map.numel () > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
428 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
429 Cell t = dotref (idx.front ());
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
430
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
431 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
432 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
433 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
434 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
435
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
436 case '{':
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
437 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
438 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
439
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
440 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
441 panic_impossible ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
442 }
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
443
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
444 // FIXME: perhaps there should be an
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
445 // octave_value_list::next_subsref member function? See also
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
446 // octave_user_function::subsref.
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
447
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
448 if (idx.size () > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
449 retval = retval(0).next_subsref (nargout, type, idx, skip);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
450 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
451 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
452 {
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
453 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
454
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
455 octave::symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
456
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
457 octave_value meth = symtab.find_method ("subsref", class_name ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
458
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
459 if (meth.is_defined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
460 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
461 octave_value_list args;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
462
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
463 args(1) = make_idx_args (type, idx, "subsref");
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
464
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31771
diff changeset
465 m_count++;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
466 args(0) = octave_value (this);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
467
32410
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
468 // If the number of output arguments is unknown, attempt to set up
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
469 // a proper value for nargout at least in the simple case where the
9691
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
470 // cs-list-type expression - i.e., {} or ().x, is the leading one.
32410
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
471 if (nargout <= 0)
9331
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
472 {
32410
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
473 bool maybe_cs_list_query = (type[0] == '.' || type[0] == '{'
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
474 || (type.length () > 1 && type[0] == '('
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
475 && type[1] == '.'));
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
476
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
477 if (maybe_cs_list_query)
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
478 {
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
479 // Set up a proper nargout for the subsref call by calling numel.
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
480 octave_value_list tmp;
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
481 int nout;
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
482 if (type[0] != '.') tmp = idx.front ();
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
483 nout = xnumel (tmp);
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
484 if (nargout != 0 || nout > 1)
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
485 nargout = nout;
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
486 }
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
487 else if (nargout < 0)
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
488 nargout = 1;
9331
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
489 }
9691
318e0cdd31bd improve OOP subsref handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9581
diff changeset
490
32410
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
491 retval = interp.feval (meth.function_value (), args, nargout);
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
492
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
493 // Since we're handling subsref, if the list has more than one element
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
494 // and the caller to subsref accepts more that one output, return
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
495 // the elements as a comma-separated list so that we can pass it to the
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
496 // evaluator
32589
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 32410
diff changeset
497 if (retval.length () > 1 && (nargout < 0 || nargout > 1))
32410
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
498 {
32589
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 32410
diff changeset
499 if (nargout <= 0 || nargout >= retval.length ())
32410
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
500 // Take the whole list
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
501 retval = octave_value (retval);
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
502 else
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
503 // Take nargout elements of the list
32589
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 32410
diff changeset
504 retval = octave_value (retval.slice (0, nargout));
32410
554a932fc6d0 Fix nargout when calling class subsref method (bug #63841)
Fernando Alvarruiz <feralber@upvnet.upv.es>
parents: 32099
diff changeset
505 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
506 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
507 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
508 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
509 if (type.length () == 1 && type[0] == '(')
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
510 retval(0) = octave_value (m_map.index (idx.front ()), m_c_name,
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
511 m_parent_list);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
512 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
513 err_invalid_index1 ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
514 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
515 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
516
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
517 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
518 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
519
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
520 octave_value
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
521 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
522 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
523 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
524
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
525 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
526 err_invalid_index_for_assignment ();
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
527
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
528 retval = val(0);
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
529
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23580
diff changeset
530 if (type.length () > 0 && type[0] == '.' && ! retval.isstruct ())
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
531 retval = octave_map ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
532
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
533 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
534 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
535
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
536 octave_value
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
537 octave_class::subsasgn (const std::string& type,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
538 const std::list<octave_value_list>& idx,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
539 const octave_value& rhs)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
540 {
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31771
diff changeset
541 m_count++;
12171
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
542 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
543 }
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
544
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
545 octave_value
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
546 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
547 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
548 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
549 {
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
550 // 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
551 // 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
552 // undefined.
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
553
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
554 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
555 }
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
556
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
557 octave_value
d08901c05c1b fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents: 12127
diff changeset
558 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
559 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
560 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
561 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
562 {
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
563 octave_value retval;
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
564
26525
0d3eca5955dc Backed out changeset 920a4ad8043b (bug #54995)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
565 if (! (in_class_method () || called_from_builtin ()))
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
566 {
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
567 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
568
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
569 octave::symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
570
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
571 octave_value meth = symtab.find_method ("subsasgn", class_name ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
572
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
573 if (meth.is_defined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
574 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
575 octave_value_list args;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
576
9333
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
577 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
578 {
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
579 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
580 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
581 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
582 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
583 }
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
584 else
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
585 args(2) = rhs;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
586
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
587 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
588 args(0) = obj;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
589
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21743
diff changeset
590 // Now comes the magic. Count copies with me:
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
591 // 1. myself (obsolete)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
592 // 2. the copy inside args (obsolete)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
593 // 3. the copy in method's symbol table (working)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
594 // ... possibly more (not obsolete).
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
595 //
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
596 // 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
597 // 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
598 // to the optimization.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
599 // 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
600 // 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
601 // optimization won't work.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
602
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
603 octave_value_list tmp;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
604
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
605 if (m_obsolete_copies == 0 && meth.is_user_function ()
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
606 && meth.user_function_value ()->subsasgn_optimization_ok ())
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
607 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
608 octave::unwind_protect_var<int> restore_var (m_obsolete_copies);
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
609 m_obsolete_copies = 2;
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
610
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
611 tmp = interp.feval (meth.function_value (), args);
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
612 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
613 else
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
614 tmp = interp.feval (meth.function_value (), args);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
615
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20700
diff changeset
616 // 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
617 // more than one value?
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
618
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
619 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
620 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
621 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
622
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
623 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
624 retval = tmp(0);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
625
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
626 return retval;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
627 }
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
628 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
629
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
630 // 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
631 // attempting to do the indexed assignment.
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
632
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
633 std::string method_class = get_current_method_class ();
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
634
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
635 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
636 if (obvp != this)
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
637 {
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
638
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
639 if (! obvp)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
640 error ("malformed class");
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
641
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
642 obvp->subsasgn (type, idx, rhs);
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
643
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31771
diff changeset
644 m_count++;
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
645 retval = octave_value (this);
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
646
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
647 return retval;
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
648 }
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
649
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
650 // 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
651 // octave_struct::subsasgn. Maybe it could be shared instead of
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
652 // duplicated.
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
653
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
654 int n = type.length ();
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
655
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
656 octave_value t_rhs = rhs;
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
657
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
658 if (n > 1 && ! (type.length () == 2 && type[0] == '(' && type[1] == '.'))
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
659 {
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
660 switch (type[0])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
661 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
662 case '(':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
663 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
664 if (type.length () > 1 && type[1] == '.')
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
665 {
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
666 auto p = idx.begin ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
667 octave_value_list t_idx = *p;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
668
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
669 octave_value_list key_idx = *++p;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
670
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
671 panic_if (key_idx.length () != 1);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
672
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20681
diff changeset
673 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
674
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
675 octave_value u;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
676
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
677 if (! m_map.contains (key))
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
678 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
679 else
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
680 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
681 Cell map_val = m_map.contents (key);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
682
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
683 Cell map_elt = map_val.index (idx.front (), true);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
684
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
685 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
686 }
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
687
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
688 std::list<octave_value_list> next_idx (idx);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
689
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
690 // 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
691 // needs to skip both of them.
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
692
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
693 next_idx.erase (next_idx.begin ());
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
694 next_idx.erase (next_idx.begin ());
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
695
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
696 u.make_unique ();
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
697
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
698 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
699 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
700 else
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_for_assignment ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
702 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
703 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
704
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
705 case '.':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
706 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
707 octave_value_list key_idx = idx.front ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
708
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
709 panic_if (key_idx.length () != 1);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
710
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
711 std::string key = key_idx(0).string_value ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
712
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
713 std::list<octave_value_list> next_idx (idx);
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
714
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
715 next_idx.erase (next_idx.begin ());
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
716
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
717 std::string next_type = type.substr (1);
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
718
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
719 Cell tmpc (1, 1);
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
720 auto pkey = m_map.seek (key);
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
721 if (pkey != m_map.end ())
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
722 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
723 m_map.contents (pkey).make_unique ();
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
724 tmpc = m_map.contents (pkey);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
725 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
726
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
727 // 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
728 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
729 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
730
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
731 octave_value& tmp = tmpc(0);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
732
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
733 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
734 {
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
735 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
736 tmp.make_unique (); // probably a no-op.
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
737 }
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
738 else
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
739 // 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
740 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
741
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21102
diff changeset
742 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
743 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
744 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
745
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
746 case '{':
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
747 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
748 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
749
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
750 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
751 panic_impossible ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
752 }
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
753 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
754
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
755 switch (type[0])
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
756 {
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
757 case '(':
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
758 {
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
759 if (n > 1 && type[1] == '.')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
760 {
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
761 auto p = idx.begin ();
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
762 octave_value_list key_idx = *++p;
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
763
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
764 panic_if (key_idx.length () != 1);
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
765
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
766 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
767
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
768 m_map.assign (idx.front (), key, t_rhs);
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
769
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31771
diff changeset
770 m_count++;
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
771 retval = octave_value (this);
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 {
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
775 if (t_rhs.isobject () || t_rhs.isstruct ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
776 {
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
777 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
778
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
779 m_map.assign (idx.front (), rhs_map);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
780
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31771
diff changeset
781 m_count++;
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
782 retval = octave_value (this);
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
783 }
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
784 else
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
785 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
786 if (! t_rhs.isempty ())
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
787 error ("invalid class assignment");
20679
19d6f94c21cb eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20584
diff changeset
788
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
789 m_map.delete_elements (idx.front ());
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
790
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31771
diff changeset
791 m_count++;
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
792 retval = octave_value (this);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
793 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
794 }
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
795 }
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
796 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
797
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
798 case '.':
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
799 {
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
800 octave_value_list key_idx = idx.front ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
801
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
802 panic_if (key_idx.length () != 1);
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
803
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
804 std::string key = key_idx(0).string_value ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
805
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
806 if (t_rhs.is_cs_list ())
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
807 {
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
808 Cell tmp_cell = Cell (t_rhs.list_value ());
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
809
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
810 // 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
811 // 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
812 // 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
813
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
814 if (numel () == tmp_cell.numel ())
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
815 tmp_cell = tmp_cell.reshape (dims ());
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
816
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
817 m_map.setfield (key, tmp_cell);
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
818 }
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
819 else
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
820 {
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
821 Cell tmp_cell(1, 1);
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
822 tmp_cell(0) = t_rhs.storable_value ();
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
823 m_map.setfield (key, tmp_cell);
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
824 }
12127
b83162e8f402 fix nested indexed assignemnt in superclasses
Jaroslav Hajek <highegg@gmail.com>
parents: 11586
diff changeset
825
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31771
diff changeset
826 m_count++;
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
827 retval = octave_value (this);
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
828 }
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
829 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
830
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
831 case '{':
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
832 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
833 break;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
834
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
835 default:
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
836 panic_impossible ();
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
837 }
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 return retval;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
840 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
841
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
842 octave::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
843 octave_class::index_vector (bool require_integers) const
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
844 {
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
845 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
846
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
847 octave::symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
848
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
849 octave_value meth = symtab.find_method ("subsindex", class_name ());
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
850
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
851 if (! meth.is_defined ())
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
852 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
853 class_name ().c_str ());
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
854
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
855 octave_value_list args;
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
856 args(0) = octave_value (new octave_class (m_map, m_c_name, m_parent_list));
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
857
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
858 octave_value_list tmp = interp.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
859
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
860 if (tmp(0).isobject ())
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
861 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
862
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
863 // 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
864 // (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
865 // 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
866 // expects it to be one based.
28631
70cdf8de553d move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents: 28444
diff changeset
867 return octave::binary_op (octave_value::op_add, tmp (0),
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
868 octave_value (1.0)).index_vector (require_integers);
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
869 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
870
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
871 std::size_t
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
872 octave_class::byte_size () const
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
873 {
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
874 // Neglect the size of the fieldnames.
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
875
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
876 std::size_t retval = 0;
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
877
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
878 for (auto it = m_map.cbegin (); it != m_map.cend (); it++)
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
879 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
880 std::string key = m_map.key (it);
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
881
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
882 octave_value val = octave_value (m_map.contents (it));
9529
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
883
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
884 retval += val.byte_size ();
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
885 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
886
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
887 return retval;
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
888 }
8e5009334661 partially revert e79470be3ecb
Jaroslav Hajek <highegg@gmail.com>
parents: 9522
diff changeset
889
21725
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
890 bool
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
891 octave_class::is_true () const
21725
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
892 {
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
893 bool retval = false;
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
894
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
895 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
896
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
897 octave::symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
898
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
899 octave_value meth = symtab.find_method ("logical", class_name ());
21725
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
900
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
901 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
902 {
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
903 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
904
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
905 octave_value_list tmp = interp.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
906 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
907 }
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
908
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
909 return retval;
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
910 }
78e0b187904b Call @class/logical method for objects in conditional expressions (bug #43097)
Mike Miller <mtmiller@octave.org>
parents: 21724
diff changeset
911
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
912 string_vector
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
913 octave_class::map_keys () const
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
914 {
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
915 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
916 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
917
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
918 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
919 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
920 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
921 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
922
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
923 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
924 retval = this;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
925 else
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
926 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
927 for (auto& par : m_parent_list)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
928 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
929 octave_map::const_iterator smap = m_map.seek (par);
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
930
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
931 const Cell& tmp = m_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
932
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
933 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
934
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
935 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
936
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
937 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
938
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
939 if (retval)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
940 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
941 }
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
942 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
943
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
944 return retval;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
945 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
946
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
947 octave_base_value *
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
948 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
949 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
950 octave_base_value *retval = nullptr;
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
951
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
952 if (parent_class_name == class_name ())
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
953 retval = this;
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
954 else
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
955 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
956 for (auto& par : m_parent_list)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
957 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
958 auto smap = m_map.seek (par);
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
959
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
960 Cell& tmp = m_map.contents (smap);
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
961
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
962 octave_value& vtmp = tmp(0);
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
963
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
964 octave_base_value *obvp = vtmp.internal_rep ();
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
965
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
966 // 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
967 retval = obvp->find_parent_class (parent_class_name);
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
968
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
969 if (retval)
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
970 {
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
971 vtmp.make_unique ();
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
972 obvp = vtmp.internal_rep ();
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
973 retval = obvp->unique_parent_class (parent_class_name);
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
974
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
975 break;
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
976 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
977 }
9767
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
978 }
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
979
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
980 return retval;
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
981 }
0df32e0b2074 fix base class field assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 9691
diff changeset
982
19103
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
983 bool
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
984 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
985 {
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
986 bool retval = false;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
987
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
988 if (cls_name == class_name ())
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
989 retval = true;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
990 else
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
991 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
992 for (auto& par : m_parent_list)
19103
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
993 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
994 octave_map::const_iterator smap = m_map.seek (par);
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
995
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
996 const Cell& tmp = m_map.contents (smap);
19103
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
997
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
998 const octave_value& vtmp = tmp(0);
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
999
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
1000 retval = vtmp.is_instance_of (cls_name);
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
1001
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
1002 if (retval)
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
1003 break;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
1004 }
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
1005 }
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
1006
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
1007 return retval;
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
1008 }
56bc1464ec59 Implement "isa" for classdef objects.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18881
diff changeset
1009
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
1010 string_vector
20990
fc9cca99b2de Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents: 20979
diff changeset
1011 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
1012 {
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
1013 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
1014
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1015 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1016
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1017 octave::symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1018
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1019 octave_value meth = symtab.find_method ("char", class_name ());
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
1020
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1021 if (! meth.is_defined ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1022 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
1023
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1024 octave_value_list args;
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
1025 args(0) = octave_value (new octave_class (m_map, m_c_name, m_parent_list));
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1026
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1027 octave_value_list tmp = interp.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
1028
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1029 if (tmp.length () >= 1)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1030 {
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1031 if (! tmp(0).is_string ())
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1032 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
1033
20990
fc9cca99b2de Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents: 20979
diff changeset
1034 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
1035 }
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1036
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
1037 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
1038 }
441af0aa125a char: when converting cell elements containing class objects, call overloaded char function if one exists
John W. Eaton <jwe@octave.org>
parents: 13241
diff changeset
1039
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1040 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18409
diff changeset
1041 octave_class::print (std::ostream& os, bool)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1042 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1043 print_raw (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1044 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1045
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1046 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1047 octave_class::print_raw (std::ostream& os, bool) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1048 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1049 indent (os);
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23795
diff changeset
1050 os << " <class " << class_name () << '>';
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1051 newline (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1052 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1053
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1054 // 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
1055 // 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
1056 // with no arguments.
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1057 bool
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
1058 octave_class::reconstruct_exemplar ()
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1059 {
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1060 bool retval = false;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1061
25342
416856765a55 be more careful with using auto in place of explicit const iterator decls
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1062 octave_class::exemplar_const_iterator it
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
1063 = octave_class::exemplar_map.find (m_c_name);
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1064
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1065 if (it != octave_class::exemplar_map.end ())
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1066 retval = true;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1067 else
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1068 {
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 30888
diff changeset
1069 octave::interpreter& interp = octave::__get_interpreter__ ();
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
1070
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
1071 octave::symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1072
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
1073 octave_value ctor = symtab.find_method (m_c_name, m_c_name);
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1074
12178
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1075 bool have_ctor = false;
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1076
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1077 if (ctor.is_defined () && ctor.is_function ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1078 {
12178
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1079 octave_function *fcn = ctor.function_value ();
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1080
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
1081 if (fcn && fcn->is_class_constructor (m_c_name))
12178
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1082 have_ctor = true;
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1083
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1084 // Something has gone terribly wrong if
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1085 // 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
1086 // a class constructor for the class c_name...
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
1087 panic_unless (have_ctor);
12178
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1088 }
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1089
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1090 if (have_ctor)
a71c1aa9823e fix construction of class exemplars
John W. Eaton <jwe@octave.org>
parents: 12171
diff changeset
1091 {
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
1092 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
1093
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1094 // 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
1095
29956
a956ca6698d2 move some error handling functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
1096 octave::interpreter_try (frame);
17473
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1097
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1098 bool execution_error = false;
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1099
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1100 octave_value_list result;
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1101
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1102 try
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1103 {
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1104 result = interp.feval (ctor, ovl (), 1);
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1105 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1106 catch (const octave::execution_exception&)
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1107 {
27474
3fec8e9fa2aa make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
1108 interp.recover_from_exception ();
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20747
diff changeset
1109
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1110 execution_error = true;
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1111 }
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1112
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20495
diff changeset
1113 if (! execution_error && result.length () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1114 retval = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1115 }
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1116 else
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
1117 warning ("no constructor for class %s", m_c_name.c_str ());
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1118 }
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1119
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1120 return retval;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1121 }
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1122
9240
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1123 void
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
1124 octave_class::clear_exemplar_map ()
9240
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1125 {
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1126 exemplar_map.clear ();
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1127 }
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
1128
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1129 // 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
1130 // class inheritance structure. reconstruct_parents () attempts to
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1131 // 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
1132 //
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1133 // 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
1134 // 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
1135 // to do its magic.
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1136 bool
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
1137 octave_class::reconstruct_parents ()
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1138 {
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 18033
diff changeset
1139 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
1140 bool might_have_inheritance = false;
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1141 std::string dbgstr = "dork";
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1142
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1143 // First, check to see if there might be an issue with inheritance.
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1144 for (auto it = m_map.cbegin (); it != m_map.cend (); it++)
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1145 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1146 std::string key = m_map.key (it);
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1147 Cell val = m_map.contents (it);
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
1148 if (val(0).isobject ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1149 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1150 dbgstr = "blork";
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18637
diff changeset
1151 if (key == val(0).class_name ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1152 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1153 might_have_inheritance = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1154 dbgstr = "cork";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1155 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1156 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1157 }
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1158 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1159
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1160 if (might_have_inheritance)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1161 {
25342
416856765a55 be more careful with using auto in place of explicit const iterator decls
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1162 octave_class::exemplar_const_iterator it
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
1163 = octave_class::exemplar_map.find (m_c_name);
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1164
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1165 if (it == octave_class::exemplar_map.end ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1166 retval = false;
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1167 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1168 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1169 octave_class::exemplar_info exmplr = it->second;
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1170 m_parent_list = exmplr.parents ();
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1171 for (auto& par : m_parent_list)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1172 {
22871
50495eeb5df1 maint: Use C++ range feature to simplify some for loops in libinterp/octave-value.
Rik <rik@octave.org>
parents: 22755
diff changeset
1173 dbgstr = par;
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1174 bool dbgbool = m_map.contains (par);
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20939
diff changeset
1175 if (! dbgbool)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1176 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1177 retval = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1178 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1179 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1180 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1181 }
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1182 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1183
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1184 return retval;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1185 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1186
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1187 bool
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1188 octave_class::save_ascii (std::ostream& os)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1189 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1190 os << "# classname: " << class_name () << "\n";
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1191 octave_map m;
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1192
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1193 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1194
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1195 octave::load_path& lp = interp.get_load_path ();
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1196
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1197 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
1198 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1199 octave_value in = new octave_class (*this);
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1200
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1201 octave_value_list tmp = interp.feval ("saveobj", in, 1);
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1202
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1203 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
1204 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1205 else
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1206 m = map_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1207
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1208 os << "# length: " << m.nfields () << "\n";
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1209
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
1210 auto i = m.begin ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1211 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1212 {
32098
6cd803819bd2 Fix segfault when saveobj() used with old-style class files (bug #64220)
Rik <rik@octave.org>
parents: 31706
diff changeset
1213 octave_value val = m.contents (i);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1214
20447
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20232
diff changeset
1215 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
1216
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1217 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
1218 return ! os.fail ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1219
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1220 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1221 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1222
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1223 return true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1224 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1225
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1226 bool
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1227 octave_class::load_ascii (std::istream& is)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1228 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1229 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
1230 std::string classname;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1231
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1232 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
1233 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
1234
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1235 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
1236 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
1237
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1238 if (len > 0)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1239 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1240 octave_map m (m_map);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1241
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1242 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
1243 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1244 octave_value t2;
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1245 bool dummy;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1246
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1247 // recurse to read cell elements
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1248 std::string nm
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20990
diff changeset
1249 = 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
1250
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1251 if (! is)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1252 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1253
31718
52a5bec0fc74 style fixes: avoid breaking lines after "(" and prefer "" over QString ("")
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
1254 Cell tcell = (t2.iscell () ? 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
1255
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1256 m.assign (nm, tcell);
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1257 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1258
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1259 if (! is)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1260 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
1261
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
1262 m_c_name = classname;
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1263 reconstruct_exemplar ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1264
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1265 m_map = m;
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1266
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1267 if (! reconstruct_parents ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1268 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
1269
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1270 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1271
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1272 octave::load_path& lp = interp.get_load_path ();
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1273
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1274 if (lp.find_method (classname, "loadobj") != "")
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1275 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1276 octave_value in = new octave_class (*this);
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1277 octave_value_list tmp = interp.feval ("loadobj", in, 1);
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1278
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1279 m_map = tmp(0).map_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1280 }
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1281 }
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1282 else if (len == 0)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1283 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1284 m_map = octave_map (dim_vector (1, 1));
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
1285 m_c_name = classname;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1286 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1287 else
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1288 panic_impossible ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1289
20879
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
1290 return true;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1291 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1292
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1293 bool
26399
586413770c7f pass save_as_floats by value in octave_value save_binary functions
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1294 octave_class::save_binary (std::ostream& os, bool save_as_floats)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1295 {
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
1296 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
1297
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1298 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
1299 os << class_name ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1300
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1301 octave_map m;
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1302
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1303 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1304
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1305 octave::load_path& lp = interp.get_load_path ();
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1306
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1307 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
1308 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1309 octave_value in = new octave_class (*this);
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1310 octave_value_list tmp = interp.feval ("saveobj", in, 1);
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1311
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1312 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
1313 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1314 else
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1315 m = map_value ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1316
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
1317 int32_t len = m.nfields ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1318 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
1319
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
1320 auto i = m.begin ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1321 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1322 {
32098
6cd803819bd2 Fix segfault when saveobj() used with old-style class files (bug #64220)
Rik <rik@octave.org>
parents: 31706
diff changeset
1323 octave_value val = m.contents (i);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1324
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1325 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
1326
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1327 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
1328 return ! os.fail ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1329
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1330 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1331 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1332
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1333 return true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1334 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1335
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1336 bool
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1337 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
1338 octave::mach_info::float_format fmt)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1339 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1340 bool success = true;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1341
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1342 int32_t classname_len;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1343
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1344 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
1345 if (! is)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1346 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1347 else if (swap)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1348 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
1349
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1350 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1351 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
1352 classname[classname_len] = '\0';
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1353 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
1354 return false;
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
1355 m_c_name = classname;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1356 }
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1357 reconstruct_exemplar ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1358
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1359 int32_t len;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1360 if (! is.read (reinterpret_cast<char *> (&len), 4))
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1361 return false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1362 if (swap)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1363 swap_bytes<4> (&len);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1364
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1365 if (len > 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1366 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1367 octave_map m (m_map);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1368
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1369 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
1370 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1371 octave_value t2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1372 bool dummy;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1373 std::string doc;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1374
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1375 // recurse to read cell elements
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20990
diff changeset
1376 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
1377 dummy, t2, doc);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1378
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1379 if (! is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1380 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1381
31718
52a5bec0fc74 style fixes: avoid breaking lines after "(" and prefer "" over QString ("")
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
1382 Cell tcell = (t2.iscell () ? 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
1383
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1384 m.assign (nm, tcell);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1385 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1386
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1387 if (is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1388 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1389 m_map = m;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1390
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1391 if (! reconstruct_parents ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1392 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
1393
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1394 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1395
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1396 octave::load_path& lp = interp.get_load_path ();
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1397
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
1398 if (lp.find_method (m_c_name, "loadobj") != "")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1399 {
17473
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1400 octave_value in = new octave_class (*this);
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1401 octave_value_list tmp = interp.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
1402
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1403 m_map = tmp(0).map_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1404 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1405 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1406 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1407 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1408 warning ("load: failed to load class");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1409 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1410 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1411 }
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18637
diff changeset
1412 else if (len == 0)
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1413 m_map = octave_map (dim_vector (1, 1));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1414 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1415 panic_impossible ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1416
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1417 return success;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1418 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1419
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
1420 bool
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1421 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
1422 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
1423 {
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1424 #if defined (HAVE_HDF5)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1425
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1426 hsize_t hdims[3];
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1427 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
1428 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
1429 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
1430 hid_t class_hid = -1;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1431 hid_t data_hid = -1;
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1432 octave_map m;
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1433 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
1434
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1435 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1436
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1437 octave::load_path& lp = interp.get_load_path ();
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1438
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
1439 #if defined (HAVE_HDF5_18)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1440 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
1441 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
1442 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1443 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
1444 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1445 if (group_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1446 goto error_cleanup;
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 // Add the class name to the group
32589
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 32410
diff changeset
1449 type_hid = H5Tcopy (H5T_C_S1);
05b4479c29d8 maint: C++ style check for libinterp/ before 9.1 release.
Rik <rik@octave.org>
parents: 32410
diff changeset
1450 H5Tset_size (type_hid, m_c_name.length () + 1);
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1451 if (type_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1452 goto error_cleanup;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1453
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1454 hdims[0] = 0;
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1455 space_hid = H5Screate_simple (0, hdims, nullptr);
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1456 if (space_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1457 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
1458 #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
1459 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
1460 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1461 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
1462 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1463 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
1464 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
1465 #endif
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1466 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
1467 octave_H5S_ALL, octave_H5P_DEFAULT,
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
1468 m_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
1469 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1470
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
1471 #if defined (HAVE_HDF5_18)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1472 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
1473 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
1474 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1475 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
1476 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1477 if (data_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1478 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1479
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1480 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
1481 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1482 octave_value in = new octave_class (*this);
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1483 octave_value_list tmp = interp.feval ("saveobj", in, 1);
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1484
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1485 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
1486 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1487 else
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1488 m = map_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1489
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1490 // 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
1491 i = m.begin ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1492 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1493 {
32098
6cd803819bd2 Fix segfault when saveobj() used with old-style class files (bug #64220)
Rik <rik@octave.org>
parents: 31706
diff changeset
1494 octave_value val = m.contents (i);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1495
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1496 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
1497 save_as_floats);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1498
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1499 if (! retval2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1500 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1501
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1502 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1503 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1504
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1505 error_cleanup:
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1506
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1507 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1508 H5Gclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1509
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1510 if (class_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1511 H5Dclose (class_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1512
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1513 if (space_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1514 H5Sclose (space_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1515
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1516 if (type_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1517 H5Tclose (type_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 if (group_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1520 H5Gclose (group_hid);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1521
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1522 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
1523
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
1524 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1525 octave_unused_parameter (loc_id);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1526 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1527 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
1528
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
1529 warn_save ("hdf5");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1530
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
1531 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
1532 #endif
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1533 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1534
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1535 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
1536 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
1537 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1538 bool retval = false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1539
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
1540 #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
1541
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1542 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
1543 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
1544 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
1545 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
1546 hid_t space_hid = -1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1547 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
1548 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
1549
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1550 hdf5_callback_data dsub;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1551
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1552 herr_t retval2 = 0;
10768
8a868004a437 use octave_map for octave_class
Jaroslav Hajek <highegg@gmail.com>
parents: 10742
diff changeset
1553 octave_map m (dim_vector (1, 1));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1554 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
1555 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
1556 int slen = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1557 hsize_t rank = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1558
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
1559 #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
1560 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
1561 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1562 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
1563 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1564 if (group_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1565 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1566
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
1567 #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
1568 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
1569 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1570 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
1571 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1572
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1573 if (data_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1574 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1575
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1576 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
1577
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1578 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
1579
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1580 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
1581 goto error_cleanup;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1582
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1583 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
1584 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
1585
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1586 if (rank != 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1587 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1588
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1589 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
1590 if (slen < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1591 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1592
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1593 // 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
1594 do
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1595 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1596 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
1597
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1598 // 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
1599 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
1600 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
1601
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1602 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
1603 octave_H5P_DEFAULT, classname)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1604 < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1605 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1606 H5Tclose (st_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1607 H5Dclose (data_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1608 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1609 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1610 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1611
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1612 H5Tclose (st_id);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1613 H5Dclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1614 data_hid = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1615
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
1616 m_c_name = classname;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1617 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1618 while (0);
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1619 reconstruct_exemplar ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1620
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
1621 #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
1622 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
1623 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1624 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
1625 #endif
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1626 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
1627 H5Gclose (subgroup_hid);
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 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
1630 && (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
1631 &dsub)) > 0)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1632 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1633 octave_value t2 = dsub.tc;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1634
31718
52a5bec0fc74 style fixes: avoid breaking lines after "(" and prefer "" over QString ("")
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
1635 Cell tcell = (t2.iscell () ? 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
1636
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1637 m.assign (dsub.name, tcell);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1638
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1639 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1640
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1641 if (retval2 >= 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1642 {
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1643 m_map = m;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1644
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20939
diff changeset
1645 if (! reconstruct_parents ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1646 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
1647
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1648 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1649
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1650 octave::load_path& lp = interp.get_load_path ();
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
1651
31838
45f8b601c992 maint: Use "m_" prefix on all private member variables in classes.
Rik <rik@octave.org>
parents: 31837
diff changeset
1652 if (lp.find_method (m_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
1653 {
9849075a5da6 allow objects to load if constructor fails but loadobj method succeeds
John W. Eaton <jwe@octave.org>
parents: 16071
diff changeset
1654 octave_value in = new octave_class (*this);
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31718
diff changeset
1655 octave_value_list tmp = interp.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
1656
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1657 m_map = tmp(0).map_value ();
20561
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1658 retval = true;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1659 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1660 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1661
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1662 error_cleanup:
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1663 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1664 H5Dclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1665
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1666 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1667 H5Gclose (group_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1668
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
1669 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1670 octave_unused_parameter (loc_id);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1671 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
1672
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
1673 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
1674 #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
1675
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1676 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1677 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1678
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1679 mxArray *
28126
4c21f99b4ad5 handle interleaved complex data and new typed data access functions for mex
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
1680 octave_class::as_mxArray (bool) const
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1681 {
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21072
diff changeset
1682 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
1683 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1684
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1685 bool
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
1686 octave_class::in_class_method ()
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1687 {
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 30888
diff changeset
1688 octave::tree_evaluator& tw = octave::__get_evaluator__ ();
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23519
diff changeset
1689
27210
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 26922
diff changeset
1690 octave_function *fcn = tw.current_function ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1691
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1692 return (fcn
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1693 && (fcn->is_class_method ()
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1694 || fcn->is_class_constructor ()
13241
2a8dcb5b3a00 improve default indexing for objects
John W. Eaton <jwe@octave.org>
parents: 13112
diff changeset
1695 || fcn->is_anonymous_function_of_class ()
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1696 || fcn->is_private_function_of_class (class_name ()))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10272
diff changeset
1697 && find_parent_class (fcn->dispatch_class ()));
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1698 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1699
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1700 octave_class::exemplar_info::exemplar_info (const octave_value& obj)
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1701 : m_field_names (), m_parent_class_names ()
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1702 {
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
1703 if (! obj.isobject ())
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1704 error ("invalid call to exemplar_info constructor");
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1705
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1706 octave_map m = obj.map_value ();
29466
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1707 m_field_names = m.keys ();
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1708
7c8a70e4daad use "m_" prefix for class members in a few more classes
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1709 m_parent_class_names = obj.parent_class_name_list ();
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1710 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1711
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1712 // A map from class names to lists of fields.
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1713 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
1714
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1715 bool
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1716 octave_class::exemplar_info::compare (const octave_value& obj) const
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1717 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1718
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
1719 if (! obj.isobject ())
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1720 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
1721
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1722 if (nfields () != obj.nfields ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1723 error ("mismatch in number of fields");
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1724
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1725 octave_map obj_map = obj.map_value ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1726 string_vector obj_fnames = obj_map.keys ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1727 string_vector fnames = fields ();
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1728
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1729 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
1730 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1731 if (obj_fnames[i] != fnames[i])
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1732 error ("mismatch in field names");
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1733 }
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1734
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1735 if (nparents () != obj.nparents ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1736 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
1737
25342
416856765a55 be more careful with using auto in place of explicit const iterator decls
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1738 const std::list<std::string> obj_parents
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1739 = obj.parent_class_name_list ();
25342
416856765a55 be more careful with using auto in place of explicit const iterator decls
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1740 const 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
1741
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
1742 auto p = obj_parents.begin ();
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
1743 auto q = pnames.begin ();
20979
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1744
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1745 while (p != obj_parents.end ())
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1746 {
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1747 if (*p++ != *q++)
0963ed389012 maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1748 error ("mismatch in parent classes");
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1749 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1750
20879
5357423bca0a Code Sprint 2015: remove return/break/goto after error
Andreas Weber <andy.weber.aw@gmail.com>
parents: 20853
diff changeset
1751 return true;
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1752 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1753
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31594
diff changeset
1754 OCTAVE_BEGIN_NAMESPACE(octave)
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29956
diff changeset
1755
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23519
diff changeset
1756 DEFMETHOD (class, interp, args, ,
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23519
diff changeset
1757 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
1758 @deftypefn {} {@var{classname} =} class (@var{obj})
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
1759 @deftypefnx {} {@var{cls} =} class (@var{s}, @var{classname})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
1760 @deftypefnx {} {@var{cls} =} class (@var{s}, @var{classname}, @var{parent1}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
1761 Return the class of the object @var{obj}, or create a class with fields from
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
1762 structure @var{s} and name (string) @var{classname}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
1763
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
1764 Additional arguments name a list of parent classes from which the new class is
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
1765 derived.
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 @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
1767 @end deftypefn */)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1768 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1769 int nargin = args.length ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1770
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1771 if (nargin == 0)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1772 print_usage ();
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1773
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1774 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1775
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1776 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
1777 // 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
1778 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
1779 else
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1780 {
15811
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1781 // 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
1782 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
1783
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1784 tree_evaluator& tw = interp.get_evaluator ();
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23519
diff changeset
1785
27210
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 26922
diff changeset
1786 octave_function *fcn = tw.caller_function ();
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1787
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1788 if (! fcn)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1789 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
1790
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1791 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
1792 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
1793 id.c_str ());
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1794
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1795 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
1796
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1797 if (nargin == 2)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1798 retval
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1799 = 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
1800 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1801 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1802 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
1803
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1804 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
1805 }
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1806
25342
416856765a55 be more careful with using auto in place of explicit const iterator decls
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1807 octave_class::exemplar_const_iterator it
416856765a55 be more careful with using auto in place of explicit const iterator decls
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
1808 = octave_class::exemplar_map.find (id);
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1809
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1810 if (it == octave_class::exemplar_map.end ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1811 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
1812 else if (! it->second.compare (retval))
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1813 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
1814 id.c_str ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1815 }
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1816
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1817 return retval;
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1818 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1819
15811
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1820 /*
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1821 %!assert (class (1.1), "double")
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1822 %!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
1823 %!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
1824 %!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
1825 %! 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
1826 %! 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
1827
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22497
diff changeset
1828 ## 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
1829 %!error class ()
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1830 */
317f4857c1e1 Modify class() to return Java class name, not type name "octave_java".
Rik <rik@octave.org>
parents: 15785
diff changeset
1831
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1832 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
1833 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30346
diff changeset
1834 @deftypefn {} {@var{tf} =} isa (@var{obj}, @var{classname})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1835 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
1836
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1837 @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
1838
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1839 @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
1840 @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
1841 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
1842 @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
1843
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1844 @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
1845 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
1846
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1847 @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
1848 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
1849 @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
1850
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1851 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
1852 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
1853 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
1854
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1855 @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
1856 @end deftypefn */)
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1857 {
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1858 if (args.length () != 2)
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1859 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
1860
20495
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1861 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
1862 std::string obj_cls = obj.class_name ();
31718
52a5bec0fc74 style fixes: avoid breaking lines after "(" and prefer "" over QString ("")
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
1863 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
1864
20495
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1865 boolNDArray matches (clsnames.dims (), false);
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1866
20495
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1867 for (octave_idx_type idx = 0; idx < clsnames.numel (); idx++)
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1868 {
20495
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1869 std::string cls = clsnames(idx);
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1870 if (obj_cls == cls
23585
570170b6eb09 maint: Deprecate is_float_type and replace with isfloat.
Rik <rik@octave.org>
parents: 23584
diff changeset
1871 || (cls == "float" && obj.isfloat ())
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23577
diff changeset
1872 || (cls == "integer" && obj.isinteger ())
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
1873 || (cls == "numeric" && obj.isnumeric ())
20495
bf6c4433ed5f Clean up isa() function.
Rik <rik@octave.org>
parents: 20447
diff changeset
1874 || 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
1875 matches(idx) = true;
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1876 }
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1877
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1878 return ovl (matches);
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1879 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1880
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1881 /*
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1882 %!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
1883 %!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
1884 %!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
1885 %!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
1886 %!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
1887 %!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
1888 %!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
1889 %!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
1890 %!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
1891 %!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
1892 %!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
1893 %!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
1894 %!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
1895 %!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
1896 %!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
1897 %!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
1898 %!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
1899 %!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
1900 %!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
1901 %!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
1902 %!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
1903 %!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
1904 %!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
1905 %!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
1906 %!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
1907 %!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
1908 %!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
1909 %!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
1910
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1911 %!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
1912 %!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
1913 %!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
1914 %!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
1915 %!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
1916 %!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
1917 %!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
1918 %!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
1919 %!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
1920 %!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
1921 %!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
1922 %!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
1923 %!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
1924 %!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
1925 %!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
1926
23405
32ec90068be5 use %!testif runtime tests to properly skip java tests
John W. Eaton <jwe@octave.org>
parents: 23352
diff changeset
1927 %!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
1928 %! ## 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
1929 %! ## 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
1930 %! ## 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
1931 %! ## 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
1932 %! 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
1933 %! 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
1934 %! 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
1935
18033
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1936 %!test
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1937 %! 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
1938 %! 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
1939 */
2627aeca5032 isa: allow cell array of class names as input, plus remove __isa_parent__().
Carnë Draug <carandraug@octave.org>
parents: 17787
diff changeset
1940
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1941 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
1942 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
1943 @deftypefn {} {@var{Ccls} =} __parent_classes__ (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1944 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
1945 @end deftypefn */)
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1946 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1947 if (args.length () != 1)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1948 print_usage ();
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1949
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1950 octave_value arg = args(0);
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1951
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
1952 if (arg.isobject ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1953 return ovl (Cell (arg.parent_class_names ()));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1954 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
1955 return ovl (Cell ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1956 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1957
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1958 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
1959 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30346
diff changeset
1960 @deftypefn {} {@var{tf} =} isobject (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1961 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
1962 @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
1963 @end deftypefn */)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1964 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1965 if (args.length () != 1)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1966 print_usage ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1967
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
1968 return ovl (args(0).isobject ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1969 }
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 static bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1972 is_built_in_class (const std::string& cn)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1973 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1974 static std::set<std::string> built_in_class_names;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1975
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1976 if (built_in_class_names.empty ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1977 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1978 built_in_class_names.insert ("double");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1979 built_in_class_names.insert ("single");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1980 built_in_class_names.insert ("cell");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1981 built_in_class_names.insert ("struct");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1982 built_in_class_names.insert ("logical");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1983 built_in_class_names.insert ("char");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1984 built_in_class_names.insert ("function handle");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1985 built_in_class_names.insert ("int8");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1986 built_in_class_names.insert ("uint8");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1987 built_in_class_names.insert ("int16");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1988 built_in_class_names.insert ("uint16");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1989 built_in_class_names.insert ("int32");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1990 built_in_class_names.insert ("uint32");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1991 built_in_class_names.insert ("int64");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1992 built_in_class_names.insert ("uint64");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1993 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1994
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1995 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
1996 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1997
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23519
diff changeset
1998 DEFMETHOD (superiorto, interp, args, ,
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23519
diff changeset
1999 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
2000 @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
2001 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
2002 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
2003
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2004 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
2005 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
2006 @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
2007 @end deftypefn */)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2008 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
2009 tree_evaluator& tw = interp.get_evaluator ();
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23519
diff changeset
2010
27210
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 26922
diff changeset
2011 octave_function *fcn = tw.caller_function ();
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23519
diff changeset
2012
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
2013 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
2014 error ("superiorto: invalid call from outside class constructor");
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2015
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2016 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
2017 {
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20700
diff changeset
2018 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
2019
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2020 // 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
2021 // 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
2022 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
2023 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2024
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
2025 symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
2026
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2027 std::string sup_class = fcn->name ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
2028 if (! symtab.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
2029 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
2030 sup_class.c_str (), inf_class.c_str ());
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2031 }
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2032
21125
8f76684324b5 maint: change "return octave_value ()" to "return ovl ()".
Rik <rik@octave.org>
parents: 21118
diff changeset
2033 return ovl ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2034 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2035
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23519
diff changeset
2036 DEFMETHOD (inferiorto, interp, args, ,
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23519
diff changeset
2037 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
2038 @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
2039 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
2040 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
2041
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
2042 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
2043 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
2044 @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
2045 @end deftypefn */)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2046 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
2047 tree_evaluator& tw = interp.get_evaluator ();
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23519
diff changeset
2048
27210
bd684aad1821 eliminate some direct access to call stack in legacy class and function objects
John W. Eaton <jwe@octave.org>
parents: 26922
diff changeset
2049 octave_function *fcn = tw.caller_function ();
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23519
diff changeset
2050
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20879
diff changeset
2051 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
2052 error ("inferiorto: invalid call from outside class constructor");
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2053
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2054 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
2055 {
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20700
diff changeset
2056 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
2057
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2058 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
2059 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
2060 "precedence than built-in class");
16071
94e95309710c Whitespace cleanup
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 16070
diff changeset
2061
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
2062 symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
2063
16070
e603ce23f20c Fix and improve functions related to class precedence (bug #38290)
Julien Bect <julien.bect@supelec.fr>
parents: 15813
diff changeset
2064 std::string inf_class = fcn->name ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
2065 if (! symtab.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
2066 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
2067 inf_class.c_str (), sup_class.c_str ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2068 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2069
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
2070 return ovl ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2071 }
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2072
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2073 // The following classes allow us to define "inline" function objects as
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2074 // legacy @class objects (as they appear to be in Matlab) while
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2075 // preserving the is_inline_function and function_value methods that
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2076 // were previously available in the octave_fcn_inline class. However,
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2077 // inline function objects no longer behave as octave_fcn_handle objects
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2078 // so calling is_function_handle for them no longer returns true. I see
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2079 // no reasonable way to preserve that behavior. The goal here is to
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2080 // allow most code that used the old octave_inline_fcn object to
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2081 // continue to work while eliminating the octave_inline_fcn class that
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2082 // was derived from the octave_fcn_handle class. Making that change
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2083 // appears to be necessary to properly fix function handle behavior and
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2084 // improve Matlab compatibility. It's unfortunate if this change causes
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2085 // trouble, but I see no better fix. Ultimately, we should replace all
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2086 // uses of "inline" function objects with anonymous functions.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2087
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2088 class octave_inline;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2089
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2090 // The following class can be removed once the
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2091 // octave_value::function_value method is removed.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2092
32628
ae4e19c0a2b1 maint: Place class name and class keyword on one line.
Rik <rik@octave.org>
parents: 32598
diff changeset
2093 class octave_inline_fcn : public octave_function
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2094 {
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2095 public:
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2096
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2097 octave_inline_fcn (octave_inline *obj) : m_inline_obj (obj) { }
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2098
31837
febd82d1a8de use new macros to consistently delete copy and move member functions
John W. Eaton <jwe@octave.org>
parents: 31814
diff changeset
2099 OCTAVE_DISABLE_COPY_MOVE (octave_inline_fcn)
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2100
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
2101 ~octave_inline_fcn () = default;
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2102
28429
8eb8ba8aff9a refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
2103 // Override default call method because we ultimately use feval to
8eb8ba8aff9a refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
2104 // execute the inline function and that will push a stack frame.
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2105
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2106 octave_value_list
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
2107 call (tree_evaluator& tw, int nargout = 0,
28429
8eb8ba8aff9a refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
2108 const octave_value_list& args = octave_value_list ())
8eb8ba8aff9a refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
2109 {
8eb8ba8aff9a refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
2110 return execute (tw, nargout, args);
8eb8ba8aff9a refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
2111 }
8eb8ba8aff9a refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
2112
8eb8ba8aff9a refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
2113 octave_value_list
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
2114 execute (tree_evaluator& tw, int nargout = 0,
28429
8eb8ba8aff9a refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
2115 const octave_value_list& args = octave_value_list ());
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2116
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2117 private:
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2118
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2119 octave_inline *m_inline_obj;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2120 };
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2121
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2122 // Once the octave_inline_fcn class is removed, we should also be able
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2123 // to eliminate the octave_inline class below and replace the
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2124 // octave_value::is_inline_function method with
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2125 //
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
2126 // bool octave_value::is_inline_function () const
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2127 // {
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2128 // return class_name () == "inline";
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2129 // }
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2130
32628
ae4e19c0a2b1 maint: Place class name and class keyword on one line.
Rik <rik@octave.org>
parents: 32598
diff changeset
2131 class octave_inline : public octave_class
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2132 {
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2133 public:
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2134
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2135 octave_inline (const octave_map& m)
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2136 : octave_class (m, "inline"), m_fcn_obj (new octave_inline_fcn (this))
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2137 { }
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2138
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2139 octave_inline (const octave_inline&) = default;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2140
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
2141 ~octave_inline () = default;
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
2142
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
2143 octave_base_value * clone () const { return new octave_inline (*this); }
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
2144
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
2145 octave_base_value * empty_clone () const
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2146 {
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2147 return new octave_inline (octave_map (map_keys ()));
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2148 }
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2149
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
2150 bool is_inline_function () const { return true; }
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2151
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2152 octave_function * function_value (bool)
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2153 {
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2154 return m_fcn_obj.get ();
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2155 }
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2156
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2157 private:
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2158
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2159 std::shared_ptr<octave_inline_fcn> m_fcn_obj;
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2160 };
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2161
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2162 octave_value_list
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
2163 octave_inline_fcn::execute (tree_evaluator& tw, int nargout,
28429
8eb8ba8aff9a refactor octave_function call method
John W. Eaton <jwe@octave.org>
parents: 28427
diff changeset
2164 const octave_value_list& args)
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2165 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
2166 interpreter& interp = tw.get_interpreter ();
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2167
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2168 return interp.feval (octave_value (m_inline_obj, true), args, nargout);
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2169 }
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2170
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2171
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2172 DEFUN (__inline_ctor__, args, ,
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2173 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
2174 @deftypefn {} {@var{inline_obj} =} __inline_ctor__ (@var{prop_struct})
31594
a3d8915b9f87 doc: more DOCSTRING changes ahead of 8.1 release.
Rik <rik@octave.org>
parents: 31105
diff changeset
2175 Implement final construction for inline objects.
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2176 @end deftypefn */)
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2177 {
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2178 // Input validation has already been done in input.m.
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2179 return octave_value (new octave_inline (args(0).map_value ()));
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
2180 }
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29956
diff changeset
2181
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31594
diff changeset
2182 OCTAVE_END_NAMESPACE(octave)