annotate src/ov-class.cc @ 9010:f914834836e7

Partial implementation of derived classes using the old form with "@" files.
author rtshort@smoketree.phaselocked.com
date Tue, 24 Mar 2009 11:29:53 -0400
parents eb63fbe60fab
children 5579998f8acf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1 /*
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
2
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8785
diff changeset
3 Copyright (C) 2007, 2008, 2009 John W. Eaton
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
4
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
6
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7444
1e1e2608da7b [project @ 2008-02-04 07:40:55 by jwe]
jwe
parents: 7338
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
1e1e2608da7b [project @ 2008-02-04 07:40:55 by jwe]
jwe
parents: 7338
diff changeset
10 option) any later version.
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
11
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
15 for more details.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
16
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7444
1e1e2608da7b [project @ 2008-02-04 07:40:55 by jwe]
jwe
parents: 7338
diff changeset
18 along with Octave; see the file COPYING. If not, see
1e1e2608da7b [project @ 2008-02-04 07:40:55 by jwe]
jwe
parents: 7338
diff changeset
19 <http://www.gnu.org/licenses/>.
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
20
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
21 */
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
22
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
25 #endif
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
26
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
27 #include <iostream>
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
28
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
29 #include "Array-util.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
30 #include "byte-swap.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8219
diff changeset
31 #include "oct-locbuf.h"
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
32
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
33 #include "Cell.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
34 #include "defun.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
35 #include "error.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
36 #include "gripes.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
37 #include "load-path.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
38 #include "ls-hdf5.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
39 #include "ls-oct-ascii.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
40 #include "ls-oct-binary.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
41 #include "ls-utils.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
42 #include "oct-lvalue.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
43 #include "ov-class.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
44 #include "ov-fcn.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
45 #include "pager.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
46 #include "parse.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
47 #include "pr-output.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
48 #include "toplev.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
49 #include "unwind-prot.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
50 #include "variables.h"
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
51
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
52 DEFINE_OCTAVE_ALLOCATOR(octave_class);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
53
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
54 int octave_class::t_id (-1);
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 const std::string octave_class::t_name ("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 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
59 octave_class::register_type (void)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
60 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
61 t_id = octave_value_typeinfo::register_type
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
62 (octave_class::t_name, "<unknown>", octave_value (new octave_class ()));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
63 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
64
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
65 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
66 const octave_value_list& parents)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
67 : octave_base_value (), map (m), c_name (id)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
68 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
69 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
70
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
71 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
72 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
73 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
74
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
75 if (! parent.is_object ())
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
76 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
77 else
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 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
80
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
81 parent_list.push_back (cnm);
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 map.assign (cnm, parent);
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
84 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
85 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
86
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
87 load_path::add_to_parent_map (id, parent_list);
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
88 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
89
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
90 octave_base_value *
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
91 octave_class::find_parent_class (const std::string& parent_class_name)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
92 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
93 octave_base_value* retval = 0;
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
94 std::string dbg_clsnm = class_name ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
95
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
96 if (parent_class_name == class_name ())
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
97 retval = this;
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
98 else
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
99 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
100 // Search in the list of immediate parents first, then in the
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
101 // ancestor tree.
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
102
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
103 std::list<std::string>::iterator
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
104 p = find (parent_list.begin (), parent_list.end (), parent_class_name);
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
105
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
106 if (p != parent_list.end ())
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
107 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
108 Octave_map::const_iterator pmap = map.seek (parent_class_name);
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
109
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
110 if (pmap != map.end ())
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
111 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
112 const Cell& tmp = pmap->second;
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
113
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
114 octave_value vtmp = tmp(0);
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
115
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
116 retval = vtmp.internal_rep ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
117 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
118 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
119 else
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
120 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
121 for (std::list<std::string>::iterator pit = parent_list.begin ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
122 pit != parent_list.end ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
123 pit++)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
124 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
125 Octave_map::const_iterator smap = map.seek (*pit);
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
126
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
127 const Cell& tmp = smap->second;
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
128
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
129 octave_value vtmp = tmp(0);
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
130
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
131 octave_base_value *obvp = vtmp.internal_rep ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
132
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
133 retval = obvp->find_parent_class (parent_class_name);
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
134
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
135 if (retval)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
136 break;
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
137 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
138 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
139 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
140
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
141 return retval;
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
142 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
143
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
144 Cell
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
145 octave_class::dotref (const octave_value_list& idx)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
146 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
147 Cell retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
148
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
149 assert (idx.length () == 1);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
150
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
151 // FIXME -- Is there a "proper" way to do this?
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
152 octave_function* fcn = octave_call_stack::current ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
153 std::string my_dir = fcn->dir_name ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
154 int ipos = my_dir.find_last_of ("@");
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
155 std::string method_class = my_dir.substr (ipos+1);
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
156
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
157 // Find the class in which this method resides before attempting to access
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
158 // the requested field.
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
159
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
160 octave_base_value *obvp = find_parent_class (method_class);
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
161
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
162 Octave_map my_map;
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
163
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
164 my_map = obvp ? obvp->map_value () : map;
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
165
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
166 std::string nm = idx(0).string_value ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
167
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
168 Octave_map::const_iterator p = my_map.seek (nm);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
169
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
170 if (p != my_map.end ())
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
171 retval = my_map.contents (p);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
172 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
173 error ("class has no member `%s'", nm.c_str ());
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 return retval;
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
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
178 static void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
179 gripe_invalid_index (void)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
180 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
181 error ("invalid index for class");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
182 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
183
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
184 static void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
185 gripe_invalid_index_for_assignment (void)
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 error ("invalid index for class assignment");
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
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
190 static void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
191 gripe_invalid_index_type (const std::string& nm, char t)
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 error ("%s cannot be indexed with %c", nm.c_str (), t);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
194 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
195
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
196 static void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
197 gripe_failed_assignment (void)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
198 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
199 error ("assignment to class element failed");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
200 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
201
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
202 static inline octave_value_list
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
203 sanitize (const octave_value_list& ovl)
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 octave_value_list retval = ovl;
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 for (octave_idx_type i = 0; i < ovl.length (); i++)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
208 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
209 if (retval(i).is_magic_colon ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
210 retval(i) = ":";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
211 }
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 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
214 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
215
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
216 static inline octave_value
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
217 make_idx_args (const std::string& type,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
218 const std::list<octave_value_list>& idx,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
219 const std::string& who)
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 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
222
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
223 size_t len = type.length ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
224
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
225 if (len == idx.size ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
226 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
227 Cell type_field (len, 1);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
228 Cell subs_field (len, 1);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
229
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
230 std::list<octave_value_list>::const_iterator p = idx.begin ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
231
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
232 for (size_t i = 0; i < len; i++)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
233 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
234 char t = type[i];
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
235
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
236 switch (t)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
237 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
238 case '(':
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
239 type_field(i) = "()";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
240 subs_field(i) = Cell (sanitize (*p++));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
241 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
242
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
243 case '{':
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
244 type_field(i) = "{}";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
245 subs_field(i) = Cell (sanitize (*p++));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
246 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
247
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
248 case '.':
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
249 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
250 type_field(i) = ".";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
251
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
252 octave_value_list vlist = *p++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
253
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
254 if (vlist.length () == 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
255 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
256 octave_value val = vlist(0);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
257
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
258 if (val.is_string ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
259 subs_field(i) = val;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
260 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
261 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
262 error ("expecting character string argument for `.' index");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
263 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
264 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
265 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
266 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
267 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
268 error ("expecting single argument for `.' index");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
269 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
270 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
271 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
272 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
273
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
274 default:
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
275 panic_impossible ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
276 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
277 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
278 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
279
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
280 Octave_map m;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
281
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
282 m.assign ("type", type_field);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
283 m.assign ("subs", subs_field);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
284
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
285 retval = m;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
286 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
287 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
288 error ("invalid index for %s", who.c_str ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
289
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
290 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
291 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
292
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
293 octave_value_list
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
294 octave_class::subsref (const std::string& type,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
295 const std::list<octave_value_list>& idx,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
296 int nargout)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
297 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
298 octave_value_list retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
299
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
300 if (in_class_method ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
301 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
302 // FIXME -- this block of code is the same as the body of
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
303 // octave_struct::subsref. Maybe it could be shared instead of
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
304 // duplicated.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
305
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
306 int skip = 1;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
307
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
308 switch (type[0])
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
309 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
310 case '(':
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
311 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
312 if (type.length () > 1 && type[1] == '.')
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
313 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
314 std::list<octave_value_list>::const_iterator p = idx.begin ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
315 octave_value_list key_idx = *++p;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
316
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
317 Cell tmp = dotref (key_idx);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
318
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
319 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
320 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
321 Cell t = tmp.index (idx.front ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
322
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
323 retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
324
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
325 // We handled two index elements, so tell
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
326 // next_subsref to skip both of them.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
327
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
328 skip++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
329 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
330 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
331 else
8782
45524925bed9 ov-class.cc (octave_class::subsref): return class object, not struct when indexing directly
John W. Eaton <jwe@octave.org>
parents: 8746
diff changeset
332 retval(0) = octave_value (map.index (idx.front ()),
45524925bed9 ov-class.cc (octave_class::subsref): return class object, not struct when indexing directly
John W. Eaton <jwe@octave.org>
parents: 8746
diff changeset
333 class_name ());
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
334 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
335 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
336
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
337 case '.':
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
338 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
339 if (map.numel() > 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
340 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
341 Cell t = dotref (idx.front ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
342
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
343 retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
344 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
345 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
346 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
347
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
348 case '{':
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
349 gripe_invalid_index_type (type_name (), type[0]);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
350 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
351
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
352 default:
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
353 panic_impossible ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
354 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
355
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
356 // FIXME -- perhaps there should be an
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
357 // octave_value_list::next_subsref member function? See also
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
358 // octave_user_function::subsref.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
359
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
360 if (idx.size () > 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
361 retval = retval(0).next_subsref (nargout, type, idx, skip);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
362 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
363 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
364 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
365 octave_value meth = symbol_table::find_method ("subsref", class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
366
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
367 if (meth.is_defined ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
368 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
369 octave_value_list args;
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 args(1) = make_idx_args (type, idx, "subsref");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
372
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
373 if (error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
374 return octave_value_list ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
375
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
376 count++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
377 args(0) = octave_value (this);
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 return feval (meth.function_value (), args, nargout);
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 else
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 if (type.length () == 1 && type[0] == '(')
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
384 retval(0) = octave_value (map.index (idx.front ()), class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
385 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
386 gripe_invalid_index ();
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 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
389
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
390 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
391 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
392
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
393 octave_value
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
394 octave_class::numeric_conv (const Cell& val, const std::string& type)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
395 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
396 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
397
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
398 if (val.length () == 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
399 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
400 retval = val(0);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
401
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
402 if (type.length () > 0 && type[0] == '.' && ! retval.is_map ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
403 retval = Octave_map ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
404 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
405 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
406 gripe_invalid_index_for_assignment ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
407
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
408 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
409 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
410
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
411 octave_value
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
412 octave_class::subsasgn (const std::string& type,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
413 const std::list<octave_value_list>& idx,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
414 const octave_value& rhs)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
415 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
416 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
417
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
418 if (! in_class_method ())
7338
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 octave_value meth = symbol_table::find_method ("subsasgn", class_name ());
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 if (meth.is_defined ())
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 octave_value_list args;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
425
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
426 args(2) = rhs;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
427
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
428 args(1) = make_idx_args (type, idx, "subsasgn");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
429
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
430 if (error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
431 return octave_value_list ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
432
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
433 count++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
434 args(0) = octave_value (this);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
435
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
436 octave_value_list tmp = feval (meth.function_value (), args);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
437
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
438 // FIXME -- should the subsasgn method be able to return
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
439 // more than one value?
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
440
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
441 if (tmp.length () > 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
442 error ("expecting single return value from @%s/subsasgn",
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
443 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
444
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
445 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
446 retval = tmp(0);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
447
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
448 return retval;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
449 }
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
450 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
451
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
452 // FIXME -- this block of code is the same as the body of
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
453 // octave_struct::subsasgn. Maybe it could be shared instead of
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
454 // duplicated.
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
455
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
456 int n = type.length ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
457
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
458 octave_value t_rhs = rhs;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
459
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
460 if (n > 1 && ! (type.length () == 2 && type[0] == '(' && type[1] == '.'))
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
461 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
462 switch (type[0])
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
463 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
464 case '(':
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
465 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
466 if (type.length () > 1 && type[1] == '.')
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
467 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
468 std::list<octave_value_list>::const_iterator p = idx.begin ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
469 octave_value_list t_idx = *p;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
470
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
471 octave_value_list key_idx = *++p;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
472
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
473 assert (key_idx.length () == 1);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
474
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
475 std::string key = key_idx(0).string_value ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
476
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
477 octave_value u;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
478
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
479 if (! map.contains (key))
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
480 u = octave_value::empty_conv (type.substr (2), rhs);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
481 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
482 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
483 Cell map_val = map.contents (key);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
484
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
485 Cell map_elt = map_val.index (idx.front (), true);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
486
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
487 u = numeric_conv (map_elt, type.substr (2));
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
488 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
489
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
490 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
491 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
492 std::list<octave_value_list> next_idx (idx);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
493
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
494 // We handled two index elements, so subsasgn to
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
495 // needs to skip both of them.
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
496
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
497 next_idx.erase (next_idx.begin ());
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
498 next_idx.erase (next_idx.begin ());
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
499
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
500 u.make_unique ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
501
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
502 t_rhs = u.subsasgn (type.substr (2), next_idx, rhs);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
503 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
504 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
505 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
506 gripe_invalid_index_for_assignment ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
507 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
508 break;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
509
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
510 case '.':
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
511 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
512 octave_value_list key_idx = idx.front ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
513
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
514 assert (key_idx.length () == 1);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
515
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
516 std::string key = key_idx(0).string_value ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
517
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
518 octave_value u;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
519
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
520 if (! map.contains (key))
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
521 u = octave_value::empty_conv (type.substr (1), rhs);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
522 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
523 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
524 Cell map_val = map.contents (key);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
525
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
526 u = numeric_conv (map_val, type.substr (1));
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
527 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
528
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
529 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
530 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
531 std::list<octave_value_list> next_idx (idx);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
532
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
533 next_idx.erase (next_idx.begin ());
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
534
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
535 u.make_unique ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
536
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
537 t_rhs = u.subsasgn (type.substr (1), next_idx, rhs);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
538 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
539 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
540 break;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
541
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
542 case '{':
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
543 gripe_invalid_index_type (type_name (), type[0]);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
544 break;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
545
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
546 default:
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
547 panic_impossible ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
548 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
549 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
550
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
551 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
552 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
553 switch (type[0])
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
554 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
555 case '(':
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
556 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
557 if (n > 1 && type[1] == '.')
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
558 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
559 std::list<octave_value_list>::const_iterator p = idx.begin ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
560 octave_value_list key_idx = *++p;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
561
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
562 assert (key_idx.length () == 1);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
563
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
564 std::string key = key_idx(0).string_value ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
565
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
566 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
567 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
568 map.assign (idx.front (), key, t_rhs);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
569
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
570 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
571 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
572 count++;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
573 retval = octave_value (this);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
574 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
575 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
576 gripe_failed_assignment ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
577 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
578 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
579 gripe_failed_assignment ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
580 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
581 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
582 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
583 if (t_rhs.is_object () || t_rhs.is_map ())
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
584 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
585 Octave_map rhs_map = t_rhs.map_value ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
586
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
587 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
588 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
589 map.assign (idx.front (), rhs_map);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
590
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
591 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
592 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
593 count++;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
594 retval = octave_value (this);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
595 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
596 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
597 gripe_failed_assignment ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
598 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
599 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
600 error ("invalid class assignment");
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
601 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
602 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
603 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
604 if (t_rhs.is_empty ())
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
605 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
606 map.maybe_delete_elements (idx.front());
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
607
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
608 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
609 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
610 count++;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
611 retval = octave_value (this);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
612 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
613 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
614 gripe_failed_assignment ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
615 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
616 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
617 error ("invalid class assignment");
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
618 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
619 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
620 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
621 break;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
622
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
623 case '.':
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
624 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
625 octave_value_list key_idx = idx.front ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
626
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
627 assert (key_idx.length () == 1);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
628
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
629 std::string key = key_idx(0).string_value ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
630
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
631 map.assign (key, t_rhs);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
632
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
633 if (! error_state)
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
634 {
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
635 count++;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
636 retval = octave_value (this);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
637 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
638 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
639 gripe_failed_assignment ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
640 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
641 break;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
642
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
643 case '{':
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
644 gripe_invalid_index_type (type_name (), type[0]);
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
645 break;
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
646
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
647 default:
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
648 panic_impossible ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
649 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
650 }
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
651 else
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
652 gripe_failed_assignment ();
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
653
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
654 return retval;
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
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
657 idx_vector
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
658 octave_class::index_vector (void) const
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
659 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
660 idx_vector retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
661
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
662 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
663
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
664 if (meth.is_defined ())
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
665 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
666 octave_value_list args;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
667 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
668
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
669 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
670
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
671 if (!error_state && tmp.length () >= 1)
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
672 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
673 if (tmp(0).is_object())
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
674 error ("subsindex function must return a valid index vector");
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
675 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
676 // Index vector returned by subsindex is zero based
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
677 // (why this inconsistency Mathworks?), and so we must
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
678 // 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
679 // expects it to be one based.
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
680 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
681 octave_value (1.0)).index_vector ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
682 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
683 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
684 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
685 error ("no subsindex method defined for class %s",
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
686 class_name().c_str ());
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
687
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
688 return retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
689 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
690
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
691 size_t
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
692 octave_class::byte_size (void) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
693 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
694 // Neglect the size of the fieldnames.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
695
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
696 size_t retval = 0;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
697
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
698 for (Octave_map::const_iterator p = map.begin (); p != map.end (); p++)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
699 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
700 std::string key = map.key (p);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
701
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
702 octave_value val = octave_value (map.contents (p));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
703
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
704 retval += val.byte_size ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
705 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
706
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
707 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
708 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
709
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
710 string_vector
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
711 octave_class::map_keys (void) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
712 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
713 string_vector retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
714 gripe_wrong_type_arg ("octave_class::map_keys()", type_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
715 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
716 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
717
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
718 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
719 octave_class::print (std::ostream& os, bool) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
720 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
721 print_raw (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
722 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
723
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
724 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
725 octave_class::print_raw (std::ostream& os, bool) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
726 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
727 unwind_protect::begin_frame ("octave_class_print");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
728
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
729 unwind_protect_int (Vstruct_levels_to_print);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
730
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
731 indent (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
732 os << " <class " << class_name () << ">";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
733 newline (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
734
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
735 unwind_protect::run_frame ("octave_class_print");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
736 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
737
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
738 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
739 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
740 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
741 bool retval = false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
742
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
743 indent (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
744 os << name << " =";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
745 newline (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
746 newline (os);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
747
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
748 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
749 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
750
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
751 void
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
752 octave_class::print_with_name (std::ostream&, const std::string& name,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
753 bool) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
754 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
755 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
756
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
757 if (fcn.is_defined ())
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
758 {
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
759 octave_value_list args;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
760
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
761 args(0) = octave_value (clone (), 1);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
762
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
763 string_vector arg_names (1);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
764
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
765 arg_names[0] = name;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
766
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
767 args.stash_name_tags (arg_names);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
768
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
769 feval (fcn.function_value (), args);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
770 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
771 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
772
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
773 bool
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
774 octave_class::save_ascii (std::ostream& os)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
775 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
776 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
777 Octave_map m;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
778 if (load_path::find_method (class_name (), "saveobj") != std::string())
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
779 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
780 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
781 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
782 if (! error_state)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
783 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
784 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
785 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
786 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
787 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
788 m = map_value ();
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 << "# length: " << m.nfields () << "\n";
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
791
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
792 Octave_map::iterator i = m.begin ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
793 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
794 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
795 octave_value val = map.contents (i);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
796
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
797 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
798
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
799 if (! b)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
800 return os;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
801
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
802 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
803 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
804
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
805 return true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
806 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
807
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
808 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
809 octave_class::load_ascii (std::istream& is)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
810 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
811 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
812 std::string classname;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
813 bool success = true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
814
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
815 if (extract_keyword (is, "classname", classname) && classname != "")
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
816 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
817 if (extract_keyword (is, "length", len) && len >= 0)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
818 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
819 if (len > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
820 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
821 Octave_map m (map);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
822
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
823 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
824 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
825 octave_value t2;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
826 bool dummy;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
827
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
828 // 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
829 std::string nm
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
830 = read_ascii_data (is, std::string (), dummy, t2, j);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
831
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
832 if (!is)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
833 break;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
834
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
835 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
836
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
837 if (error_state)
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 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
840 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
841 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
842
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
843 m.assign (nm, tcell);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
844 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
845
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
846 if (is)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
847 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
848 map = m;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
849 c_name = classname;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
850
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
851 if (load_path::find_method (classname, "loadobj") !=
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
852 std::string())
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
853 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
854 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
855 octave_value_list tmp = feval ("loadobj", in, 1);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
856
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
857 if (! error_state)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
858 map = tmp(0).map_value ();
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
859 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
860 success = false;
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 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
863 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
864 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
865 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
866 success = false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
867 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
868 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
869 else if (len == 0 )
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
870 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
871 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
872 c_name = classname;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
873 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
874 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
875 panic_impossible ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
876 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
877 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
878 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
879 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
880 success = false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
881 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
882 }
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
883 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
884 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
885 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
886 success = false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
887 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
888
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
889 return success;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
890 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
891
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
892 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
893 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
894 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
895 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
896
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
897 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
898 os << class_name ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
899
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
900 Octave_map m;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
901 if (load_path::find_method (class_name (), "saveobj") != std::string())
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
902 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
903 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
904 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
905 if (! error_state)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
906 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
907 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
908 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
909 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
910 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
911 m = map_value ();
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
912
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
913 int32_t len = m.nfields();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
914 os.write (reinterpret_cast<char *> (&len), 4);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
915
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
916 Octave_map::iterator i = m.begin ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
917 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
918 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
919 octave_value val = map.contents (i);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
920
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
921 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
922
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
923 if (! b)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
924 return os;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
925
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
926 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
927 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
928
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
929 return true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
930 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
931
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
932 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
933 octave_class::load_binary (std::istream& is, bool swap,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
934 oct_mach_info::float_format fmt)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
935 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
936 bool success = true;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
937
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
938 int32_t classname_len;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
939
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
940 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
941 if (! is)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
942 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
943 else if (swap)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
944 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
945
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
946 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
947 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
948 classname[classname_len] = '\0';
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
949 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
950 return false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
951 c_name = classname;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
952 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
953
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
954 int32_t len;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
955 if (! is.read (reinterpret_cast<char *> (&len), 4))
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
956 return false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
957 if (swap)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
958 swap_bytes<4> (&len);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
959
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
960 if (len > 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
961 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
962 Octave_map m (map);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
963
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
964 for (octave_idx_type j = 0; j < len; j++)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
965 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
966 octave_value t2;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
967 bool dummy;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
968 std::string doc;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
969
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
970 // recurse to read cell elements
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
971 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
972 dummy, t2, doc);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
973
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
974 if (!is)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
975 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
976
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
977 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
978
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
979 if (error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
980 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
981 error ("load: internal error loading class elements");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
982 return false;
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
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
985 m.assign (nm, tcell);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
986 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
987
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
988 if (is)
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
989 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
990 map = m;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
991
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
992 if (load_path::find_method (class_name(), "loadobj") != std::string())
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
993 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
994 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
995 octave_value_list tmp = feval ("loadobj", in, 1);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
996
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
997 if (! error_state)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
998 map = tmp(0).map_value ();
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
999 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1000 success = false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1001 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1002 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1003 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1004 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1005 error ("load: failed to load class");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1006 success = false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1007 }
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 else if (len == 0 )
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1010 map = Octave_map (dim_vector (1, 1));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1011 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1012 panic_impossible ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1013
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1014 return success;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1015 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1016
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1017 #if defined (HAVE_HDF5)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1018
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1019 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1020 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
1021 {
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1022 hsize_t hdims[3];
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1023 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
1024 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
1025 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
1026 hid_t class_hid = -1;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1027 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
1028 Octave_map m;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1029 Octave_map::iterator i;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1030
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1031 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
1032 if (group_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1033 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1034
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1035 // 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
1036 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
1037 if (type_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1038 goto error_cleanup;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1039
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1040 hdims[0] = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1041 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
1042 if (space_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1043 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1044
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1045 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
1046 H5P_DEFAULT);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1047 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
1048 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
1049 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1050
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1051 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
1052 if (data_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1053 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1054
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1055 if (load_path::find_method (class_name (), "saveobj") != std::string())
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1056 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1057 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
1058 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
1059 if (! error_state)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1060 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
1061 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1062 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1063 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1064 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1065 m = map_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1066
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1067 // 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
1068 i = m.begin ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1069 while (i != m.end ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1070 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1071 octave_value val = map.contents (i);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1072
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1073 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
1074 save_as_floats);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1075
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1076 if (! retval2)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1077 break;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1078
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1079 i++;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1080 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1081
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1082 error_cleanup:
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 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1085 H5Gclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1086
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1087 if (class_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1088 H5Dclose (class_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1089
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1090 if (space_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1091 H5Sclose (space_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1092
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1093 if (type_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1094 H5Tclose (type_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1095
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1096 if (group_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1097 H5Gclose (group_hid);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1098
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1099 return true;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1100 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1101
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1102 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1103 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
1104 bool have_h5giterate_bug)
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 bool retval = false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1107
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1108 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
1109 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
1110 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
1111 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
1112 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
1113 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
1114 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
1115
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1116 hdf5_callback_data dsub;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1117
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1118 herr_t retval2 = 0;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1119 Octave_map m (dim_vector (1, 1));
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1120 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
1121 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
1122 int slen = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1123 hsize_t rank = 0;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1124
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1125 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
1126 if (group_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1127 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1128
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1129
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1130 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
1131
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1132 if (data_hid < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1133 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1134
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1135 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
1136
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1137 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
1138
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1139 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
1140 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1141
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1142 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
1143 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
1144
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1145 if (rank != 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1146 goto error_cleanup;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1147
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1148 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
1149 if (slen < 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1150 goto error_cleanup;
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 // 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
1153 do
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1154 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1155 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
1156
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1157 // 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
1158 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
1159 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
1160
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1161 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
1162 classname) < 0)
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 H5Tclose (st_id);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1165 H5Dclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1166 H5Gclose (group_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1167 return false;
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
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1170 H5Tclose (st_id);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1171 H5Dclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1172 data_hid = -1;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1173
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1174 c_name = classname;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1175 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1176 while (0);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1177
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1178
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1179 #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
1180 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
1181 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
1182 H5Gclose (subgroup_hid);
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1183
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1184 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
1185 && (retval2 = H5Giterate (group_hid, name, &current_item,
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1186 hdf5_read_next_data, &dsub)) > 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1187 #else
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1188 while ((retval2 = H5Giterate (group_hid, name, &current_item,
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1189 hdf5_read_next_data, &dsub)) > 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1190 #endif
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1191 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1192 octave_value t2 = dsub.tc;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1193
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1194 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1195
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1196 if (error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1197 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1198 error ("load: internal error loading class elements");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1199 return false;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1200 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1201
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1202 m.assign (dsub.name, tcell);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1203
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1204 if (have_h5giterate_bug)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1205 current_item++; // H5Giterate returned the last index processed
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1206 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1207
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1208 if (retval2 >= 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1209 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1210 map = m;
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1211
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1212 if (load_path::find_method (class_name(), "loadobj") != std::string())
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1213 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1214 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
1215 octave_value_list tmp = feval ("loadobj", in, 1);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1216
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1217 if (! error_state)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1218 {
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1219 map = tmp(0).map_value ();
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1220 retval = true;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1221 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1222 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1223 retval = false;
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1224 }
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1225 else
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1226 retval = true;
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1227 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1228
8212
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1229 error_cleanup:
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1230 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1231 H5Dclose (data_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1232
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1233 if (data_hid > 0)
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1234 H5Gclose (group_hid);
ebf6f6a0f9a7 Allow saving/loading of classes. Add saveobj and loadobj methods
David Bateman <dbateman@free.fr>
parents: 8154
diff changeset
1235
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1236 return retval;
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
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1239 #endif
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1240
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1241 mxArray *
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1242 octave_class::as_mxArray (void) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1243 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1244 gripe_wrong_type_arg ("octave_class::as_mxArray ()", type_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1245
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1246 return 0;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1247 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1248
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1249 bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1250 octave_class::in_class_method (void) const
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1251 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1252 octave_function *fcn = octave_call_stack::current ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1253
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1254 return (fcn
8785
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
1255 && (fcn->is_class_method ()
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
1256 || fcn->is_class_constructor ()
70f5a0375afd oct-map.h: fix think-o in previous change
John W. Eaton <jwe@octave.org>
parents: 8782
diff changeset
1257 || fcn->is_private_function_of_class (class_name ()))
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1258 && fcn->dispatch_class () == class_name ());
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1259 }
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 DEFUN (class, args, ,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1262 "-*- texinfo -*-\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1263 @deftypefn {Built-in Function} {} class (@var{expr})\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1264 @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
1265 @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
1266 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
1267 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
1268 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
1269 derived.\n\
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1270 @end deftypefn")
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 octave_value retval;
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 int nargin = args.length ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1275
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1276 if (nargin == 0)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1277 print_usage ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1278 else if (nargin == 1)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1279 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
1280 else
7338
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 Octave_map m = args(0).map_value ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1283
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1284 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1285 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1286 std::string id = args(1).string_value ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1287
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1288 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1289 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1290 octave_function *fcn = octave_call_stack::caller ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1291
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1292 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
1293 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1294 if (nargin == 2)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1295 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
1296 else
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1297 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1298 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
1299
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1300 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
1301 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1302 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1303 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1304 error ("class: invalid call from outside class constructor");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1305 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1306 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1307 error ("class: expecting character string as second argument");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1308 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1309 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1310 error ("class: expecting structure as first argument");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1311 }
9010
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1312
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1313 return retval;
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1314 }
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1315
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1316 DEFUN (__parent_classes__, args, ,
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1317 "-*- texinfo -*-\n\
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1318 @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
1319 Undocumented internal function.\n\
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1320 @end deftypefn")
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1321 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1322 octave_value retval = Cell ();
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1323
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1324 if (args.length () == 1)
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1325 {
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1326 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
1327
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1328 if (arg.is_object ())
f914834836e7 Partial implementation of derived classes using the old form with "@" files.
rtshort@smoketree.phaselocked.com
parents: 8920
diff changeset
1329 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
1330 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1331 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1332 print_usage ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1333
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1334 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1335 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1336
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1337 DEFUN (isobject, args, ,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1338 "-*- texinfo -*-\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1339 @deftypefn {Built-in Function} {} isobject (@var{x})\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1340 Return true if @var{x} is a class object.\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1341 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1342 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1343 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1344
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1345 if (args.length () == 1)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1346 retval = args(0).is_object ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1347 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1348 print_usage ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1349
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1350 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1351 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1352
8154
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1353 DEFUN (ismethod, args, ,
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1354 "-*- texinfo -*-\n\
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1355 @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
1356 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
1357 is a method of this class.\n\
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1358 @end deftypefn")
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1359 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1360 octave_value retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1361
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1362 if (args.length () == 2)
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1363 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1364 octave_value arg = args(0);
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1365
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1366 std::string class_name;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1367
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1368 if (arg.is_object ())
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1369 class_name = arg.class_name ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1370 else if (arg.is_string ())
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1371 class_name = arg.string_value ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1372 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1373 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
1374
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1375 if (! error_state)
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1376 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1377 std::string method = args(1).string_value ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1378
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1379 if (! error_state)
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1380 {
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1381 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
1382 retval = true;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1383 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1384 retval = false;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1385 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1386 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1387 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1388 else
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1389 print_usage ();
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1390
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1391 return retval;
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1392 }
265a821f6555 Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents: 7972
diff changeset
1393
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8658
diff changeset
1394 DEFUN (methods, args, nargout,
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1395 "-*- texinfo -*-\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1396 @deftypefn {Built-in Function} {} methods (@var{x})\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1397 @deftypefnx {Built-in Function} {} methods (\"classname\")\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1398 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
1399 object @var{x} or the named class.\n\
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1400 @end deftypefn")
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 octave_value retval;
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 if (args.length () == 1)
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 octave_value arg = args(0);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1407
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1408 std::string class_name;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1409
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1410 if (arg.is_object ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1411 class_name = arg.class_name ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1412 else if (arg.is_string ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1413 class_name = arg.string_value ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1414 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1415 error ("methods: expecting object or class name as argument");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1416
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1417 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1418 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1419 string_vector sv = load_path::methods (class_name);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1420
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1421 if (nargout == 0)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1422 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1423 octave_stdout << "Methods for class " << class_name << ":\n\n";
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1424
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1425 sv.list_in_columns (octave_stdout);
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1426
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1427 octave_stdout << std::endl;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1428 }
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 retval = sv;
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 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1433 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1434 print_usage ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1435
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1436 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1437 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1438
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1439 static bool
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1440 is_built_in_class (const std::string& cn)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1441 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1442 static std::set<std::string> built_in_class_names;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1443
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1444 if (built_in_class_names.empty ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1445 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1446 built_in_class_names.insert ("double");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1447 built_in_class_names.insert ("single");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1448 built_in_class_names.insert ("cell");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1449 built_in_class_names.insert ("struct");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1450 built_in_class_names.insert ("logical");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1451 built_in_class_names.insert ("char");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1452 built_in_class_names.insert ("function handle");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1453 built_in_class_names.insert ("int8");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1454 built_in_class_names.insert ("uint8");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1455 built_in_class_names.insert ("int16");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1456 built_in_class_names.insert ("uint16");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1457 built_in_class_names.insert ("int32");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1458 built_in_class_names.insert ("uint32");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1459 built_in_class_names.insert ("int64");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1460 built_in_class_names.insert ("uint64");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1461 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1462
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1463 return 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
1464 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1465
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1466 DEFUN (superiorto, args, ,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1467 "-*- texinfo -*-\n\
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1468 @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
1469 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
1470 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
1471 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
1472 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
1473 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1474 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1475 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1476
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1477 octave_function *fcn = octave_call_stack::caller ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1478
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1479 if (fcn && fcn->is_class_constructor ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1480 {
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1481 for (int i = 0; i < args.length(); i++)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1482 {
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1483 std::string class_name = args(i).string_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1484
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1485 if (! error_state)
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 if (! is_built_in_class (class_name))
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 std::string this_class_name = fcn->name ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1490
7972
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1491 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
1492 class_name))
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1493 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1494 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
1495 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
1496 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1497 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1498 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1499 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1500 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1501 // User defined classes always have higher precedence
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1502 // than built-in classes.
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1503 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1504 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1505 else
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1506 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1507 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
1508 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1509 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1510 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1511 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1512 else
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1513 error ("superiorto: invalid call from outside class constructor");
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1514
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1515 return retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1516 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1517
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1518 DEFUN (inferiorto, args, ,
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1519 "-*- texinfo -*-\n\
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1520 @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
1521 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
1522 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
1523 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
1524 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
1525 @end deftypefn")
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1526 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1527 octave_value retval;
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1528
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1529 octave_function *fcn = octave_call_stack::caller ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1530
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1531 if (fcn && fcn->is_class_constructor ())
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1532 {
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1533 for (int i = 0; i < args.length(); i++)
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1534 {
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1535 std::string class_name = args(i).string_value ();
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1536
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1537 if (! error_state)
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1538 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1539 if (! is_built_in_class (class_name))
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1540 {
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1541 std::string this_class_name = fcn->name ();
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1542
7972
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1543 symbol_table::set_class_relationship (class_name,
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1544 this_class_name);
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1545
5bf4e2c13ed8 make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents: 7960
diff changeset
1546 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
1547 class_name))
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1548 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1549 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
1550 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
1551 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1552 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1553 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1554 else
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1555 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1556 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
1557 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1558 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1559 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1560 else
8219
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1561 {
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1562 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
1563 break;
f8a885ccd5b4 allow multiple args for inferiorto and superiorto
David Bateman <dbateman@free.fr>
parents: 8212
diff changeset
1564 }
7338
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1565 }
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1566 }
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 ("inferiorto: invalid call from outside class constructor");
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 return retval;
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
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 ;;; Local Variables: ***
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1575 ;;; mode: C++ ***
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1576 ;;; End: ***
5215422865e0 [project @ 2007-12-28 22:31:35 by jwe]
jwe
parents:
diff changeset
1577 */