annotate src/ov-class.cc @ 12178:a71c1aa9823e

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