annotate src/ov-class.cc @ 9522:e79470be3ecb

implement subsasgn this-arg optimization
author Jaroslav Hajek <highegg@gmail.com>
date Thu, 13 Aug 2009 15:51:57 +0200
parents e08d72bb988e
children 8e5009334661
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
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
4 Copyright (C) 2009 VZLU Prague
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
5
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
7
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7444
1e1e2608da7b [project @ 2008-02-04 07:40:55 by jwe]
jwe
parents: 7338
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
1e1e2608da7b [project @ 2008-02-04 07:40:55 by jwe]
jwe
parents: 7338
diff changeset
11 option) any later version.
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
12
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
16 for more details.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
17
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7444
1e1e2608da7b [project @ 2008-02-04 07:40:55 by jwe]
jwe
parents: 7338
diff changeset
19 along with Octave; see the file COPYING. If not, see
1e1e2608da7b [project @ 2008-02-04 07:40:55 by jwe]
jwe
parents: 7338
diff changeset
20 <http://www.gnu.org/licenses/>.
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
21
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
22 */
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
23
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
26 #endif
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
27
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
28 #include <iostream>
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
29
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
30 #include "Array-util.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
31 #include "byte-swap.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8219
diff changeset
32 #include "oct-locbuf.h"
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
33 #include "lo-mappers.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
34
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
35 #include "Cell.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
36 #include "defun.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
37 #include "error.h"
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
38 #include "file-ops.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
39 #include "gripes.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
40 #include "load-path.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
41 #include "ls-hdf5.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
42 #include "ls-oct-ascii.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
43 #include "ls-oct-binary.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
44 #include "ls-utils.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
45 #include "oct-lvalue.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
46 #include "ov-class.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
47 #include "ov-fcn.h"
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
48 #include "ov-usr-fcn.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
49 #include "pager.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
50 #include "parse.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
51 #include "pr-output.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
52 #include "toplev.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
53 #include "unwind-prot.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
54 #include "variables.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
55
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
56 DEFINE_OCTAVE_ALLOCATOR(octave_class);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
57
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
58 int octave_class::t_id (-1);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
59
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
60 const std::string octave_class::t_name ("class");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
61
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
62 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
63 octave_class::register_type (void)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
64 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
65 t_id = octave_value_typeinfo::register_type
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
66 (octave_class::t_name, "<unknown>", octave_value (new octave_class ()));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
67 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
68
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
69 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
70 const octave_value_list& parents)
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
71 : octave_struct (m), c_name (id), obsolete_copies (0)
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
72 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
73 octave_idx_type n = parents.length ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
74
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
75 for (octave_idx_type idx = 0; idx < n; idx++)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
76 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
77 octave_value parent = parents(idx);
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
78
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
79 if (! parent.is_object ())
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
80 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
81 else
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
82 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
83 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
84
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
85 if (find_parent_class (cnm))
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
86 error ("duplicate class in parent tree");
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
87 else
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
88 {
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
89 parent_list.push_back (cnm);
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
90
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
91 map.assign (cnm, parent);
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
92 }
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
93 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
94 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
95
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
96 if (! error_state)
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
97 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
98 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
99
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
100 octave_base_value *
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
101 octave_class::unique_clone (void)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
102 {
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
103 if (count == obsolete_copies)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
104 {
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
105 // All remaining copies are obsolete. We don't actually need to clone.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
106 count++;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
107 return this;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
108 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
109 else
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
110 {
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
111 // In theory, this shouldn't be happening, but it's here just in case.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
112 if (count < obsolete_copies)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
113 obsolete_copies = 0;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
114
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
115 return clone ();
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
116 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
117 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
118
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
119 static std::string
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
120 get_current_method_class (void)
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
121 {
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
122 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
123
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
124 octave_function *fcn = octave_call_stack::current ();
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
125
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
126 std::string my_dir = fcn->dir_name ();
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
127
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
128 std::string method_class = file_ops::tail (my_dir);
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
129
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
130 retval = method_class.substr (1);
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
131
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
132 return retval;
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
133 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
134
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
135 static void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
136 gripe_invalid_index (void)
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 error ("invalid index for class");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
139 }
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 static inline octave_value_list
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
142 sanitize (const octave_value_list& ovl)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
143 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
144 octave_value_list retval = ovl;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
145
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
146 for (octave_idx_type i = 0; i < ovl.length (); 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 if (retval(i).is_magic_colon ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
149 retval(i) = ":";
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 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
153 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
154
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
155 static inline octave_value
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
156 make_idx_args (const std::string& type,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
157 const std::list<octave_value_list>& idx,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
158 const std::string& who)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
159 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
160 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
161
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
162 size_t len = type.length ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
163
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
164 if (len == idx.size ())
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 Cell type_field (len, 1);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
167 Cell subs_field (len, 1);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
168
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
169 std::list<octave_value_list>::const_iterator p = idx.begin ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
170
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
171 for (size_t i = 0; i < len; i++)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
172 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
173 char t = type[i];
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
174
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
175 switch (t)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
176 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
177 case '(':
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
178 type_field(i) = "()";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
179 subs_field(i) = Cell (sanitize (*p++));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
180 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
181
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
182 case '{':
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
183 type_field(i) = "{}";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
184 subs_field(i) = Cell (sanitize (*p++));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
185 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
186
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
187 case '.':
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
188 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
189 type_field(i) = ".";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
190
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
191 octave_value_list vlist = *p++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
192
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
193 if (vlist.length () == 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
194 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
195 octave_value val = vlist(0);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
196
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
197 if (val.is_string ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
198 subs_field(i) = val;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
199 else
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 error ("expecting character string argument for `.' index");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
202 return retval;
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 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
205 else
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 error ("expecting single argument for `.' index");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
208 return retval;
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 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
211 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
212
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
213 default:
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
214 panic_impossible ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
215 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
216 }
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
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
219 Octave_map m;
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 m.assign ("type", type_field);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
222 m.assign ("subs", subs_field);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
223
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
224 retval = m;
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 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
227 error ("invalid index for %s", who.c_str ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
228
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
229 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
230 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
231
9148
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
232 Cell
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
233 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
234 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
235 Cell retval;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
236
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
237 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
238
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
239 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
240
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
241 // 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
242 // 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
243
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
244 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
245 = 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
246
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
247 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
248
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
249 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
250
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
251 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
252
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
253 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
254 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
255 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
256
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
257 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
258 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
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 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
261 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
262 else
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
263 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
264
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
265 return retval;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
266 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
267
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
268 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
269 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
270 {
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 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
272
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 // 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
274 // 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
275 // 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
276 // 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
277 // 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
278
b2b8ed43b922 ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents: 9151
diff changeset
279 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
280 }
b2b8ed43b922 ov-class.cc: don't dispatch subsref or subsasgn when called from builtin
John W. Eaton <jwe@octave.org>
parents: 9151
diff changeset
281
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
282 Matrix
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
283 octave_class::size (void)
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 Matrix retval (1, 2, 1.0);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
286 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
287
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
288 if (meth.is_defined ())
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 count++;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
291 octave_value_list args (1, octave_value (this));
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
292
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
293 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
294 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
295 retval = lv(0).matrix_value ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
296 else
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
297 error ("@%s/size: invalid return value");
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 return retval;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
301 }
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
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
304 octave_class::numel (const octave_value_list& idx)
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_idx_type retval = -1;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
307 const std::string cn = class_name ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
308
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
309 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
310
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
311 if (meth.is_defined ())
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
312 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
313 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
314
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
315 count++;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
316 args(0) = octave_value (this);
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 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
319 args(i+1) = idx(i);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
320
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
321 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
322 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
323 retval = lv(0).idx_type_value (true);
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 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
326 }
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
327 else
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
328 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
329 // If method is not found, calculate using size ().
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
330 const Matrix mdv = size ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
331 octave_idx_type nmdv = mdv.numel ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
332 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
333 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
334 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
335 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
336 dv(i) = mdv(i);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
337 else
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
338 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
339 cn.c_str (), cn.c_str ());
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
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
342 if (! error_state)
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
343 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
344 octave_idx_type len = idx.length ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
345 if (len == 0)
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
346 retval = dv.numel ();
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
347 else
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
348 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
349 dv = dv.redim (len);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
350 retval = 1;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
351 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
352 {
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
353 if (idx(i).is_magic_colon ())
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
354 retval *= dv(i);
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
355 else
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
356 retval *= idx(i).numel ();
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
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
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
363 return retval;
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
364 }
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9240
diff changeset
365
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
366 octave_value_list
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
367 octave_class::subsref (const std::string& type,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
368 const std::list<octave_value_list>& idx,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
369 int nargout)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
370 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
371 octave_value_list retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
372
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
373 if (in_class_method () || called_from_builtin ())
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
374 retval = octave_struct::subsref (type, idx, nargout);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
375 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
376 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
377 octave_value meth = symbol_table::find_method ("subsref", class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
378
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
379 if (meth.is_defined ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
380 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
381 octave_value_list args;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
382
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
383 args(1) = make_idx_args (type, idx, "subsref");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
384
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
385 if (error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
386 return octave_value_list ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
387
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
388 count++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
389 args(0) = octave_value (this);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
390
9331
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
391 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
392 || (type.length () > 1 && type[0] == '('
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
393 && type[1] == '.'));
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
394
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
395 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
396 {
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
397 // 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
398 octave_value_list tmp;
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
399 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
400 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
401 if (! error_state)
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
402 {
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
403 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
404 if (true_nargout != 1)
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
405 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
406 else
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
407 retval = tmp;
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
408 }
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
409 }
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
410 else
a76f391a3d02 set up proper nargout for call to subsref method
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
411 retval = feval (meth.function_value (), args, nargout);
7338
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 else
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 if (type.length () == 1 && type[0] == '(')
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
416 retval(0) = octave_value (map.index (idx.front ()), class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
417 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
418 gripe_invalid_index ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
419 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
420 }
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 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
423 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
424
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
425 octave_value
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
426 octave_class::subsref (const std::string& type,
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
427 const std::list<octave_value_list>& idx,
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
428 bool auto_add)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
429 {
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
430 if (in_class_method () || called_from_builtin ())
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
431 return octave_struct::subsref (type, idx, auto_add);
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
432 else
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
433 return subsref (type, idx);
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
434
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
435 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
436
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
437 void
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
438 octave_class::gripe_failed_assignment (void)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
439 {
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
440 error ("assignment to class element failed");
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
441 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
442
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
443 octave_value
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
444 octave_class::dotasgn (const octave_value_list& idx, const octave_value& rhs)
7338
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 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
447
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
448 // Find the class in which this method resides before
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
449 // attempting to access the requested field.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
450
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
451 std::string method_class = get_current_method_class ();
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
452
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
453 octave_base_value *obvp = find_parent_class (method_class);
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
454
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
455 if (obvp)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
456 {
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
457 assert (idx.length () == 1);
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
458
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
459 std::string key = idx(0).string_value ();
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
460
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
461 if (! error_state)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
462 {
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
463 obvp->assign (key, rhs);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
464
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
465 if (! error_state)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
466 {
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
467 count++;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
468 retval = octave_value (this);
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
469 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
470 else
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
471 gripe_failed_assignment ();
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
472 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
473 else
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
474 gripe_failed_assignment ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
475 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
476 else
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
477 error ("malformed class");
7338
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 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
480 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
481
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
482 octave_value
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
483 octave_class::subsasgn (const std::string& type,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
484 const std::list<octave_value_list>& idx,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
485 const octave_value& rhs)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
486 {
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
487 if (! (in_class_method () || called_from_builtin ()))
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
488 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
489 octave_value meth = symbol_table::find_method ("subsasgn", class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
490
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
491 if (meth.is_defined ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
492 {
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
493 octave_value retval;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
494
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
495 octave_value_list args;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
496
9333
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
497 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
498 {
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
499 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
500 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
501 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
502 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
503 }
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
504 else
3930f8ce6430 Unpack cs-list and setup nargin for call to subsasgn method
Jaroslav Hajek <highegg@gmail.com>
parents: 9331
diff changeset
505 args(2) = rhs;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
506
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
507 args(1) = make_idx_args (type, idx, "subsasgn");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
508
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
509 if (error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
510 return octave_value_list ();
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 count++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
513 args(0) = octave_value (this);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
514
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
515 // Now comes the magic. Count copies with me:
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
516 // 1. myself (obsolete)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
517 // 2. the copy inside args (obsolete)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
518 // 3. the copy in method's symbol table (working)
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
519 // ... possibly more (not obsolete).
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
520 //
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
521 // So we mark 2 copies as obsolete and hold our fingers crossed.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
522 // But prior to doing that, check whether the routine is amenable
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
523 // to the optimization.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
524 // It is essential that the handling function doesn't store extra
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
525 // copies anywhere. If it does, things will not break but the
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
526 // optimization won't work.
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
527
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
528 octave_value_list tmp;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
529
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
530 if (obsolete_copies == 0 && meth.is_user_function ()
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
531 && meth.user_function_value ()->subsasgn_optimization_ok ())
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
532 {
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
533 unwind_protect::protect_var (obsolete_copies);
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
534 obsolete_copies = 2;
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
535
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
536 tmp = feval (meth.function_value (), args);
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
537
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
538 unwind_protect::run ();
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
539 }
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
540 else
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
541 tmp = feval (meth.function_value (), args);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
542
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
543 // FIXME -- should the subsasgn method be able to return
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
544 // more than one value?
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
545
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
546 if (tmp.length () > 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
547 error ("expecting single return value from @%s/subsasgn",
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
548 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
549
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
550 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
551 retval = tmp(0);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
552
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
553 return retval;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
554 }
8785
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
9522
e79470be3ecb implement subsasgn this-arg optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 9521
diff changeset
557 return octave_struct::subsasgn (type, idx, rhs);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
558 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
559
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
560 idx_vector
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
561 octave_class::index_vector (void) const
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
562 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
563 idx_vector retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
564
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
565 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
566
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
567 if (meth.is_defined ())
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
568 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
569 octave_value_list args;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
570 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
571
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
572 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
573
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
574 if (!error_state && tmp.length () >= 1)
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
575 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
576 if (tmp(0).is_object())
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
577 error ("subsindex function must return a valid index vector");
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
578 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
579 // Index vector returned by subsindex is zero based
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
580 // (why this inconsistency Mathworks?), and so we must
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
581 // 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
582 // expects it to be one based.
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
583 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
584 octave_value (1.0)).index_vector ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
585 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
586 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
587 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
588 error ("no subsindex method defined for class %s",
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
589 class_name().c_str ());
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
590
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
591 return retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
592 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
593
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
594 string_vector
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
595 octave_class::map_keys (void) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
596 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
597 string_vector retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
598 gripe_wrong_type_arg ("octave_class::map_keys()", type_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
599 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
600 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
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 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
603 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
604 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
605 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
606
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
607 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
608 retval = this;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
609 else
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
610 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
611 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
612 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
613 pit++)
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
614 {
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
615 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
616
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
617 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
618
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
619 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
620
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
621 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
622
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
623 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
624
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
625 if (retval)
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
626 break;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
627 }
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
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
630 return retval;
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
631 }
69e6bbfef8c2 ov-class.cc: protect against possiblly invalid octave_value -> string conversions
John W. Eaton <jwe@octave.org>
parents: 9147
diff changeset
632
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
633 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
634 octave_class::print (std::ostream& os, bool) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
635 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
636 print_raw (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
637 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
638
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
639 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
640 octave_class::print_raw (std::ostream& os, bool) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
641 {
9377
610bf90fce2a update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents: 9333
diff changeset
642 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
643
9377
610bf90fce2a update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents: 9333
diff changeset
644 unwind_protect::protect_var (Vstruct_levels_to_print);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
645
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
646 indent (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
647 os << " <class " << class_name () << ">";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
648 newline (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
649
9377
610bf90fce2a update unwind_protect usage everywhere
Jaroslav Hajek <highegg@gmail.com>
parents: 9333
diff changeset
650 unwind_protect::run_frame (uwp_frame);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
651 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
652
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
653 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
654 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
655 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
656 bool retval = false;
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 indent (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
659 os << name << " =";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
660 newline (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
661 newline (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
662
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
663 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
664 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
665
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
666 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
667 octave_class::print_with_name (std::ostream&, const std::string& name,
9521
e08d72bb988e simplify cloning
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
668 bool)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
669 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
670 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
671
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
672 if (fcn.is_defined ())
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
673 {
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
674 octave_value_list args;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
675
9521
e08d72bb988e simplify cloning
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
676 count++;
e08d72bb988e simplify cloning
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
677 args(0) = octave_value (this);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
678
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
679 string_vector arg_names (1);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
680
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
681 arg_names[0] = name;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
682
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
683 args.stash_name_tags (arg_names);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
684
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
685 feval (fcn.function_value (), args);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
686 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
687 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
688
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
689 // Loading a class properly requires an exemplar map entry for success.
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
690 // 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
691 // with no arguments.
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
692 bool
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
693 octave_class::reconstruct_exemplar (void)
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
694 {
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
695 bool retval = false;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
696
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
697 octave_class::exemplar_const_iterator it
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
698 = octave_class::exemplar_map.find (c_name);
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
699
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
700 if (it != octave_class::exemplar_map.end ())
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
701 retval = true;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
702 else
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
703 {
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
704 octave_value ctor = symbol_table::find_method (c_name, c_name);
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
705
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
706 if (ctor.is_defined ())
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
707 {
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
708 octave_value_list result = feval (ctor, 1);
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
709
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
710 if (result.length () == 1)
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
711 retval = true;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
712 else
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
713 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
714 }
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
715 else
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
716 warning ("no constructor for class %s", c_name.c_str ());
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
717 }
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
718
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
719 return retval;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
720 }
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
721
9240
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
722 void
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
723 octave_class::clear_exemplar_map (void)
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
724 {
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
725 exemplar_map.clear ();
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
726 }
f27a8c07f0b2 clear -classes and support.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9206
diff changeset
727
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
728 // 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
729 // class inheritance structure. reconstruct_parents () attempts to
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
730 // 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
731 //
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
732 // 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
733 // 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
734 // to do its magic.
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
735 bool
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
736 octave_class::reconstruct_parents (void)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
737 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
738 bool retval = true, might_have_inheritance = false;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
739 std::string dbgstr = "dork";
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
740
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
741 // 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
742 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
743 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
744 std::string key = map.key (p);
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
745 Cell val = map.contents (p);
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
746 if ( val(0).is_object() )
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
747 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
748 dbgstr = "blork";
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
749 if( key == val(0).class_name() )
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
750 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
751 might_have_inheritance = true;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
752 dbgstr = "cork";
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
753 break;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
754 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
755 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
756 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
757
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
758 if (might_have_inheritance)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
759 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
760 octave_class::exemplar_const_iterator it
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
761 = octave_class::exemplar_map.find (c_name);
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
762
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
763 if (it == octave_class::exemplar_map.end ())
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
764 retval = false;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
765 else
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
766 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
767 octave_class::exemplar_info exmplr = it->second;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
768 parent_list = exmplr.parents ();
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
769 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
770 pit != parent_list.end ();
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
771 pit++)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
772 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
773 dbgstr = *pit;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
774 bool dbgbool = map.contains (*pit);
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
775 if (!dbgbool)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
776 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
777 retval = false;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
778 break;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
779 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
780 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
781 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
782 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
783
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
784 return retval;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
785 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
786
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
787 bool
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
788 octave_class::save_ascii (std::ostream& os)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
789 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
790 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
791 Octave_map m;
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
792 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
793 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
794 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
795 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
796 if (! error_state)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
797 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
798 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
799 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
800 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
801 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
802 m = map_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
803
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
804 os << "# length: " << m.nfields () << "\n";
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
805
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
806 Octave_map::iterator i = m.begin ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
807 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
808 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
809 octave_value val = map.contents (i);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
810
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
811 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
812
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
813 if (! b)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
814 return os;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
815
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
816 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
817 }
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 return true;
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
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
822 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
823 octave_class::load_ascii (std::istream& is)
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 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
826 std::string classname;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
827 bool success = true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
828
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
829 if (extract_keyword (is, "classname", classname) && classname != "")
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
830 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
831 if (extract_keyword (is, "length", len) && len >= 0)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
832 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
833 if (len > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
834 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
835 Octave_map m (map);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
836
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
837 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
838 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
839 octave_value t2;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
840 bool dummy;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
841
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
842 // 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
843 std::string nm
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
844 = read_ascii_data (is, std::string (), dummy, t2, j);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
845
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
846 if (! is)
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
847 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
848
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
849 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
850
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
851 if (error_state)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
852 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
853 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
854 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
855 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
856
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
857 m.assign (nm, tcell);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
858 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
859
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
860 if (is)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
861 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
862 c_name = classname;
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
863 reconstruct_exemplar ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
864
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
865 map = m;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
866
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
867 if (! reconstruct_parents ())
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
868 warning ("load: unable to reconstruct object inheritance");
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
869 else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
870 {
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
871 if (load_path::find_method (classname, "loadobj")
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
872 != std::string ())
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
873 {
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
874 octave_value in = new octave_class (*this);
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
875 octave_value_list tmp = feval ("loadobj", in, 1);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
876
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
877 if (! error_state)
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
878 map = tmp(0).map_value ();
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
879 else
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
880 success = false;
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
881 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
882 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
883 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
884 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
885 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
886 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
887 success = false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
888 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
889 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
890 else if (len == 0 )
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
891 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
892 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
893 c_name = classname;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
894 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
895 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
896 panic_impossible ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
897 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
898 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
899 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
900 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
901 success = false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
902 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
903 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
904 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
905 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
906 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
907 success = false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
908 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
909
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
910 return success;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
911 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
912
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
913 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
914 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
915 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
916 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
917
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
918 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
919 os << class_name ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
920
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
921 Octave_map m;
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
922 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
923 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
924 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
925 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
926 if (! error_state)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
927 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
928 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
929 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
930 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
931 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
932 m = map_value ();
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
933
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
934 int32_t len = m.nfields();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
935 os.write (reinterpret_cast<char *> (&len), 4);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
936
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
937 Octave_map::iterator i = m.begin ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
938 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
939 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
940 octave_value val = map.contents (i);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
941
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
942 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
943
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
944 if (! b)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
945 return os;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
946
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
947 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
948 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
949
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
950 return true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
951 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
952
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
953 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
954 octave_class::load_binary (std::istream& is, bool swap,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
955 oct_mach_info::float_format fmt)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
956 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
957 bool success = true;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
958
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
959 int32_t classname_len;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
960
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
961 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
962 if (! is)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
963 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
964 else if (swap)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
965 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
966
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
967 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
968 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
969 classname[classname_len] = '\0';
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
970 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
971 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
972 c_name = classname;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
973 }
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
974 reconstruct_exemplar ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
975
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
976 int32_t len;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
977 if (! is.read (reinterpret_cast<char *> (&len), 4))
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
978 return false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
979 if (swap)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
980 swap_bytes<4> (&len);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
981
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
982 if (len > 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
983 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
984 Octave_map m (map);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
985
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
986 for (octave_idx_type j = 0; j < len; j++)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
987 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
988 octave_value t2;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
989 bool dummy;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
990 std::string doc;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
991
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
992 // recurse to read cell elements
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
993 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
994 dummy, t2, doc);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
995
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
996 if (! is)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
997 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
998
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
999 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1000
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1001 if (error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1002 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1003 error ("load: internal error loading class elements");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1004 return false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1005 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1006
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1007 m.assign (nm, tcell);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1008 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1009
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1010 if (is)
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1011 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1012 map = m;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1013
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1014 if (! reconstruct_parents ())
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1015 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
1016 else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1017 {
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1018 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
1019 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1020 octave_value in = new octave_class (*this);
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1021 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
1022
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1023 if (! error_state)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1024 map = tmp(0).map_value ();
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1025 else
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1026 success = false;
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 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1029 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1030 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1031 {
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1032 warning ("load: failed to load class");
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1033 success = false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1034 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1035 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1036 else if (len == 0 )
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1037 map = Octave_map (dim_vector (1, 1));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1038 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1039 panic_impossible ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1040
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1041 return success;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1042 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1043
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1044 #if defined (HAVE_HDF5)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1045
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1046 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1047 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
1048 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1049 hsize_t hdims[3];
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1050 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
1051 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
1052 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
1053 hid_t class_hid = -1;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1054 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
1055 Octave_map m;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1056 Octave_map::iterator i;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1057
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1058 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
1059 if (group_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1060 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1061
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1062 // 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
1063 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
1064 if (type_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1065 goto error_cleanup;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1066
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1067 hdims[0] = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1068 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
1069 if (space_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1070 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1071
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1072 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
1073 H5P_DEFAULT);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1074 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
1075 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
1076 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1077
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1078 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
1079 if (data_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1080 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1081
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1082 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
1083 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1084 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
1085 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
1086 if (! error_state)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1087 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
1088 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1089 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1090 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1091 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1092 m = map_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1093
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1094 // 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
1095 i = m.begin ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1096 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1097 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1098 octave_value val = map.contents (i);
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 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
1101 save_as_floats);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1102
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1103 if (! retval2)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1104 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1105
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1106 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1107 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1108
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1109 error_cleanup:
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1110
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1111 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1112 H5Gclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1113
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1114 if (class_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1115 H5Dclose (class_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1116
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1117 if (space_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1118 H5Sclose (space_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1119
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1120 if (type_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1121 H5Tclose (type_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1122
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1123 if (group_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1124 H5Gclose (group_hid);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1125
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1126 return true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1127 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1128
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1129 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1130 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
1131 bool have_h5giterate_bug)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1132 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1133 bool retval = false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1134
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1135 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
1136 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
1137 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
1138 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
1139 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
1140 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
1141 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
1142
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1143 hdf5_callback_data dsub;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1144
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1145 herr_t retval2 = 0;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1146 Octave_map m (dim_vector (1, 1));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1147 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
1148 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
1149 int slen = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1150 hsize_t rank = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1151
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1152 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
1153 if (group_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1154 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1155
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1156
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1157 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
1158
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1159 if (data_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1160 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1161
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1162 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
1163
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1164 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
1165
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1166 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
1167 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1168
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1169 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
1170 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
1171
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1172 if (rank != 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1173 goto error_cleanup;
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 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
1176 if (slen < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1177 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1178
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1179 // 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
1180 do
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1181 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1182 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
1183
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1184 // 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
1185 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
1186 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
1187
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1188 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
1189 classname) < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1190 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1191 H5Tclose (st_id);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1192 H5Dclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1193 H5Gclose (group_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1194 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1195 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1196
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1197 H5Tclose (st_id);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1198 H5Dclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1199 data_hid = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1200
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1201 c_name = classname;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1202 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1203 while (0);
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1204 reconstruct_exemplar ();
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1205
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1206
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1207 #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
1208 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
1209 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
1210 H5Gclose (subgroup_hid);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1211
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1212 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
1213 && (retval2 = H5Giterate (group_hid, name, &current_item,
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1214 hdf5_read_next_data, &dsub)) > 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1215 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1216 while ((retval2 = H5Giterate (group_hid, name, &current_item,
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1217 hdf5_read_next_data, &dsub)) > 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1218 #endif
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1219 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1220 octave_value t2 = dsub.tc;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1221
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1222 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1223
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1224 if (error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1225 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1226 error ("load: internal error loading class elements");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1227 return false;
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
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1230 m.assign (dsub.name, tcell);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1231
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1232 if (have_h5giterate_bug)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1233 current_item++; // H5Giterate returned the last index processed
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1234 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1235
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1236 if (retval2 >= 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1237 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1238 map = m;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1239
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1240 if (!reconstruct_parents ())
9190
7a10410db2c6 [mq]: x
Robert T. Short <rtshort@ieee.org>
parents: 9182
diff changeset
1241 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
1242 else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1243 {
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1244 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
1245 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1246 octave_value in = new octave_class (*this);
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1247 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
1248
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1249 if (! error_state)
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1250 {
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1251 map = tmp(0).map_value ();
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1252 retval = true;
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1253 }
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1254 else
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1255 retval = false;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1256 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1257 else
9182
23af5910e5f5 make load work for derived classses
Robert T. Short <octave@phaselockedsystems.com>
parents: 9156
diff changeset
1258 retval = true;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1259 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1260 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1261
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1262 error_cleanup:
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1263 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1264 H5Dclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1265
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1266 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1267 H5Gclose (group_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1268
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1269 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1270 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1271
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1272 #endif
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1273
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1274 mxArray *
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1275 octave_class::as_mxArray (void) const
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 gripe_wrong_type_arg ("octave_class::as_mxArray ()", type_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1278
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1279 return 0;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1280 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1281
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1282 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1283 octave_class::in_class_method (void) const
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 octave_function *fcn = octave_call_stack::current ();
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 return (fcn
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
1288 && (fcn->is_class_method ()
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
1289 || fcn->is_class_constructor ()
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
1290 || fcn->is_private_function_of_class (class_name ()))
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1291 && fcn->dispatch_class () == class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1292 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1293
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1294 octave_class::exemplar_info::exemplar_info (const octave_value& obj)
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1295 : field_names (), parent_class_names ()
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1296 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1297 if (obj.is_object ())
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1298 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1299 Octave_map m = obj.map_value ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1300 field_names = m.keys ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1301
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1302 parent_class_names = obj.parent_class_name_list ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1303 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1304 else
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1305 error ("invalid call to exmplar_info constructor");
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1306 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1307
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1308
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1309 // A map from class names to lists of fields.
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1310 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
1311
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1312 bool
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1313 octave_class::exemplar_info::compare (const octave_value& obj) const
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1314 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1315 bool retval = true;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1316
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1317 if (obj.is_object ())
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1318 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1319 if (nfields () == obj.nfields ())
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1320 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1321 Octave_map obj_map = obj.map_value ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1322 string_vector obj_fnames = obj_map.keys ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1323 string_vector fnames = fields ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1324
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1325 for (octave_idx_type i = 0; i < nfields (); i++)
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1326 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1327 if (obj_fnames[i] != fnames[i])
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1328 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1329 retval = false;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1330 error ("mismatch in field names");
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1331 break;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1332 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1333 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1334
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1335 if (nparents () == obj.nparents ())
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1336 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1337 std::list<std::string> obj_parents
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1338 = obj.parent_class_name_list ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1339 std::list<std::string> pnames = parents ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1340
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1341 std::list<std::string>::const_iterator p = obj_parents.begin ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1342 std::list<std::string>::const_iterator q = pnames.begin ();
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1343
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1344 while (p != obj_parents.end ())
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1345 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1346 if (*p++ != *q++)
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1347 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1348 retval = false;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1349 error ("mismatch in parent classes");
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1350 break;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1351 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1352 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1353 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1354 else
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1355 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1356 retval = false;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1357 error ("mismatch in number of parent classes");
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1358 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1359 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1360 else
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1361 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1362 retval = false;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1363 error ("mismatch in number of fields");
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1364 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1365 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1366 else
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1367 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1368 retval = false;
9206
5f36c6c9be13 Handle loading of objects with inheritance from MAT files.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9190
diff changeset
1369 error ("invalid comparison of class exemplar to non-class object");
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1370 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1371
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1372 return retval;
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1373 }
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1374
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1375 DEFUN (class, args, ,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1376 "-*- texinfo -*-\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1377 @deftypefn {Built-in Function} {} class (@var{expr})\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1378 @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
1379 @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
1380 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
1381 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
1382 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
1383 derived.\n\
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1384 @end deftypefn")
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 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1387
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1388 int nargin = args.length ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1389
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1390 if (nargin == 0)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1391 print_usage ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1392 else if (nargin == 1)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1393 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
1394 else
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1395 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1396 Octave_map m = args(0).map_value ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1397
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1398 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1399 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1400 std::string id = args(1).string_value ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1401
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1402 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1403 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1404 octave_function *fcn = octave_call_stack::caller ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1405
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1406 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
1407 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1408 if (nargin == 2)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1409 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
1410 else
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1411 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1412 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
1413
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1414 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
1415 }
9151
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1416
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1417 if (! error_state)
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1418 {
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1419 octave_class::exemplar_const_iterator it
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1420 = octave_class::exemplar_map.find (id);
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1421
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1422 if (it == octave_class::exemplar_map.end ())
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1423 octave_class::exemplar_map[id]
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1424 = octave_class::exemplar_info (retval);
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1425 else if (! it->second.compare (retval))
d8f9588c6ba1 object exemplars
John W. Eaton <jwe@octave.org>
parents: 9148
diff changeset
1426 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
1427 }
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1428 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1429 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1430 error ("class: invalid call from outside class constructor");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1431 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1432 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1433 error ("class: expecting character string as second argument");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1434 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1435 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1436 error ("class: expecting structure as first argument");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1437 }
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1438
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1439 return retval;
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1440 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1441
9147
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1442 DEFUN (__isa_parent__, args, ,
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1443 "-*- texinfo -*-\n\
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1444 @deftypefn {Built-in Function} {} __isa_parent__ (@var{class}, @var{name})\n\
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1445 Undocumented internal function.\n\
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1446 @end deftypefn")
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1447 {
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1448 octave_value retval = false;
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1449
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1450 if (args.length () == 2)
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1451 {
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1452 octave_value cls = args(0);
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1453 octave_value nm = args(1);
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1454
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1455 if (! error_state)
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1456 {
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1457 if (cls.find_parent_class (nm.string_value ()))
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1458 retval = true;
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1459 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1460 else
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1461 error ("__isa_parent__: expecting arguments to be character strings");
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1462 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1463 else
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1464 print_usage ();
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1465
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1466 return retval;
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1467 }
5579998f8acf Update to OOP facilities.
rtshort@bristlecone.phaselocked.com
parents: 9010
diff changeset
1468
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1469 DEFUN (__parent_classes__, args, ,
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1470 "-*- texinfo -*-\n\
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1471 @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
1472 Undocumented internal function.\n\
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1473 @end deftypefn")
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1474 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1475 octave_value retval = Cell ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1476
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1477 if (args.length () == 1)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1478 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1479 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
1480
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1481 if (arg.is_object ())
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1482 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
1483 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1484 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1485 print_usage ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1486
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1487 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1488 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1489
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1490 DEFUN (isobject, args, ,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1491 "-*- texinfo -*-\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1492 @deftypefn {Built-in Function} {} isobject (@var{x})\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1493 Return true if @var{x} is a class object.\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1494 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1495 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1496 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1497
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1498 if (args.length () == 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1499 retval = args(0).is_object ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1500 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1501 print_usage ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1502
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1503 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1504 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1505
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1506 DEFUN (ismethod, args, ,
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1507 "-*- texinfo -*-\n\
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1508 @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
1509 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
1510 is a method of this class.\n\
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1511 @end deftypefn")
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1512 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1513 octave_value retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1514
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1515 if (args.length () == 2)
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1516 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1517 octave_value arg = args(0);
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1518
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1519 std::string class_name;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1520
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1521 if (arg.is_object ())
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1522 class_name = arg.class_name ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1523 else if (arg.is_string ())
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1524 class_name = arg.string_value ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1525 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1526 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
1527
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1528 if (! error_state)
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1529 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1530 std::string method = args(1).string_value ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1531
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1532 if (! error_state)
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1533 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1534 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
1535 retval = true;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1536 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1537 retval = false;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1538 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1539 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1540 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1541 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1542 print_usage ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1543
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1544 return retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1545 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1546
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
1547 DEFUN (methods, args, nargout,
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1548 "-*- texinfo -*-\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1549 @deftypefn {Built-in Function} {} methods (@var{x})\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1550 @deftypefnx {Built-in Function} {} methods (\"classname\")\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1551 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
1552 object @var{x} or the named class.\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1553 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1554 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1555 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1556
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1557 if (args.length () == 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1558 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1559 octave_value arg = args(0);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1560
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1561 std::string class_name;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1562
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1563 if (arg.is_object ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1564 class_name = arg.class_name ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1565 else if (arg.is_string ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1566 class_name = arg.string_value ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1567 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1568 error ("methods: expecting object or class name as argument");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1569
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1570 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1571 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1572 string_vector sv = load_path::methods (class_name);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1573
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1574 if (nargout == 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1575 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1576 octave_stdout << "Methods for class " << class_name << ":\n\n";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1577
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1578 sv.list_in_columns (octave_stdout);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1579
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1580 octave_stdout << std::endl;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1581 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1582 else
9206
5f36c6c9be13 Handle loading of objects with inheritance from MAT files.
Robert T. Short <octave@phaselockedsystems.com>
parents: 9190
diff changeset
1583 retval = Cell (sv);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1584 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1585 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1586 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1587 print_usage ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1588
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1589 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1590 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1591
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1592 static bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1593 is_built_in_class (const std::string& cn)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1594 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1595 static std::set<std::string> built_in_class_names;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1596
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1597 if (built_in_class_names.empty ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1598 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1599 built_in_class_names.insert ("double");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1600 built_in_class_names.insert ("single");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1601 built_in_class_names.insert ("cell");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1602 built_in_class_names.insert ("struct");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1603 built_in_class_names.insert ("logical");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1604 built_in_class_names.insert ("char");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1605 built_in_class_names.insert ("function handle");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1606 built_in_class_names.insert ("int8");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1607 built_in_class_names.insert ("uint8");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1608 built_in_class_names.insert ("int16");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1609 built_in_class_names.insert ("uint16");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1610 built_in_class_names.insert ("int32");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1611 built_in_class_names.insert ("uint32");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1612 built_in_class_names.insert ("int64");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1613 built_in_class_names.insert ("uint64");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1614 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1615
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1616 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
1617 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1618
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1619 DEFUN (superiorto, args, ,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1620 "-*- texinfo -*-\n\
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1621 @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
1622 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
1623 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
1624 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
1625 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
1626 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1627 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1628 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1629
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1630 octave_function *fcn = octave_call_stack::caller ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1631
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1632 if (fcn && fcn->is_class_constructor ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1633 {
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1634 for (int i = 0; i < args.length(); i++)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1635 {
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1636 std::string class_name = args(i).string_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1637
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1638 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1639 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1640 if (! is_built_in_class (class_name))
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1641 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1642 std::string this_class_name = fcn->name ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1643
7972
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1644 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
1645 class_name))
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1646 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1647 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
1648 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
1649 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1650 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1651 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1652 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1653 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1654 // User defined classes always have higher precedence
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1655 // than built-in classes.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1656 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1657 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1658 else
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1659 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1660 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
1661 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1662 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1663 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1664 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1665 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1666 error ("superiorto: invalid call from outside class constructor");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1667
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1668 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1669 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1670
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1671 DEFUN (inferiorto, args, ,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1672 "-*- texinfo -*-\n\
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1673 @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
1674 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
1675 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
1676 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
1677 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
1678 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1679 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1680 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1681
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1682 octave_function *fcn = octave_call_stack::caller ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1683
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1684 if (fcn && fcn->is_class_constructor ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1685 {
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1686 for (int i = 0; i < args.length(); i++)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1687 {
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1688 std::string class_name = args(i).string_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1689
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1690 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1691 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1692 if (! is_built_in_class (class_name))
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1693 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1694 std::string this_class_name = fcn->name ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1695
7972
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1696 symbol_table::set_class_relationship (class_name,
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1697 this_class_name);
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1698
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1699 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
1700 class_name))
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1701 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1702 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
1703 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
1704 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1705 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1706 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1707 else
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1708 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1709 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
1710 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1711 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1712 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1713 else
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1714 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1715 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
1716 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1717 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1718 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1719 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1720 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1721 error ("inferiorto: invalid call from outside class constructor");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1722
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1723 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1724 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1725
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1726 /*
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1727 ;;; Local Variables: ***
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1728 ;;; mode: C++ ***
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1729 ;;; End: ***
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1730 */