annotate src/ov-class.cc @ 9521:e08d72bb988e

simplify cloning
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 13 Aug 2009 11:52:07 +0200
parents 610bf90fce2a
children e79470be3ecb
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
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8785
diff changeset
3 Copyright (C) 2007, 2008, 2009 John W. Eaton
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
4
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
6
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
7 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
8 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
9 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
10 option) any later version.
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
11
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
12 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
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
14 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
15 for more details.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
16
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
17 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
18 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
19 <http://www.gnu.org/licenses/>.
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
20
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 #ifdef HAVE_CONFIG_H
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
25 #endif
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
26
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
27 #include <iostream>
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
28
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
29 #include "Array-util.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
30 #include "byte-swap.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8219
diff changeset
31 #include "oct-locbuf.h"
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
32 #include "lo-mappers.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
33
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
34 #include "Cell.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
35 #include "defun.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
36 #include "error.h"
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
37 #include "file-ops.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
38 #include "gripes.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
39 #include "load-path.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
40 #include "ls-hdf5.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
41 #include "ls-oct-ascii.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
42 #include "ls-oct-binary.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
43 #include "ls-utils.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
44 #include "oct-lvalue.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
45 #include "ov-class.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
46 #include "ov-fcn.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
47 #include "pager.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
48 #include "parse.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
49 #include "pr-output.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
50 #include "toplev.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
51 #include "unwind-prot.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
52 #include "variables.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
53
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
54 DEFINE_OCTAVE_ALLOCATOR(octave_class);
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 int octave_class::t_id (-1);
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 const std::string octave_class::t_name ("class");
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 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
61 octave_class::register_type (void)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
62 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
63 t_id = octave_value_typeinfo::register_type
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
64 (octave_class::t_name, "<unknown>", octave_value (new octave_class ()));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
65 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
66
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
67 octave_class::octave_class (const Octave_map& m, const std::string& id,
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
68 const octave_value_list& parents)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
69 : octave_base_value (), map (m), c_name (id)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
70 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
71 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
72
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
73 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
74 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
75 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
76
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
77 if (! parent.is_object ())
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
78 error ("parents must be objects");
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
79 else
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
80 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
81 std::string cnm = parent.class_name ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
82
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
83 if (find_parent_class (cnm))
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
84 error ("duplicate class in parent tree");
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
85 else
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
86 {
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
87 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
88
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
89 map.assign (cnm, parent);
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
90 }
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
91 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
92 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
93
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
94 if (! error_state)
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
95 load_path::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
96 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
97
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
98 static std::string
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
99 get_current_method_class (void)
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
100 {
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
101 std::string retval;
b2b8ed43b922 ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents: 9151
diff changeset
102
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
103 octave_function *fcn = octave_call_stack::current ();
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
104
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
105 std::string my_dir = fcn->dir_name ();
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
106
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
107 std::string method_class = file_ops::tail (my_dir);
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
108
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
109 retval = method_class.substr (1);
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
110
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
111 return retval;
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
112 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
113
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
114 static void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
115 gripe_invalid_index (void)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
116 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
117 error ("invalid index for class");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
118 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
119
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
120 static void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
121 gripe_invalid_index_for_assignment (void)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
122 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
123 error ("invalid index for class assignment");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
124 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
125
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
126 static void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
127 gripe_invalid_index_type (const std::string& nm, char t)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
128 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
129 error ("%s cannot be indexed with %c", nm.c_str (), t);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
130 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
131
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
132 static void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
133 gripe_failed_assignment (void)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
134 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
135 error ("assignment to class element failed");
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
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
138 static inline octave_value_list
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
139 sanitize (const octave_value_list& ovl)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
140 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
141 octave_value_list retval = ovl;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
142
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
143 for (octave_idx_type i = 0; i < ovl.length (); i++)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
144 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
145 if (retval(i).is_magic_colon ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
146 retval(i) = ":";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
147 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
148
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
149 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
150 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
151
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
152 static inline octave_value
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
153 make_idx_args (const std::string& type,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
154 const std::list<octave_value_list>& idx,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
155 const std::string& who)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
156 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
157 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
158
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
159 size_t len = type.length ();
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 if (len == idx.size ())
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 Cell type_field (len, 1);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
164 Cell subs_field (len, 1);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
165
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
166 std::list<octave_value_list>::const_iterator p = idx.begin ();
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 for (size_t i = 0; i < len; i++)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
169 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
170 char t = type[i];
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 switch (t)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
173 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
174 case '(':
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
175 type_field(i) = "()";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
176 subs_field(i) = Cell (sanitize (*p++));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
177 break;
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 case '{':
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
180 type_field(i) = "{}";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
181 subs_field(i) = Cell (sanitize (*p++));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
182 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
183
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
184 case '.':
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 type_field(i) = ".";
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 octave_value_list vlist = *p++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
189
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
190 if (vlist.length () == 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
191 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
192 octave_value val = vlist(0);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
193
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
194 if (val.is_string ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
195 subs_field(i) = val;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
196 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
197 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
198 error ("expecting character string argument for `.' index");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
199 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
200 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
201 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
202 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
203 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
204 error ("expecting single argument for `.' index");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
205 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
206 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
207 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
208 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
209
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
210 default:
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
211 panic_impossible ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
212 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
213 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
214 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
215
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
216 Octave_map m;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
217
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
218 m.assign ("type", type_field);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
219 m.assign ("subs", subs_field);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
220
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
221 retval = m;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
222 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
223 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
224 error ("invalid index for %s", who.c_str ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
225
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
226 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
227 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
228
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
229 Cell
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
230 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
231 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
232 Cell retval;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
233
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
234 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
235
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
236 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
237
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
238 // 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
239 // 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
240
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
241 octave_base_value *obvp
b2b8ed43b922 ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents: 9151
diff changeset
242 = method_class.empty () ? 0 : 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
243
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
244 Octave_map my_map;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
245
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
246 my_map = obvp ? obvp->map_value () : map;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
247
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
248 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
249
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
250 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
251 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
252 Octave_map::const_iterator p = my_map.seek (nm);
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 if (p != my_map.end ())
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
255 retval = my_map.contents (p);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
256 else
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
257 error ("class has no member `%s'", nm.c_str ());
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
258 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
259 else
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
260 gripe_invalid_index ();
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
261
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
262 return retval;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
263 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
264
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
265 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
266 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
267 {
b2b8ed43b922 ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents: 9151
diff changeset
268 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
269
b2b8ed43b922 ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents: 9151
diff changeset
270 // 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
271 // 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
272 // 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
273 // 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
274 // 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
275
b2b8ed43b922 ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents: 9151
diff changeset
276 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
277 }
b2b8ed43b922 ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents: 9151
diff changeset
278
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
279 Matrix
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
280 octave_class::size (void)
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
281 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
282 Matrix retval (1, 2, 1.0);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
283 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
284
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
285 if (meth.is_defined ())
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
286 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
287 count++;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
288 octave_value_list args (1, octave_value (this));
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
289
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
290 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
291 if (lv.length () == 1 && lv(0).is_matrix_type () && lv(0).dims ().is_vector ())
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
292 retval = lv(0).matrix_value ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
293 else
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
294 error ("@%s/size: invalid return value");
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
295 }
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
296
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
297 return retval;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
298 }
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
299
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
300 octave_idx_type
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
301 octave_class::numel (const octave_value_list& idx)
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
302 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
303 octave_idx_type retval = -1;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
304 const std::string cn = class_name ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
305
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
306 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
307
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
308 if (meth.is_defined ())
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
309 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
310 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
311
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
312 count++;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
313 args(0) = octave_value (this);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
314
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
315 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
316 args(i+1) = idx(i);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
317
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
318 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
319 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
320 retval = lv(0).idx_type_value (true);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
321 else
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
322 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
323 }
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
324 else
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 // If method is not found, calculate using size ().
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
327 const Matrix mdv = size ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
328 octave_idx_type nmdv = mdv.numel ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
329 dim_vector dv; dv.resize (std::max (nmdv, 2));
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
330 for (octave_idx_type i = 0; i < nmdv && !error_state; i++)
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
331 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
332 if (mdv(i) == xround (mdv(i)) && xfinite (mdv(i)) && mdv(i) >= 0)
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
333 dv(i) = mdv(i);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
334 else
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
335 error ("@%s/numel: expected nonnegative integers from @%s/size",
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
336 cn.c_str (), cn.c_str ());
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
337 }
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 if (! error_state)
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 octave_idx_type len = idx.length ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
342 if (len == 0)
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
343 retval = dv.numel ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
344 else
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
345 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
346 dv = dv.redim (len);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
347 retval = 1;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
348 for (octave_idx_type i = 0; i < len; i++)
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
349 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
350 if (idx(i).is_magic_colon ())
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
351 retval *= dv(i);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
352 else
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
353 retval *= idx(i).numel ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
354 }
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 }
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 }
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
359
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
360 return retval;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
361 }
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
362
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
363 octave_value_list
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
364 octave_class::subsref (const std::string& type,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
365 const std::list<octave_value_list>& idx,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
366 int nargout)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
367 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
368 octave_value_list retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
369
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
370 if (in_class_method () || called_from_builtin ())
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
371 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
372 // FIXME -- this block of code is the same as the body of
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
373 // octave_struct::subsref. Maybe it could be shared instead of
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
374 // duplicated.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
375
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
376 int skip = 1;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
377
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
378 switch (type[0])
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
379 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
380 case '(':
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
381 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
382 if (type.length () > 1 && type[1] == '.')
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
383 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
384 std::list<octave_value_list>::const_iterator p = idx.begin ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
385 octave_value_list key_idx = *++p;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
386
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
387 Cell tmp = dotref (key_idx);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
388
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
389 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
390 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
391 Cell t = tmp.index (idx.front ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
392
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
393 retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
394
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
395 // We handled two index elements, so tell
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
396 // next_subsref to skip both of them.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
397
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
398 skip++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
399 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
400 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
401 else
8782
45524925bed9 ov-class.cc (octave_class::subsref): return class object, not struct when indexing directly
John W. Eaton <jwe@octave.org>
parents: 8746
diff changeset
402 retval(0) = octave_value (map.index (idx.front ()),
45524925bed9 ov-class.cc (octave_class::subsref): return class object, not struct when indexing directly
John W. Eaton <jwe@octave.org>
parents: 8746
diff changeset
403 class_name ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
404 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
405 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
406
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
407 case '.':
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
408 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
409 if (map.numel() > 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
410 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
411 Cell t = dotref (idx.front ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
412
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
413 retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
414 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
415 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
416 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
417
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
418 case '{':
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
419 gripe_invalid_index_type (type_name (), type[0]);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
420 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
421
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
422 default:
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
423 panic_impossible ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
424 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
425
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
426 // FIXME -- perhaps there should be an
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
427 // octave_value_list::next_subsref member function? See also
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
428 // octave_user_function::subsref.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
429
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
430 if (idx.size () > 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
431 retval = retval(0).next_subsref (nargout, type, idx, skip);
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 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
434 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
435 octave_value meth = symbol_table::find_method ("subsref", class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
436
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
437 if (meth.is_defined ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
438 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
439 octave_value_list args;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
440
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
441 args(1) = make_idx_args (type, idx, "subsref");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
442
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
443 if (error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
444 return octave_value_list ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
445
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
446 count++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
447 args(0) = octave_value (this);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
448
9331
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
449 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
450 || (type.length () > 1 && type[0] == '('
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
451 && type[1] == '.'));
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
452
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
453 if (nargout == 1 && maybe_cs_list_query)
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
454 {
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
455 // 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
456 octave_value_list tmp;
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
457 if (type[0] != '.') tmp = idx.front ();
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
458 octave_idx_type true_nargout = numel (tmp);
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
459 if (! error_state)
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
460 {
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
461 tmp = feval (meth.function_value (), args, true_nargout);
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
462 if (true_nargout != 1)
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
463 retval(0) = octave_value (tmp, true);
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
464 else
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
465 retval = tmp;
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
466 }
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
467 }
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
468 else
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
469 retval = feval (meth.function_value (), args, nargout);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
470 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
471 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
472 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
473 if (type.length () == 1 && type[0] == '(')
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
474 retval(0) = octave_value (map.index (idx.front ()), class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
475 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
476 gripe_invalid_index ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
477 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
478 }
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 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
481 }
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 octave_value
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
484 octave_class::numeric_conv (const Cell& val, const std::string& type)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
485 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
486 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
487
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
488 if (val.length () == 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
489 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
490 retval = val(0);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
491
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
492 if (type.length () > 0 && type[0] == '.' && ! retval.is_map ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
493 retval = Octave_map ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
494 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
495 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
496 gripe_invalid_index_for_assignment ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
497
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
498 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
499 }
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 octave_value
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
502 octave_class::subsasgn (const std::string& type,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
503 const std::list<octave_value_list>& idx,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
504 const octave_value& rhs)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
505 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
506 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
507
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
508 if (! (in_class_method () || called_from_builtin ()))
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
509 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
510 octave_value meth = symbol_table::find_method ("subsasgn", class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
511
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
512 if (meth.is_defined ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
513 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
514 octave_value_list args;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
515
9333
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
516 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
517 {
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
518 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
519 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
520 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
521 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
522 }
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
523 else
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
524 args(2) = rhs;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
525
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
526 args(1) = make_idx_args (type, idx, "subsasgn");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
527
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
528 if (error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
529 return octave_value_list ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
530
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
531 count++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
532 args(0) = octave_value (this);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
533
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
534 octave_value_list tmp = feval (meth.function_value (), args);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
535
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
536 // FIXME -- should the subsasgn method be able to return
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
537 // more than one value?
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
538
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
539 if (tmp.length () > 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
540 error ("expecting single return value from @%s/subsasgn",
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
541 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
542
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
543 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
544 retval = tmp(0);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
545
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
546 return retval;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
547 }
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
548 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
549
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
550 // FIXME -- this block of code is the same as the body of
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
551 // octave_struct::subsasgn. Maybe it could be shared instead of
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
552 // duplicated.
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
553
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
554 int n = type.length ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
555
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
556 octave_value t_rhs = rhs;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
557
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
558 if (n > 1 && ! (type.length () == 2 && type[0] == '(' && type[1] == '.'))
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
559 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
560 switch (type[0])
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
561 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
562 case '(':
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
563 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
564 if (type.length () > 1 && type[1] == '.')
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
565 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
566 std::list<octave_value_list>::const_iterator p = idx.begin ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
567 octave_value_list t_idx = *p;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
568
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
569 octave_value_list key_idx = *++p;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
570
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
571 assert (key_idx.length () == 1);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
572
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
573 std::string key = key_idx(0).string_value ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
574
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
575 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
576 {
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
577 octave_value u;
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
578
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
579 if (! map.contains (key))
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
580 u = octave_value::empty_conv (type.substr (2), rhs);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
581 else
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
582 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
583 Cell map_val = map.contents (key);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
584
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
585 Cell map_elt = map_val.index (idx.front (), true);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
586
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
587 u = numeric_conv (map_elt, type.substr (2));
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
588 }
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
589
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
590 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
591 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
592 std::list<octave_value_list> next_idx (idx);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
593
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
594 // We handled two index elements, so subsasgn to
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
595 // needs to skip both of them.
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
596
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
597 next_idx.erase (next_idx.begin ());
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
598 next_idx.erase (next_idx.begin ());
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
599
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
600 u.make_unique ();
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
601
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
602 t_rhs = u.subsasgn (type.substr (2), next_idx, rhs);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
603 }
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
604 }
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
605 else
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
606 gripe_invalid_index_for_assignment ();
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
607 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
608 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
609 gripe_invalid_index_for_assignment ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
610 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
611 break;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
612
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
613 case '.':
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
614 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
615 octave_value_list key_idx = idx.front ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
616
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
617 assert (key_idx.length () == 1);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
618
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
619 std::string key = key_idx(0).string_value ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
620
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
621 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
622 {
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
623 octave_value u;
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
624
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
625 if (! map.contains (key))
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
626 u = octave_value::empty_conv (type.substr (1), rhs);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
627 else
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
628 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
629 Cell map_val = map.contents (key);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
630
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
631 u = numeric_conv (map_val, type.substr (1));
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
632 }
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
633
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
634 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
635 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
636 std::list<octave_value_list> next_idx (idx);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
637
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
638 next_idx.erase (next_idx.begin ());
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
639
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
640 u.make_unique ();
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
641
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
642 t_rhs = u.subsasgn (type.substr (1), next_idx, rhs);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
643 }
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
644 }
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
645 else
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
646 gripe_invalid_index_for_assignment ();
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
647 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
648 break;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
649
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
650 case '{':
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
651 gripe_invalid_index_type (type_name (), type[0]);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
652 break;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
653
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
654 default:
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
655 panic_impossible ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
656 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
657 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
658
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
659 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
660 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
661 switch (type[0])
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
662 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
663 case '(':
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
664 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
665 if (n > 1 && type[1] == '.')
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
666 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
667 std::list<octave_value_list>::const_iterator p = idx.begin ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
668 octave_value_list key_idx = *++p;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
669
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
670 assert (key_idx.length () == 1);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
671
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
672 std::string key = key_idx(0).string_value ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
673
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
674 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
675 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
676 map.assign (idx.front (), key, t_rhs);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
677
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
678 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
679 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
680 count++;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
681 retval = octave_value (this);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
682 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
683 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
684 gripe_failed_assignment ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
685 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
686 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
687 gripe_failed_assignment ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
688 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
689 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
690 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
691 if (t_rhs.is_object () || t_rhs.is_map ())
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
692 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
693 Octave_map rhs_map = t_rhs.map_value ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
694
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
695 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
696 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
697 map.assign (idx.front (), rhs_map);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
698
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
699 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
700 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
701 count++;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
702 retval = octave_value (this);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
703 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
704 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
705 gripe_failed_assignment ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
706 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
707 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
708 error ("invalid class assignment");
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
709 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
710 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
711 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
712 if (t_rhs.is_empty ())
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
713 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
714 map.maybe_delete_elements (idx.front());
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
715
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
716 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
717 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
718 count++;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
719 retval = octave_value (this);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
720 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
721 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
722 gripe_failed_assignment ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
723 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
724 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
725 error ("invalid class assignment");
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
726 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
727 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
728 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
729 break;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
730
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
731 case '.':
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
732 {
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
733 // Find the class in which this method resides before
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
734 // attempting to access the requested field.
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
735
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
736 std::string method_class = get_current_method_class ();
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
737
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
738 octave_base_value *obvp = find_parent_class (method_class);
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
739
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
740 if (obvp)
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
741 {
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
742 octave_value_list key_idx = idx.front ();
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
743
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
744 assert (key_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
745
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
746 std::string key = key_idx(0).string_value ();
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
747
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
748 if (! error_state)
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
749 {
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
750 obvp->assign (key, t_rhs);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
751
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
752 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
753 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
754 count++;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
755 retval = octave_value (this);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
756 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
757 else
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
758 gripe_failed_assignment ();
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
759 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
760 else
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
761 gripe_failed_assignment ();
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
762 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
763 else
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
764 error ("malformed class");
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
765 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
766 break;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
767
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
768 case '{':
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
769 gripe_invalid_index_type (type_name (), type[0]);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
770 break;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
771
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
772 default:
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
773 panic_impossible ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
774 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
775 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
776 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
777 gripe_failed_assignment ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
778
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
779 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
780 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
781
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
782 idx_vector
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
783 octave_class::index_vector (void) const
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
784 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
785 idx_vector retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
786
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
787 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
788
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
789 if (meth.is_defined ())
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
790 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
791 octave_value_list args;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
792 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
793
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
794 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
795
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
796 if (!error_state && tmp.length () >= 1)
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
797 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
798 if (tmp(0).is_object())
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
799 error ("subsindex function must return a valid index vector");
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
800 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
801 // Index vector returned by subsindex is zero based
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
802 // (why this inconsistency Mathworks?), and so we must
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
803 // add one to the value returned as the index_vector method
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
804 // expects it to be one based.
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
805 retval = do_binary_op (octave_value::op_add, tmp (0),
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
806 octave_value (1.0)).index_vector ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
807 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
808 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
809 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
810 error ("no subsindex method defined for class %s",
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
811 class_name().c_str ());
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
812
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
813 return retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
814 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
815
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
816 size_t
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
817 octave_class::byte_size (void) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
818 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
819 // Neglect the size of the fieldnames.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
820
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
821 size_t retval = 0;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
822
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
823 for (Octave_map::const_iterator p = map.begin (); p != map.end (); p++)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
824 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
825 std::string key = map.key (p);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
826
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
827 octave_value val = octave_value (map.contents (p));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
828
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
829 retval += val.byte_size ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
830 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
831
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
832 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
833 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
834
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
835 string_vector
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
836 octave_class::map_keys (void) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
837 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
838 string_vector retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
839 gripe_wrong_type_arg ("octave_class::map_keys()", type_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
840 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
841 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
842
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
843 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
844 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
845 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
846 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
847
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
848 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
849 retval = this;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
850 else
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
851 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
852 for (std::list<std::string>::iterator pit = parent_list.begin ();
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
853 pit != parent_list.end ();
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
854 pit++)
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
855 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
856 Octave_map::const_iterator smap = map.seek (*pit);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
857
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
858 const Cell& tmp = smap->second;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
859
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
860 octave_value vtmp = tmp(0);
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
861
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
862 octave_base_value *obvp = vtmp.internal_rep ();
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
863
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
864 retval = obvp->find_parent_class (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
865
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
866 if (retval)
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
867 break;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
868 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
869 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
870
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
871 return retval;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
872 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
873
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
874 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
875 octave_class::print (std::ostream& os, bool) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
876 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
877 print_raw (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
878 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
879
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
880 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
881 octave_class::print_raw (std::ostream& os, bool) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
882 {
9377
610bf90fce2a update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents: 9333
diff changeset
883 unwind_protect::frame_id_t uwp_frame = unwind_protect::begin_frame ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
884
9377
610bf90fce2a update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents: 9333
diff changeset
885 unwind_protect::protect_var (Vstruct_levels_to_print);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
886
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
887 indent (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
888 os << " <class " << class_name () << ">";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
889 newline (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
890
9377
610bf90fce2a update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents: 9333
diff changeset
891 unwind_protect::run_frame (uwp_frame);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
892 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
893
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
894 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
895 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
896 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
897 bool retval = false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
898
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
899 indent (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
900 os << name << " =";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
901 newline (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
902 newline (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
903
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
904 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
905 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
906
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
907 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
908 octave_class::print_with_name (std::ostream&, const std::string& name,
9521
e08d72bb988e simplify cloning
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
909 bool)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
910 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
911 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
912
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
913 if (fcn.is_defined ())
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
914 {
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
915 octave_value_list args;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
916
9521
e08d72bb988e simplify cloning
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
917 count++;
e08d72bb988e simplify cloning
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
918 args(0) = octave_value (this);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
919
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
920 string_vector arg_names (1);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
921
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
922 arg_names[0] = name;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
923
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
924 args.stash_name_tags (arg_names);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
925
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
926 feval (fcn.function_value (), args);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
927 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
928 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
929
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
930 // Loading a class properly requires an exemplar map entry for success.
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
931 // If we don't have one, we attempt to create one by calling the constructor
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
932 // with no arguments.
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
933 bool
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
934 octave_class::reconstruct_exemplar (void)
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
935 {
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
936 bool retval = false;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
937
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
938 octave_class::exemplar_const_iterator it
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
939 = octave_class::exemplar_map.find (c_name);
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
940
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
941 if (it != octave_class::exemplar_map.end ())
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
942 retval = true;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
943 else
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
944 {
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
945 octave_value ctor = symbol_table::find_method (c_name, c_name);
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
946
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
947 if (ctor.is_defined ())
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
948 {
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
949 octave_value_list result = feval (ctor, 1);
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
950
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
951 if (result.length () == 1)
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
952 retval = true;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
953 else
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
954 warning ("call to constructor for class %s failed", c_name.c_str ());
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
955 }
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
956 else
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
957 warning ("no constructor for class %s", c_name.c_str ());
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
958 }
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
959
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
960 return retval;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
961 }
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
962
9240
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
963 void
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
964 octave_class::clear_exemplar_map (void)
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
965 {
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
966 exemplar_map.clear ();
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
967 }
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
968
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
969 // 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
970 // class inheritance structure. reconstruct_parents () attempts to
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
971 // 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
972 //
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
973 // 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
974 // 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
975 // to do its magic.
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
976 bool
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
977 octave_class::reconstruct_parents (void)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
978 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
979 bool retval = true, might_have_inheritance = false;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
980 std::string dbgstr = "dork";
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
981
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
982 // First, check to see if there might be an issue with inheritance.
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
983 for (Octave_map::const_iterator p = map.begin (); p != map.end (); p++)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
984 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
985 std::string key = map.key (p);
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
986 Cell val = map.contents (p);
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
987 if ( val(0).is_object() )
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
988 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
989 dbgstr = "blork";
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
990 if( key == val(0).class_name() )
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
991 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
992 might_have_inheritance = true;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
993 dbgstr = "cork";
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
994 break;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
995 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
996 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
997 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
998
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
999 if (might_have_inheritance)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1000 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1001 octave_class::exemplar_const_iterator it
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1002 = octave_class::exemplar_map.find (c_name);
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1003
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1004 if (it == octave_class::exemplar_map.end ())
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1005 retval = false;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1006 else
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1007 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1008 octave_class::exemplar_info exmplr = it->second;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1009 parent_list = exmplr.parents ();
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1010 for (std::list<std::string>::iterator pit = parent_list.begin ();
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1011 pit != parent_list.end ();
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1012 pit++)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1013 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1014 dbgstr = *pit;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1015 bool dbgbool = map.contains (*pit);
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1016 if (!dbgbool)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1017 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1018 retval = false;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1019 break;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1020 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1021 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1022 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1023 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1024
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1025 return retval;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1026 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1027
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1028 bool
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1029 octave_class::save_ascii (std::ostream& os)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1030 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1031 os << "# classname: " << class_name () << "\n";
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1032 Octave_map m;
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1033 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
1034 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1035 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
1036 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
1037 if (! error_state)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1038 m = tmp(0).map_value ();
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1039 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1040 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1041 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1042 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1043 m = map_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1044
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1045 os << "# length: " << m.nfields () << "\n";
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1046
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1047 Octave_map::iterator i = m.begin ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1048 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1049 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1050 octave_value val = map.contents (i);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1051
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1052 bool b = save_ascii_data (os, val, m.key (i), false, 0);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1053
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1054 if (! b)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1055 return os;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1056
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1057 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1058 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1059
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1060 return true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1061 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1062
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1063 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1064 octave_class::load_ascii (std::istream& is)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1065 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1066 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
1067 std::string classname;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1068 bool success = true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1069
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1070 if (extract_keyword (is, "classname", classname) && classname != "")
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1071 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1072 if (extract_keyword (is, "length", len) && len >= 0)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1073 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1074 if (len > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1075 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1076 Octave_map m (map);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1077
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1078 for (octave_idx_type j = 0; j < len; j++)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1079 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1080 octave_value t2;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1081 bool dummy;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1082
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1083 // recurse to read cell elements
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1084 std::string nm
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1085 = read_ascii_data (is, std::string (), dummy, t2, j);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1086
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1087 if (! is)
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1088 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1089
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1090 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
1091
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1092 if (error_state)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1093 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1094 error ("load: internal error loading class elements");
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1095 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1096 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1097
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1098 m.assign (nm, tcell);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1099 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1100
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1101 if (is)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1102 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1103 c_name = classname;
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1104 reconstruct_exemplar ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1105
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1106 map = m;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1107
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1108 if (! reconstruct_parents ())
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1109 warning ("load: unable to reconstruct object inheritance");
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1110 else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1111 {
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1112 if (load_path::find_method (classname, "loadobj")
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1113 != std::string ())
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1114 {
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1115 octave_value in = new octave_class (*this);
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1116 octave_value_list tmp = feval ("loadobj", in, 1);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1117
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1118 if (! error_state)
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1119 map = tmp(0).map_value ();
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1120 else
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1121 success = false;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1122 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1123 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1124 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1125 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1126 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1127 error ("load: failed to load class");
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1128 success = false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1129 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1130 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1131 else if (len == 0 )
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1132 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1133 map = Octave_map (dim_vector (1, 1));
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1134 c_name = classname;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1135 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1136 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1137 panic_impossible ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1138 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1139 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1140 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1141 error ("load: failed to extract number of elements in class");
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1142 success = false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1143 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1144 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1145 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1146 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1147 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
1148 success = false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1149 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1150
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1151 return success;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1152 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1153
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1154 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1155 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
1156 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1157 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
1158
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1159 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
1160 os << class_name ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1161
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1162 Octave_map m;
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1163 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
1164 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1165 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
1166 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
1167 if (! error_state)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1168 m = tmp(0).map_value ();
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1169 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1170 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1171 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1172 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1173 m = map_value ();
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 int32_t len = m.nfields();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1176 os.write (reinterpret_cast<char *> (&len), 4);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1177
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1178 Octave_map::iterator i = m.begin ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1179 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1180 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1181 octave_value val = map.contents (i);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1182
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1183 bool b = save_binary_data (os, val, m.key (i), "", 0, save_as_floats);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1184
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1185 if (! b)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1186 return os;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1187
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1188 i++;
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
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1191 return true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1192 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1193
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1194 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1195 octave_class::load_binary (std::istream& is, bool swap,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1196 oct_mach_info::float_format fmt)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1197 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1198 bool success = true;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1199
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1200 int32_t classname_len;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1201
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1202 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
1203 if (! is)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1204 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1205 else if (swap)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1206 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
1207
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1208 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1209 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
1210 classname[classname_len] = '\0';
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1211 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
1212 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1213 c_name = classname;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1214 }
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1215 reconstruct_exemplar ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1216
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1217 int32_t len;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1218 if (! is.read (reinterpret_cast<char *> (&len), 4))
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1219 return false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1220 if (swap)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1221 swap_bytes<4> (&len);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1222
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1223 if (len > 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1224 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1225 Octave_map m (map);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1226
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1227 for (octave_idx_type j = 0; j < len; j++)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1228 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1229 octave_value t2;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1230 bool dummy;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1231 std::string doc;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1232
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1233 // recurse to read cell elements
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1234 std::string nm = read_binary_data (is, swap, fmt, std::string (),
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1235 dummy, t2, doc);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1236
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1237 if (! is)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1238 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1239
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1240 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1241
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1242 if (error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1243 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1244 error ("load: internal error loading class elements");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1245 return false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1246 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1247
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1248 m.assign (nm, tcell);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1249 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1250
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1251 if (is)
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1252 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1253 map = m;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1254
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1255 if (! reconstruct_parents ())
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1256 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
1257 else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1258 {
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1259 if (load_path::find_method (c_name, "loadobj") != std::string ())
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1260 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1261 octave_value in = new octave_class (*this);
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1262 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
1263
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1264 if (! error_state)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1265 map = tmp(0).map_value ();
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1266 else
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1267 success = false;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1268 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1269 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1270 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1271 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1272 {
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1273 warning ("load: failed to load class");
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1274 success = false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1275 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1276 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1277 else if (len == 0 )
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1278 map = Octave_map (dim_vector (1, 1));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1279 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1280 panic_impossible ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1281
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1282 return success;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1283 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1284
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1285 #if defined (HAVE_HDF5)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1286
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1287 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1288 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
1289 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1290 hsize_t hdims[3];
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1291 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
1292 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
1293 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
1294 hid_t class_hid = -1;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1295 hid_t data_hid = -1;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1296 Octave_map m;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1297 Octave_map::iterator i;
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 group_hid = H5Gcreate (loc_id, name, 0);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1300 if (group_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1301 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1302
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1303 // 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
1304 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
1305 if (type_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1306 goto error_cleanup;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1307
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1308 hdims[0] = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1309 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
1310 if (space_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1311 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1312
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1313 class_hid = H5Dcreate (group_hid, "classname", type_hid, space_hid,
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1314 H5P_DEFAULT);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1315 if (class_hid < 0 || H5Dwrite (class_hid, type_hid, H5S_ALL, H5S_ALL,
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1316 H5P_DEFAULT, c_name.c_str ()) < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1317 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1318
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1319 data_hid = H5Gcreate (group_hid, "value", 0);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1320 if (data_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1321 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1322
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1323 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
1324 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1325 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
1326 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
1327 if (! error_state)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1328 m = tmp(0).map_value ();
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1329 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1330 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1331 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1332 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1333 m = map_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1334
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1335 // 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
1336 i = m.begin ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1337 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1338 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1339 octave_value val = map.contents (i);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1340
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1341 bool retval2 = add_hdf5_data (data_hid, val, m.key (i), "", false,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1342 save_as_floats);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1343
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1344 if (! retval2)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1345 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1346
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1347 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1348 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1349
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1350 error_cleanup:
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1351
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1352 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1353 H5Gclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1354
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1355 if (class_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1356 H5Dclose (class_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1357
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1358 if (space_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1359 H5Sclose (space_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1360
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1361 if (type_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1362 H5Tclose (type_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1363
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1364 if (group_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1365 H5Gclose (group_hid);
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 return true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1368 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1369
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1370 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1371 octave_class::load_hdf5 (hid_t loc_id, const char *name,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1372 bool have_h5giterate_bug)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1373 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1374 bool retval = false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1375
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1376 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
1377 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
1378 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
1379 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
1380 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
1381 hid_t subgroup_hid = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1382 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
1383
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1384 hdf5_callback_data dsub;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1385
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1386 herr_t retval2 = 0;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1387 Octave_map m (dim_vector (1, 1));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1388 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
1389 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
1390 int slen = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1391 hsize_t rank = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1392
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1393 group_hid = H5Gopen (loc_id, name);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1394 if (group_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1395 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1396
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1397
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1398 data_hid = H5Dopen (group_hid, "classname");
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1399
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1400 if (data_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1401 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1402
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1403 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
1404
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1405 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
1406
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1407 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
1408 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1409
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1410 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
1411 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
1412
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1413 if (rank != 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1414 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1415
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1416 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
1417 if (slen < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1418 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1419
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1420 // 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
1421 do
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1422 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1423 OCTAVE_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
1424
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1425 // 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
1426 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
1427 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
1428
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1429 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT,
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1430 classname) < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1431 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1432 H5Tclose (st_id);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1433 H5Dclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1434 H5Gclose (group_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1435 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1436 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1437
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1438 H5Tclose (st_id);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1439 H5Dclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1440 data_hid = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1441
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1442 c_name = classname;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1443 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1444 while (0);
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1445 reconstruct_exemplar ();
8212
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
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1448 #ifdef HAVE_H5GGET_NUM_OBJS
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1449 subgroup_hid = H5Gopen (group_hid, name);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1450 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
1451 H5Gclose (subgroup_hid);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1452
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1453 while (current_item < static_cast<int> (num_obj)
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1454 && (retval2 = H5Giterate (group_hid, name, &current_item,
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1455 hdf5_read_next_data, &dsub)) > 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1456 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1457 while ((retval2 = H5Giterate (group_hid, name, &current_item,
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1458 hdf5_read_next_data, &dsub)) > 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1459 #endif
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1460 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1461 octave_value t2 = dsub.tc;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1462
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1463 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1464
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1465 if (error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1466 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1467 error ("load: internal error loading class elements");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1468 return false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1469 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1470
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1471 m.assign (dsub.name, tcell);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1472
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1473 if (have_h5giterate_bug)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1474 current_item++; // H5Giterate returned the last index processed
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1475 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1476
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1477 if (retval2 >= 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1478 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1479 map = m;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1480
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1481 if (!reconstruct_parents ())
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1482 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
1483 else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1484 {
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1485 if (load_path::find_method (c_name, "loadobj") != std::string ())
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1486 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1487 octave_value in = new octave_class (*this);
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1488 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
1489
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1490 if (! error_state)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1491 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1492 map = tmp(0).map_value ();
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1493 retval = true;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1494 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1495 else
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1496 retval = false;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1497 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1498 else
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1499 retval = true;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1500 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1501 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1502
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1503 error_cleanup:
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 H5Dclose (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 (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1508 H5Gclose (group_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1509
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1510 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1511 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1512
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1513 #endif
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1514
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1515 mxArray *
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1516 octave_class::as_mxArray (void) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1517 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1518 gripe_wrong_type_arg ("octave_class::as_mxArray ()", type_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1519
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1520 return 0;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1521 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1522
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1523 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1524 octave_class::in_class_method (void) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1525 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1526 octave_function *fcn = octave_call_stack::current ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1527
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1528 return (fcn
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
1529 && (fcn->is_class_method ()
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
1530 || fcn->is_class_constructor ()
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
1531 || fcn->is_private_function_of_class (class_name ()))
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1532 && fcn->dispatch_class () == class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1533 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1534
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1535 octave_class::exemplar_info::exemplar_info (const octave_value& obj)
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1536 : field_names (), parent_class_names ()
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1537 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1538 if (obj.is_object ())
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1539 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1540 Octave_map m = obj.map_value ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1541 field_names = m.keys ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1542
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1543 parent_class_names = obj.parent_class_name_list ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1544 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1545 else
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1546 error ("invalid call to exmplar_info constructor");
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1547 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1548
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1549
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1550 // A map from class names to lists of fields.
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1551 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
1552
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1553 bool
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1554 octave_class::exemplar_info::compare (const octave_value& obj) const
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1555 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1556 bool retval = true;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1557
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1558 if (obj.is_object ())
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1559 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1560 if (nfields () == obj.nfields ())
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1561 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1562 Octave_map obj_map = obj.map_value ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1563 string_vector obj_fnames = obj_map.keys ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1564 string_vector fnames = fields ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1565
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1566 for (octave_idx_type i = 0; i < nfields (); i++)
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1567 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1568 if (obj_fnames[i] != fnames[i])
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1569 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1570 retval = false;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1571 error ("mismatch in field names");
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1572 break;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1573 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1574 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1575
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1576 if (nparents () == obj.nparents ())
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1577 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1578 std::list<std::string> obj_parents
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1579 = obj.parent_class_name_list ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1580 std::list<std::string> pnames = parents ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1581
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1582 std::list<std::string>::const_iterator p = obj_parents.begin ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1583 std::list<std::string>::const_iterator q = pnames.begin ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1584
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1585 while (p != obj_parents.end ())
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1586 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1587 if (*p++ != *q++)
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1588 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1589 retval = false;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1590 error ("mismatch in parent classes");
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1591 break;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1592 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1593 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1594 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1595 else
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1596 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1597 retval = false;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1598 error ("mismatch in number of parent classes");
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1599 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1600 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1601 else
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1602 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1603 retval = false;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1604 error ("mismatch in number of fields");
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1605 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1606 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1607 else
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1608 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1609 retval = false;
9206
5f36c6c9be13 Handle loading of objects with inheritance from MAT files.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9190
diff changeset
1610 error ("invalid comparison of class exemplar to non-class object");
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1611 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1612
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1613 return retval;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1614 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1615
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1616 DEFUN (class, args, ,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1617 "-*- texinfo -*-\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1618 @deftypefn {Built-in Function} {} class (@var{expr})\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1619 @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
1620 @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
1621 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
1622 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
1623 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
1624 derived.\n\
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1625 @end deftypefn")
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 octave_value retval;
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 int nargin = args.length ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1630
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1631 if (nargin == 0)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1632 print_usage ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1633 else if (nargin == 1)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1634 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
1635 else
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1636 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1637 Octave_map m = args(0).map_value ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1638
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1639 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1640 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1641 std::string id = args(1).string_value ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1642
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1643 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1644 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1645 octave_function *fcn = octave_call_stack::caller ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1646
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1647 if (fcn && fcn->is_class_constructor ())
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1648 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1649 if (nargin == 2)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1650 retval = octave_value (new octave_class (m, id));
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1651 else
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1652 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1653 octave_value_list parents = args.slice (2, nargin-2);
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1654
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1655 retval = octave_value (new octave_class (m, id, parents));
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1656 }
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1657
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1658 if (! error_state)
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1659 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1660 octave_class::exemplar_const_iterator it
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1661 = octave_class::exemplar_map.find (id);
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1662
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1663 if (it == octave_class::exemplar_map.end ())
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1664 octave_class::exemplar_map[id]
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1665 = octave_class::exemplar_info (retval);
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1666 else if (! it->second.compare (retval))
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1667 error ("class: object of class `%s' does not match previously constructed objects", id.c_str ());
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1668 }
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1669 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1670 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1671 error ("class: invalid call from outside class constructor");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1672 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1673 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1674 error ("class: expecting character string as second argument");
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 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1677 error ("class: expecting structure as first argument");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1678 }
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1679
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1680 return retval;
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1681 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1682
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1683 DEFUN (__isa_parent__, args, ,
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1684 "-*- texinfo -*-\n\
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1685 @deftypefn {Built-in Function} {} __isa_parent__ (@var{class}, @var{name})\n\
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1686 Undocumented internal function.\n\
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1687 @end deftypefn")
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1688 {
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1689 octave_value retval = false;
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1690
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1691 if (args.length () == 2)
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1692 {
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1693 octave_value cls = args(0);
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1694 octave_value nm = args(1);
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1695
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1696 if (! error_state)
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1697 {
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1698 if (cls.find_parent_class (nm.string_value ()))
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1699 retval = true;
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1700 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1701 else
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1702 error ("__isa_parent__: expecting arguments to be character strings");
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1703 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1704 else
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1705 print_usage ();
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1706
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1707 return retval;
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1708 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1709
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1710 DEFUN (__parent_classes__, args, ,
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1711 "-*- texinfo -*-\n\
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1712 @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
1713 Undocumented internal function.\n\
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1714 @end deftypefn")
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1715 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1716 octave_value retval = Cell ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1717
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1718 if (args.length () == 1)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1719 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1720 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
1721
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1722 if (arg.is_object ())
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1723 retval = Cell (arg.parent_class_names ());
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1724 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1725 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1726 print_usage ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1727
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1728 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1729 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1730
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1731 DEFUN (isobject, args, ,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1732 "-*- texinfo -*-\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1733 @deftypefn {Built-in Function} {} isobject (@var{x})\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1734 Return true if @var{x} is a class object.\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1735 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1736 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1737 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1738
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1739 if (args.length () == 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1740 retval = args(0).is_object ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1741 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1742 print_usage ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1743
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1744 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1745 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1746
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1747 DEFUN (ismethod, args, ,
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1748 "-*- texinfo -*-\n\
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1749 @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
1750 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
1751 is a method of this class.\n\
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1752 @end deftypefn")
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1753 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1754 octave_value retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1755
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1756 if (args.length () == 2)
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1757 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1758 octave_value arg = args(0);
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1759
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1760 std::string class_name;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1761
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1762 if (arg.is_object ())
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1763 class_name = arg.class_name ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1764 else if (arg.is_string ())
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1765 class_name = arg.string_value ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1766 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1767 error ("ismethod: expecting object or class name as first argument");
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1768
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1769 if (! error_state)
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1770 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1771 std::string method = args(1).string_value ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1772
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1773 if (! error_state)
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1774 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1775 if (load_path::find_method (class_name, method) != std::string ())
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1776 retval = true;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1777 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1778 retval = false;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1779 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1780 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1781 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1782 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1783 print_usage ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1784
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1785 return retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1786 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1787
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
1788 DEFUN (methods, args, nargout,
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1789 "-*- texinfo -*-\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1790 @deftypefn {Built-in Function} {} methods (@var{x})\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1791 @deftypefnx {Built-in Function} {} methods (\"classname\")\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1792 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
1793 object @var{x} or the named class.\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1794 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1795 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1796 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1797
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1798 if (args.length () == 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1799 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1800 octave_value arg = args(0);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1801
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1802 std::string class_name;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1803
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1804 if (arg.is_object ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1805 class_name = arg.class_name ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1806 else if (arg.is_string ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1807 class_name = arg.string_value ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1808 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1809 error ("methods: expecting object or class name as argument");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1810
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1811 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1812 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1813 string_vector sv = load_path::methods (class_name);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1814
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1815 if (nargout == 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1816 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1817 octave_stdout << "Methods for class " << class_name << ":\n\n";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1818
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1819 sv.list_in_columns (octave_stdout);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1820
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1821 octave_stdout << std::endl;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1822 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1823 else
9206
5f36c6c9be13 Handle loading of objects with inheritance from MAT files.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9190
diff changeset
1824 retval = Cell (sv);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1825 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1826 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1827 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1828 print_usage ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1829
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1830 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1831 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1832
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1833 static bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1834 is_built_in_class (const std::string& cn)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1835 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1836 static std::set<std::string> built_in_class_names;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1837
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1838 if (built_in_class_names.empty ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1839 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1840 built_in_class_names.insert ("double");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1841 built_in_class_names.insert ("single");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1842 built_in_class_names.insert ("cell");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1843 built_in_class_names.insert ("struct");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1844 built_in_class_names.insert ("logical");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1845 built_in_class_names.insert ("char");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1846 built_in_class_names.insert ("function handle");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1847 built_in_class_names.insert ("int8");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1848 built_in_class_names.insert ("uint8");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1849 built_in_class_names.insert ("int16");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1850 built_in_class_names.insert ("uint16");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1851 built_in_class_names.insert ("int32");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1852 built_in_class_names.insert ("uint32");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1853 built_in_class_names.insert ("int64");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1854 built_in_class_names.insert ("uint64");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1855 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1856
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1857 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
1858 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1859
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1860 DEFUN (superiorto, args, ,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1861 "-*- texinfo -*-\n\
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1862 @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
1863 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
1864 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
1865 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
1866 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
1867 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1868 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1869 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1870
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1871 octave_function *fcn = octave_call_stack::caller ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1872
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1873 if (fcn && fcn->is_class_constructor ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1874 {
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1875 for (int i = 0; i < args.length(); i++)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1876 {
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1877 std::string class_name = args(i).string_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1878
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1879 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1880 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1881 if (! is_built_in_class (class_name))
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1882 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1883 std::string this_class_name = fcn->name ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1884
7972
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1885 if (! symbol_table::set_class_relationship (this_class_name,
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1886 class_name))
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1887 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1888 error ("superiorto: precedence already set for %s and %s",
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1889 this_class_name.c_str (), class_name.c_str ());
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1890 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1891 }
7338
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 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1894 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1895 // User defined classes always have higher precedence
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1896 // than built-in classes.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1897 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1898 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1899 else
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1900 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1901 error ("superiorto: expecting argument to be class name");
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1902 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1903 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1904 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1905 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1906 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1907 error ("superiorto: invalid call from outside class constructor");
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 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1910 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1911
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1912 DEFUN (inferiorto, args, ,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1913 "-*- texinfo -*-\n\
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1914 @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
1915 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
1916 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
1917 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
1918 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
1919 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1920 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1921 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1922
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1923 octave_function *fcn = octave_call_stack::caller ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1924
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1925 if (fcn && fcn->is_class_constructor ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1926 {
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1927 for (int i = 0; i < args.length(); i++)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1928 {
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1929 std::string class_name = args(i).string_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1930
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1931 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1932 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1933 if (! is_built_in_class (class_name))
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1934 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1935 std::string this_class_name = fcn->name ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1936
7972
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1937 symbol_table::set_class_relationship (class_name,
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1938 this_class_name);
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1939
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1940 if (! symbol_table::set_class_relationship (this_class_name,
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1941 class_name))
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1942 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1943 error ("inferiorto: precedence already set for %s and %s",
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1944 this_class_name.c_str (), class_name.c_str ());
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1945 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1946 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1947 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1948 else
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1949 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1950 error ("inferiorto: cannot give user-defined class lower precedence than built-in class");
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1951 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1952 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1953 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1954 else
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1955 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1956 error ("inferiorto: expecting argument to be class name");
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1957 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1958 }
7338
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 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1961 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1962 error ("inferiorto: invalid call from outside class constructor");
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 return retval;
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
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 ;;; Local Variables: ***
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1969 ;;; mode: C++ ***
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1970 ;;; End: ***
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1971 */