Mercurial > octave-nkf
annotate src/ov-class.cc @ 8154:265a821f6555
Add subsindex and ismethod functions
author | David Bateman <dbateman@free.fr> |
---|---|
date | Fri, 26 Sep 2008 13:29:29 -0400 |
parents | 5bf4e2c13ed8 |
children | ebf6f6a0f9a7 |
rev | line source |
---|---|
7338 | 1 /* |
2 | |
3 Copyright (C) 2007 John W. Eaton | |
4 | |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7444 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
7338 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7444 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
7338 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <iostream> | |
28 | |
29 #include "Array-util.h" | |
30 #include "byte-swap.h" | |
31 | |
32 #include "Cell.h" | |
33 #include "defun.h" | |
34 #include "error.h" | |
35 #include "gripes.h" | |
36 #include "load-path.h" | |
37 #include "ls-hdf5.h" | |
38 #include "ls-oct-ascii.h" | |
39 #include "ls-oct-binary.h" | |
40 #include "ls-utils.h" | |
41 #include "oct-lvalue.h" | |
42 #include "ov-class.h" | |
43 #include "ov-fcn.h" | |
44 #include "pager.h" | |
45 #include "parse.h" | |
46 #include "pr-output.h" | |
47 #include "toplev.h" | |
48 #include "unwind-prot.h" | |
49 #include "variables.h" | |
50 | |
51 DEFINE_OCTAVE_ALLOCATOR(octave_class); | |
52 | |
53 int octave_class::t_id (-1); | |
54 | |
55 const std::string octave_class::t_name ("class"); | |
56 | |
57 void | |
58 octave_class::register_type (void) | |
59 { | |
60 t_id = octave_value_typeinfo::register_type | |
61 (octave_class::t_name, "<unknown>", octave_value (new octave_class ())); | |
62 } | |
63 | |
64 Cell | |
65 octave_class::dotref (const octave_value_list& idx) | |
66 { | |
67 Cell retval; | |
68 | |
69 assert (idx.length () == 1); | |
70 | |
71 std::string nm = idx(0).string_value (); | |
72 | |
73 Octave_map::const_iterator p = map.seek (nm); | |
74 | |
75 if (p != map.end ()) | |
76 retval = map.contents (p); | |
77 else | |
78 error ("class has no member `%s'", nm.c_str ()); | |
79 | |
80 return retval; | |
81 } | |
82 | |
83 static void | |
84 gripe_invalid_index (void) | |
85 { | |
86 error ("invalid index for class"); | |
87 } | |
88 | |
89 static void | |
90 gripe_invalid_index_for_assignment (void) | |
91 { | |
92 error ("invalid index for class assignment"); | |
93 } | |
94 | |
95 static void | |
96 gripe_invalid_index_type (const std::string& nm, char t) | |
97 { | |
98 error ("%s cannot be indexed with %c", nm.c_str (), t); | |
99 } | |
100 | |
101 static void | |
102 gripe_failed_assignment (void) | |
103 { | |
104 error ("assignment to class element failed"); | |
105 } | |
106 | |
107 static inline octave_value_list | |
108 sanitize (const octave_value_list& ovl) | |
109 { | |
110 octave_value_list retval = ovl; | |
111 | |
112 for (octave_idx_type i = 0; i < ovl.length (); i++) | |
113 { | |
114 if (retval(i).is_magic_colon ()) | |
115 retval(i) = ":"; | |
116 } | |
117 | |
118 return retval; | |
119 } | |
120 | |
121 static inline octave_value | |
122 make_idx_args (const std::string& type, | |
123 const std::list<octave_value_list>& idx, | |
124 const std::string& who) | |
125 { | |
126 octave_value retval; | |
127 | |
128 size_t len = type.length (); | |
129 | |
130 if (len == idx.size ()) | |
131 { | |
132 Cell type_field (len, 1); | |
133 Cell subs_field (len, 1); | |
134 | |
135 std::list<octave_value_list>::const_iterator p = idx.begin (); | |
136 | |
137 for (size_t i = 0; i < len; i++) | |
138 { | |
139 char t = type[i]; | |
140 | |
141 switch (t) | |
142 { | |
143 case '(': | |
144 type_field(i) = "()"; | |
145 subs_field(i) = Cell (sanitize (*p++)); | |
146 break; | |
147 | |
148 case '{': | |
149 type_field(i) = "{}"; | |
150 subs_field(i) = Cell (sanitize (*p++)); | |
151 break; | |
152 | |
153 case '.': | |
154 { | |
155 type_field(i) = "."; | |
156 | |
157 octave_value_list vlist = *p++; | |
158 | |
159 if (vlist.length () == 1) | |
160 { | |
161 octave_value val = vlist(0); | |
162 | |
163 if (val.is_string ()) | |
164 subs_field(i) = val; | |
165 else | |
166 { | |
167 error ("expecting character string argument for `.' index"); | |
168 return retval; | |
169 } | |
170 } | |
171 else | |
172 { | |
173 error ("expecting single argument for `.' index"); | |
174 return retval; | |
175 } | |
176 } | |
177 break; | |
178 | |
179 default: | |
180 panic_impossible (); | |
181 break; | |
182 } | |
183 } | |
184 | |
185 Octave_map m; | |
186 | |
187 m.assign ("type", type_field); | |
188 m.assign ("subs", subs_field); | |
189 | |
190 retval = m; | |
191 } | |
192 else | |
193 error ("invalid index for %s", who.c_str ()); | |
194 | |
195 return retval; | |
196 } | |
197 | |
198 octave_value_list | |
199 octave_class::subsref (const std::string& type, | |
200 const std::list<octave_value_list>& idx, | |
201 int nargout) | |
202 { | |
203 octave_value_list retval; | |
204 | |
205 if (in_class_method ()) | |
206 { | |
207 // FIXME -- this block of code is the same as the body of | |
208 // octave_struct::subsref. Maybe it could be shared instead of | |
209 // duplicated. | |
210 | |
211 int skip = 1; | |
212 | |
213 switch (type[0]) | |
214 { | |
215 case '(': | |
216 { | |
217 if (type.length () > 1 && type[1] == '.') | |
218 { | |
219 std::list<octave_value_list>::const_iterator p = idx.begin (); | |
220 octave_value_list key_idx = *++p; | |
221 | |
222 Cell tmp = dotref (key_idx); | |
223 | |
224 if (! error_state) | |
225 { | |
226 Cell t = tmp.index (idx.front ()); | |
227 | |
228 retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); | |
229 | |
230 // We handled two index elements, so tell | |
231 // next_subsref to skip both of them. | |
232 | |
233 skip++; | |
234 } | |
235 } | |
236 else | |
237 retval(0) = map.index (idx.front ()); | |
238 } | |
239 break; | |
240 | |
241 case '.': | |
242 { | |
243 if (map.numel() > 0) | |
244 { | |
245 Cell t = dotref (idx.front ()); | |
246 | |
247 retval(0) = (t.length () == 1) ? t(0) : octave_value (t, true); | |
248 } | |
249 } | |
250 break; | |
251 | |
252 case '{': | |
253 gripe_invalid_index_type (type_name (), type[0]); | |
254 break; | |
255 | |
256 default: | |
257 panic_impossible (); | |
258 } | |
259 | |
260 // FIXME -- perhaps there should be an | |
261 // octave_value_list::next_subsref member function? See also | |
262 // octave_user_function::subsref. | |
263 | |
264 if (idx.size () > 1) | |
265 retval = retval(0).next_subsref (nargout, type, idx, skip); | |
266 } | |
267 else | |
268 { | |
269 octave_value meth = symbol_table::find_method ("subsref", class_name ()); | |
270 | |
271 if (meth.is_defined ()) | |
272 { | |
273 octave_value_list args; | |
274 | |
275 args(1) = make_idx_args (type, idx, "subsref"); | |
276 | |
277 if (error_state) | |
278 return octave_value_list (); | |
279 | |
280 count++; | |
281 args(0) = octave_value (this); | |
282 | |
283 return feval (meth.function_value (), args, nargout); | |
284 } | |
285 else | |
286 { | |
287 if (type.length () == 1 && type[0] == '(') | |
288 retval(0) = octave_value (map.index (idx.front ()), class_name ()); | |
289 else | |
290 gripe_invalid_index (); | |
291 } | |
292 } | |
293 | |
294 return retval; | |
295 } | |
296 | |
297 octave_value | |
298 octave_class::numeric_conv (const Cell& val, const std::string& type) | |
299 { | |
300 octave_value retval; | |
301 | |
302 if (val.length () == 1) | |
303 { | |
304 retval = val(0); | |
305 | |
306 if (type.length () > 0 && type[0] == '.' && ! retval.is_map ()) | |
307 retval = Octave_map (); | |
308 } | |
309 else | |
310 gripe_invalid_index_for_assignment (); | |
311 | |
312 return retval; | |
313 } | |
314 | |
315 octave_value | |
316 octave_class::subsasgn (const std::string& type, | |
317 const std::list<octave_value_list>& idx, | |
318 const octave_value& rhs) | |
319 { | |
320 octave_value retval; | |
321 | |
7960
22a18f206121
octave_class::subsasgn: only do internal magic if RHS is not an octave_class object
John W. Eaton <jwe@octave.org>
parents:
7444
diff
changeset
|
322 if (in_class_method () && ! rhs.is_object ()) |
7338 | 323 { |
324 // FIXME -- this block of code is the same as the body of | |
325 // octave_struct::subsasgn. Maybe it could be shared instead of | |
326 // duplicated. | |
327 | |
328 int n = type.length (); | |
329 | |
330 octave_value t_rhs = rhs; | |
331 | |
332 if (n > 1 && ! (type.length () == 2 && type[0] == '(' && type[1] == '.')) | |
333 { | |
334 switch (type[0]) | |
335 { | |
336 case '(': | |
337 { | |
338 if (type.length () > 1 && type[1] == '.') | |
339 { | |
340 std::list<octave_value_list>::const_iterator p = idx.begin (); | |
341 octave_value_list t_idx = *p; | |
342 | |
343 octave_value_list key_idx = *++p; | |
344 | |
345 assert (key_idx.length () == 1); | |
346 | |
347 std::string key = key_idx(0).string_value (); | |
348 | |
349 octave_value u; | |
350 | |
351 if (! map.contains (key)) | |
352 u = octave_value::empty_conv (type.substr (2), rhs); | |
353 else | |
354 { | |
355 Cell map_val = map.contents (key); | |
356 | |
357 Cell map_elt = map_val.index (idx.front (), true); | |
358 | |
359 u = numeric_conv (map_elt, type.substr (2)); | |
360 } | |
361 | |
362 if (! error_state) | |
363 { | |
364 std::list<octave_value_list> next_idx (idx); | |
365 | |
366 // We handled two index elements, so subsasgn to | |
367 // needs to skip both of them. | |
368 | |
369 next_idx.erase (next_idx.begin ()); | |
370 next_idx.erase (next_idx.begin ()); | |
371 | |
372 u.make_unique (); | |
373 | |
374 t_rhs = u.subsasgn (type.substr (2), next_idx, rhs); | |
375 } | |
376 } | |
377 else | |
378 gripe_invalid_index_for_assignment (); | |
379 } | |
380 break; | |
381 | |
382 case '.': | |
383 { | |
384 octave_value_list key_idx = idx.front (); | |
385 | |
386 assert (key_idx.length () == 1); | |
387 | |
388 std::string key = key_idx(0).string_value (); | |
389 | |
390 octave_value u; | |
391 | |
392 if (! map.contains (key)) | |
393 u = octave_value::empty_conv (type.substr (1), rhs); | |
394 else | |
395 { | |
396 Cell map_val = map.contents (key); | |
397 | |
398 u = numeric_conv (map_val, type.substr (1)); | |
399 } | |
400 | |
401 if (! error_state) | |
402 { | |
403 std::list<octave_value_list> next_idx (idx); | |
404 | |
405 next_idx.erase (next_idx.begin ()); | |
406 | |
407 u.make_unique (); | |
408 | |
409 t_rhs = u.subsasgn (type.substr (1), next_idx, rhs); | |
410 } | |
411 } | |
412 break; | |
413 | |
414 case '{': | |
415 gripe_invalid_index_type (type_name (), type[0]); | |
416 break; | |
417 | |
418 default: | |
419 panic_impossible (); | |
420 } | |
421 } | |
422 | |
423 if (! error_state) | |
424 { | |
425 switch (type[0]) | |
426 { | |
427 case '(': | |
428 { | |
429 if (n > 1 && type[1] == '.') | |
430 { | |
431 std::list<octave_value_list>::const_iterator p = idx.begin (); | |
432 octave_value_list key_idx = *++p; | |
433 | |
434 assert (key_idx.length () == 1); | |
435 | |
436 std::string key = key_idx(0).string_value (); | |
437 | |
438 if (! error_state) | |
439 { | |
440 map.assign (idx.front (), key, t_rhs); | |
441 | |
442 if (! error_state) | |
443 { | |
444 count++; | |
445 retval = octave_value (this); | |
446 } | |
447 else | |
448 gripe_failed_assignment (); | |
449 } | |
450 else | |
451 gripe_failed_assignment (); | |
452 } | |
453 else | |
454 { | |
455 if (t_rhs.is_map()) | |
456 { | |
457 Octave_map rhs_map = t_rhs.map_value (); | |
458 | |
459 if (! error_state) | |
460 { | |
461 map.assign (idx.front (), rhs_map); | |
462 | |
463 if (! error_state) | |
464 { | |
465 count++; | |
466 retval = octave_value (this); | |
467 } | |
468 else | |
469 gripe_failed_assignment (); | |
470 } | |
471 else | |
472 error ("invalid class assignment"); | |
473 } | |
474 else | |
475 { | |
476 if (t_rhs.is_empty()) | |
477 { | |
478 map.maybe_delete_elements (idx.front()); | |
479 | |
480 if (! error_state) | |
481 { | |
482 count++; | |
483 retval = octave_value (this); | |
484 } | |
485 else | |
486 gripe_failed_assignment (); | |
487 } | |
488 else | |
489 error ("invalid class assignment"); | |
490 } | |
491 } | |
492 } | |
493 break; | |
494 | |
495 case '.': | |
496 { | |
497 octave_value_list key_idx = idx.front (); | |
498 | |
499 assert (key_idx.length () == 1); | |
500 | |
501 std::string key = key_idx(0).string_value (); | |
502 | |
503 map.assign (key, t_rhs); | |
504 | |
505 if (! error_state) | |
506 { | |
507 count++; | |
508 retval = octave_value (this); | |
509 } | |
510 else | |
511 gripe_failed_assignment (); | |
512 } | |
513 break; | |
514 | |
515 case '{': | |
516 gripe_invalid_index_type (type_name (), type[0]); | |
517 break; | |
518 | |
519 default: | |
520 panic_impossible (); | |
521 } | |
522 } | |
523 else | |
524 gripe_failed_assignment (); | |
525 } | |
526 else | |
527 { | |
528 octave_value meth = symbol_table::find_method ("subsasgn", class_name ()); | |
529 | |
530 if (meth.is_defined ()) | |
531 { | |
532 octave_value_list args; | |
533 | |
534 args(2) = rhs; | |
535 | |
536 args(1) = make_idx_args (type, idx, "subsasgn"); | |
537 | |
538 if (error_state) | |
539 return octave_value_list (); | |
540 | |
541 count++; | |
542 args(0) = octave_value (this); | |
543 | |
544 octave_value_list tmp = feval (meth.function_value (), args); | |
545 | |
546 // FIXME -- should the subsasgn method be able to return | |
547 // more than one value? | |
548 | |
549 if (tmp.length () > 1) | |
550 error ("expecting single return value from @%s/subsasgn", | |
551 class_name().c_str ()); | |
552 else | |
553 retval = tmp(0); | |
554 | |
555 } | |
556 else | |
557 error ("no subsasgn method defined for class %s", | |
558 class_name().c_str ()); | |
559 } | |
560 | |
561 return retval; | |
562 } | |
563 | |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
564 idx_vector |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
565 octave_class::index_vector (void) const |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
566 { |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
567 idx_vector retval; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
568 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
569 octave_value meth = symbol_table::find_method ("subsindex", class_name ()); |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
570 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
571 if (meth.is_defined ()) |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
572 { |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
573 octave_value_list args; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
574 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
|
575 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
576 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
|
577 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
578 if (!error_state && tmp.length () >= 1) |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
579 { |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
580 if (tmp(0).is_object()) |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
581 error ("subsindex function must return a valid index vector"); |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
582 else |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
583 // Index vector returned by subsindex is zero based |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
584 // (why this inconsistency Mathworks?), and so we must |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
585 // 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
|
586 // expects it to be one based. |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
587 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
|
588 octave_value (1.0)).index_vector (); |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
589 } |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
590 } |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
591 else |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
592 error ("no subsindex method defined for class %s", |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
593 class_name().c_str ()); |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
594 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
595 return retval; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
596 } |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
597 |
7338 | 598 size_t |
599 octave_class::byte_size (void) const | |
600 { | |
601 // Neglect the size of the fieldnames. | |
602 | |
603 size_t retval = 0; | |
604 | |
605 for (Octave_map::const_iterator p = map.begin (); p != map.end (); p++) | |
606 { | |
607 std::string key = map.key (p); | |
608 | |
609 octave_value val = octave_value (map.contents (p)); | |
610 | |
611 retval += val.byte_size (); | |
612 } | |
613 | |
614 return retval; | |
615 } | |
616 | |
617 Octave_map | |
618 octave_class::map_value (void) const | |
619 { | |
620 Octave_map retval; | |
621 gripe_wrong_type_arg ("octave_class::map_value()", type_name ()); | |
622 return retval; | |
623 } | |
624 | |
625 string_vector | |
626 octave_class::map_keys (void) const | |
627 { | |
628 string_vector retval; | |
629 gripe_wrong_type_arg ("octave_class::map_keys()", type_name ()); | |
630 return retval; | |
631 } | |
632 | |
633 void | |
634 octave_class::print (std::ostream& os, bool) const | |
635 { | |
636 print_raw (os); | |
637 } | |
638 | |
639 void | |
640 octave_class::print_raw (std::ostream& os, bool) const | |
641 { | |
642 unwind_protect::begin_frame ("octave_class_print"); | |
643 | |
644 unwind_protect_int (Vstruct_levels_to_print); | |
645 | |
646 indent (os); | |
647 os << " <class " << class_name () << ">"; | |
648 newline (os); | |
649 | |
650 unwind_protect::run_frame ("octave_class_print"); | |
651 } | |
652 | |
653 bool | |
654 octave_class::print_name_tag (std::ostream& os, const std::string& name) const | |
655 { | |
656 bool retval = false; | |
657 | |
658 indent (os); | |
659 os << name << " ="; | |
660 newline (os); | |
661 newline (os); | |
662 | |
663 return retval; | |
664 } | |
665 | |
666 void | |
667 octave_class::print_with_name (std::ostream&, const std::string& name, | |
668 bool) const | |
669 { | |
670 if (! (evaluating_function_body && Vsilent_functions)) | |
671 { | |
672 octave_value fcn = symbol_table::find_method ("display", class_name ()); | |
673 | |
674 if (fcn.is_defined ()) | |
675 { | |
676 octave_value_list args; | |
677 | |
678 args(0) = octave_value (clone (), 1); | |
679 | |
680 string_vector arg_names (1); | |
681 | |
682 arg_names[0] = name; | |
683 | |
684 args.stash_name_tags (arg_names); | |
685 | |
686 feval (fcn.function_value (), args); | |
687 } | |
688 } | |
689 } | |
690 | |
691 bool | |
692 octave_class::save_ascii (std::ostream&, bool&) | |
693 { | |
694 gripe_wrong_type_arg ("octave_class::save_ascii()", type_name ()); | |
695 return false; | |
696 } | |
697 | |
698 bool | |
699 octave_class::load_ascii (std::istream&) | |
700 { | |
701 gripe_wrong_type_arg ("octave_class::load_ascii()", type_name ()); | |
702 return false; | |
703 } | |
704 | |
705 bool | |
706 octave_class::save_binary (std::ostream&, bool&) | |
707 { | |
708 gripe_wrong_type_arg ("octave_class::save_binary()", type_name ()); | |
709 return false; | |
710 } | |
711 | |
712 bool | |
713 octave_class::load_binary (std::istream&, bool, | |
714 oct_mach_info::float_format) | |
715 { | |
716 gripe_wrong_type_arg ("octave_class::load_binary()", type_name ()); | |
717 return false; | |
718 } | |
719 | |
720 #if defined (HAVE_HDF5) | |
721 | |
722 bool | |
723 octave_class::save_hdf5 (hid_t, const char *, bool) | |
724 { | |
725 gripe_wrong_type_arg ("octave_class::save_binary()", type_name ()); | |
726 | |
727 return false; | |
728 } | |
729 | |
730 bool | |
731 octave_class::load_hdf5 (hid_t, const char *, bool) | |
732 { | |
733 gripe_wrong_type_arg ("octave_class::load_binary()", type_name ()); | |
734 | |
735 return false; | |
736 } | |
737 | |
738 #endif | |
739 | |
740 #if 0 | |
741 bool | |
742 octave_class::save_ascii (std::ostream& os, bool& infnan_warned) | |
743 { | |
744 Octave_map m = map_value (); | |
745 os << "# length: " << m.length () << "\n"; | |
746 | |
747 Octave_map::iterator i = m.begin (); | |
748 while (i != m.end ()) | |
749 { | |
750 octave_value val = map.contents (i); | |
751 | |
752 bool b = save_ascii_data (os, val, m.key (i), infnan_warned, false, 0); | |
753 | |
754 if (! b) | |
755 return os; | |
756 | |
757 i++; | |
758 } | |
759 | |
760 return true; | |
761 } | |
762 | |
763 bool | |
764 octave_class::load_ascii (std::istream& is) | |
765 { | |
766 octave_idx_type len = 0; | |
767 bool success = true; | |
768 | |
769 if (extract_keyword (is, "length", len) && len >= 0) | |
770 { | |
771 if (len > 0) | |
772 { | |
773 Octave_map m (map); | |
774 | |
775 for (octave_idx_type j = 0; j < len; j++) | |
776 { | |
777 octave_value t2; | |
778 bool dummy; | |
779 | |
780 // recurse to read cell elements | |
781 std::string nm | |
782 = read_ascii_data (is, std::string (), dummy, t2, j); | |
783 | |
784 if (!is) | |
785 break; | |
786 | |
787 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); | |
788 | |
789 if (error_state) | |
790 { | |
791 error ("load: internal error loading class elements"); | |
792 return false; | |
793 } | |
794 | |
795 m.assign (nm, tcell); | |
796 } | |
797 | |
798 if (is) | |
799 map = m; | |
800 else | |
801 { | |
802 error ("load: failed to load class"); | |
803 success = false; | |
804 } | |
805 } | |
806 else if (len == 0 ) | |
807 map = Octave_map (dim_vector (1, 1)); | |
808 else | |
809 panic_impossible (); | |
810 } | |
811 else { | |
812 error ("load: failed to extract number of elements in class"); | |
813 success = false; | |
814 } | |
815 | |
816 return success; | |
817 } | |
818 | |
819 bool | |
820 octave_class::save_binary (std::ostream& os, bool& save_as_floats) | |
821 { | |
822 Octave_map m = map_value (); | |
823 | |
824 int32_t len = m.length(); | |
825 os.write (reinterpret_cast<char *> (&len), 4); | |
826 | |
827 Octave_map::iterator i = m.begin (); | |
828 while (i != m.end ()) | |
829 { | |
830 octave_value val = map.contents (i); | |
831 | |
832 bool b = save_binary_data (os, val, m.key (i), "", 0, save_as_floats); | |
833 | |
834 if (! b) | |
835 return os; | |
836 | |
837 i++; | |
838 } | |
839 | |
840 return true; | |
841 } | |
842 | |
843 bool | |
844 octave_class::load_binary (std::istream& is, bool swap, | |
845 oct_mach_info::float_format fmt) | |
846 { | |
847 bool success = true; | |
848 int32_t len; | |
849 if (! is.read (reinterpret_cast<char *> (&len), 4)) | |
850 return false; | |
851 if (swap) | |
852 swap_bytes<4> (&len); | |
853 | |
854 if (len > 0) | |
855 { | |
856 Octave_map m (map); | |
857 | |
858 for (octave_idx_type j = 0; j < len; j++) | |
859 { | |
860 octave_value t2; | |
861 bool dummy; | |
862 std::string doc; | |
863 | |
864 // recurse to read cell elements | |
865 std::string nm = read_binary_data (is, swap, fmt, std::string (), | |
866 dummy, t2, doc); | |
867 | |
868 if (!is) | |
869 break; | |
870 | |
871 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); | |
872 | |
873 if (error_state) | |
874 { | |
875 error ("load: internal error loading class elements"); | |
876 return false; | |
877 } | |
878 | |
879 m.assign (nm, tcell); | |
880 } | |
881 | |
882 if (is) | |
883 map = m; | |
884 else | |
885 { | |
886 error ("load: failed to load class"); | |
887 success = false; | |
888 } | |
889 } | |
890 else if (len == 0 ) | |
891 map = Octave_map (dim_vector (1, 1)); | |
892 else | |
893 panic_impossible (); | |
894 | |
895 return success; | |
896 } | |
897 | |
898 #if defined (HAVE_HDF5) | |
899 | |
900 bool | |
901 octave_class::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) | |
902 { | |
903 hid_t data_hid = -1; | |
904 | |
905 data_hid = H5Gcreate (loc_id, name, 0); | |
906 if (data_hid < 0) return false; | |
907 | |
908 // recursively add each element of the class to this group | |
909 Octave_map m = map_value (); | |
910 Octave_map::iterator i = m.begin (); | |
911 while (i != m.end ()) | |
912 { | |
913 octave_value val = map.contents (i); | |
914 | |
915 bool retval2 = add_hdf5_data (data_hid, val, m.key (i), "", false, | |
916 save_as_floats); | |
917 | |
918 if (! retval2) | |
919 break; | |
920 | |
921 i++; | |
922 } | |
923 | |
924 H5Gclose (data_hid); | |
925 | |
926 return true; | |
927 } | |
928 | |
929 bool | |
930 octave_class::load_hdf5 (hid_t loc_id, const char *name, | |
931 bool have_h5giterate_bug) | |
932 { | |
933 bool retval = false; | |
934 | |
935 hdf5_callback_data dsub; | |
936 | |
937 herr_t retval2 = 0; | |
938 Octave_map m (dim_vector (1, 1)); | |
939 int current_item = 0; | |
940 #ifdef HAVE_H5GGET_NUM_OBJS | |
941 hsize_t num_obj = 0; | |
942 hid_t group_id = H5Gopen (loc_id, name); | |
943 H5Gget_num_objs (group_id, &num_obj); | |
944 H5Gclose (group_id); | |
945 | |
946 while (current_item < static_cast<int> (num_obj) | |
947 && (retval2 = H5Giterate (loc_id, name, ¤t_item, | |
948 hdf5_read_next_data, &dsub)) > 0) | |
949 #else | |
950 while ((retval2 = H5Giterate (loc_id, name, ¤t_item, | |
951 hdf5_read_next_data, &dsub)) > 0) | |
952 #endif | |
953 { | |
954 octave_value t2 = dsub.tc; | |
955 | |
956 Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2); | |
957 | |
958 if (error_state) | |
959 { | |
960 error ("load: internal error loading class elements"); | |
961 return false; | |
962 } | |
963 | |
964 m.assign (dsub.name, tcell); | |
965 | |
966 if (have_h5giterate_bug) | |
967 current_item++; // H5Giterate returned the last index processed | |
968 } | |
969 | |
970 if (retval2 >= 0) | |
971 { | |
972 map = m; | |
973 retval = true; | |
974 } | |
975 | |
976 return retval; | |
977 } | |
978 | |
979 #endif | |
980 | |
981 #endif | |
982 | |
983 mxArray * | |
984 octave_class::as_mxArray (void) const | |
985 { | |
986 gripe_wrong_type_arg ("octave_class::as_mxArray ()", type_name ()); | |
987 | |
988 return 0; | |
989 } | |
990 | |
991 bool | |
992 octave_class::in_class_method (void) const | |
993 { | |
994 octave_function *fcn = octave_call_stack::current (); | |
995 | |
996 return (fcn | |
997 && (fcn->is_class_method () || fcn->is_class_constructor ()) | |
998 && fcn->dispatch_class () == class_name ()); | |
999 } | |
1000 | |
1001 DEFUN (class, args, , | |
1002 "-*- texinfo -*-\n\ | |
1003 @deftypefn {Built-in Function} {} class (@var{expr})\n\ | |
1004 @deftypefnx {Built-in Function} {} class (@var{s}, @var{id})\n\ | |
1005 \n\ | |
1006 Return the class of the expression @var{expr}, as a string or\n\ | |
1007 create a class object from the structure @var{s} with name @var{id}.\n\ | |
1008 @end deftypefn") | |
1009 { | |
1010 octave_value retval; | |
1011 | |
1012 int nargin = args.length (); | |
1013 | |
1014 if (nargin == 1) | |
1015 retval = args(0).class_name (); | |
1016 else if (nargin == 2) | |
1017 { | |
1018 Octave_map m = args(0).map_value (); | |
1019 | |
1020 if (! error_state) | |
1021 { | |
1022 std::string id = args(1).string_value (); | |
1023 | |
1024 if (! error_state) | |
1025 { | |
1026 octave_function *fcn = octave_call_stack::caller (); | |
1027 | |
1028 if (fcn && fcn->is_class_constructor ()) | |
1029 retval = octave_value (new octave_class (m, id)); | |
1030 else | |
1031 error ("class: invalid call from outside class constructor"); | |
1032 } | |
1033 else | |
1034 error ("class: expecting character string as second argument"); | |
1035 } | |
1036 else | |
1037 error ("class: expecting structure as first argument"); | |
1038 } | |
1039 else | |
1040 print_usage (); | |
1041 | |
1042 return retval; | |
1043 } | |
1044 | |
1045 | |
1046 DEFUN (isobject, args, , | |
1047 "-*- texinfo -*-\n\ | |
1048 @deftypefn {Built-in Function} {} isobject (@var{x})\n\ | |
1049 Return true if @var{x} is a class object.\n\ | |
1050 @end deftypefn") | |
1051 { | |
1052 octave_value retval; | |
1053 | |
1054 if (args.length () == 1) | |
1055 retval = args(0).is_object (); | |
1056 else | |
1057 print_usage (); | |
1058 | |
1059 return retval; | |
1060 } | |
1061 | |
8154
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1062 DEFUN (ismethod, args, , |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1063 "-*- texinfo -*-\n\ |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1064 @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
|
1065 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
|
1066 is a method of this class.\n\ |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1067 @end deftypefn") |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1068 { |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1069 octave_value retval; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1070 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1071 if (args.length () == 2) |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1072 { |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1073 octave_value arg = args(0); |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1074 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1075 std::string class_name; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1076 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1077 if (arg.is_object ()) |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1078 class_name = arg.class_name (); |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1079 else if (arg.is_string ()) |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1080 class_name = arg.string_value (); |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1081 else |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1082 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
|
1083 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1084 if (! error_state) |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1085 { |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1086 std::string method = args(1).string_value (); |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1087 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1088 if (! error_state) |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1089 { |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1090 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
|
1091 retval = true; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1092 else |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1093 retval = false; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1094 } |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1095 } |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1096 } |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1097 else |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1098 print_usage (); |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1099 |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1100 return retval; |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1101 } |
265a821f6555
Add subsindex and ismethod functions
David Bateman <dbateman@free.fr>
parents:
7972
diff
changeset
|
1102 |
7338 | 1103 DEFCMD (methods, args, nargout, |
1104 "-*- texinfo -*-\n\ | |
1105 @deftypefn {Built-in Function} {} methods (@var{x})\n\ | |
1106 @deftypefnx {Built-in Function} {} methods (\"classname\")\n\ | |
1107 Return a cell array containing the names of the methods for the\n\ | |
1108 object @var{x} or the named class.\n\ | |
1109 @end deftypefn") | |
1110 { | |
1111 octave_value retval; | |
1112 | |
1113 if (args.length () == 1) | |
1114 { | |
1115 octave_value arg = args(0); | |
1116 | |
1117 std::string class_name; | |
1118 | |
1119 if (arg.is_object ()) | |
1120 class_name = arg.class_name (); | |
1121 else if (arg.is_string ()) | |
1122 class_name = arg.string_value (); | |
1123 else | |
1124 error ("methods: expecting object or class name as argument"); | |
1125 | |
1126 if (! error_state) | |
1127 { | |
1128 string_vector sv = load_path::methods (class_name); | |
1129 | |
1130 if (nargout == 0) | |
1131 { | |
1132 octave_stdout << "Methods for class " << class_name << ":\n\n"; | |
1133 | |
1134 sv.list_in_columns (octave_stdout); | |
1135 | |
1136 octave_stdout << std::endl; | |
1137 } | |
1138 else | |
1139 retval = sv; | |
1140 } | |
1141 } | |
1142 else | |
1143 print_usage (); | |
1144 | |
1145 return retval; | |
1146 } | |
1147 | |
1148 static bool | |
1149 is_built_in_class (const std::string& cn) | |
1150 { | |
1151 static std::set<std::string> built_in_class_names; | |
1152 | |
1153 if (built_in_class_names.empty ()) | |
1154 { | |
1155 built_in_class_names.insert ("double"); | |
1156 built_in_class_names.insert ("single"); | |
1157 built_in_class_names.insert ("cell"); | |
1158 built_in_class_names.insert ("struct"); | |
1159 built_in_class_names.insert ("logical"); | |
1160 built_in_class_names.insert ("char"); | |
1161 built_in_class_names.insert ("function handle"); | |
1162 built_in_class_names.insert ("int8"); | |
1163 built_in_class_names.insert ("uint8"); | |
1164 built_in_class_names.insert ("int16"); | |
1165 built_in_class_names.insert ("uint16"); | |
1166 built_in_class_names.insert ("int32"); | |
1167 built_in_class_names.insert ("uint32"); | |
1168 built_in_class_names.insert ("int64"); | |
1169 built_in_class_names.insert ("uint64"); | |
1170 } | |
1171 | |
1172 return built_in_class_names.find (cn) != built_in_class_names.end (); | |
1173 } | |
1174 | |
1175 DEFUN (superiorto, args, , | |
1176 "-*- texinfo -*-\n\ | |
1177 @deftypefn {Built-in Function} {} superiorto (@var{class_name})\n\ | |
1178 When called from a class constructor, mark the object currently\n\ | |
1179 constructed as having a higher precedence than @var{class_name}.\n\ | |
1180 This function may only be called from a class constructor.\n\ | |
1181 @end deftypefn") | |
1182 { | |
1183 octave_value retval; | |
1184 | |
1185 octave_function *fcn = octave_call_stack::caller (); | |
1186 | |
1187 if (fcn && fcn->is_class_constructor ()) | |
1188 { | |
1189 if (args.length () == 1) | |
1190 { | |
1191 std::string class_name = args(0).string_value (); | |
1192 | |
1193 if (! error_state) | |
1194 { | |
1195 if (! is_built_in_class (class_name)) | |
1196 { | |
1197 std::string this_class_name = fcn->name (); | |
1198 | |
7972
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7960
diff
changeset
|
1199 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
|
1200 class_name)) |
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7960
diff
changeset
|
1201 error ("superiorto: precedence already set for %s and %s", |
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7960
diff
changeset
|
1202 this_class_name.c_str (), class_name.c_str ()); |
7338 | 1203 } |
1204 else | |
1205 { | |
1206 // User defined classes always have higher precedence | |
1207 // than built-in classes. | |
1208 } | |
1209 } | |
1210 else | |
1211 error ("superiorto: expecting argument to be class name"); | |
1212 } | |
1213 else | |
1214 print_usage (); | |
1215 } | |
1216 else | |
1217 error ("superiorto: invalid call from outside class constructor"); | |
1218 | |
1219 return retval; | |
1220 } | |
1221 | |
1222 DEFUN (inferiorto, args, , | |
1223 "-*- texinfo -*-\n\ | |
1224 @deftypefn {Built-in Function} {} inferiorto (@var{class_name})\n\ | |
1225 When called from a class constructor, mark the object currently\n\ | |
1226 constructed as having a lower precedence than @var{class_name}.\n\ | |
1227 This function may only be called from a class constructor.\n\ | |
1228 @end deftypefn") | |
1229 { | |
1230 octave_value retval; | |
1231 | |
1232 octave_function *fcn = octave_call_stack::caller (); | |
1233 | |
1234 if (fcn && fcn->is_class_constructor ()) | |
1235 { | |
1236 if (args.length () == 1) | |
1237 { | |
1238 std::string class_name = args(0).string_value (); | |
1239 | |
1240 if (! error_state) | |
1241 { | |
1242 if (! is_built_in_class (class_name)) | |
1243 { | |
1244 std::string this_class_name = fcn->name (); | |
1245 | |
7972
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7960
diff
changeset
|
1246 symbol_table::set_class_relationship (class_name, |
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7960
diff
changeset
|
1247 this_class_name); |
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7960
diff
changeset
|
1248 |
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7960
diff
changeset
|
1249 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
|
1250 class_name)) |
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7960
diff
changeset
|
1251 error ("inferiorto: precedence already set for %s and %s", |
5bf4e2c13ed8
make superiorto and inferiorto work
John W. Eaton <jwe@octave.org>
parents:
7960
diff
changeset
|
1252 this_class_name.c_str (), class_name.c_str ()); |
7338 | 1253 } |
1254 else | |
1255 error ("inferiorto: cannot give user-defined class lower precedence than built-in class"); | |
1256 } | |
1257 else | |
1258 error ("inferiorto: expecting argument to be class name"); | |
1259 } | |
1260 else | |
1261 print_usage (); | |
1262 } | |
1263 else | |
1264 error ("inferiorto: invalid call from outside class constructor"); | |
1265 | |
1266 return retval; | |
1267 } | |
1268 | |
1269 /* | |
1270 ;;; Local Variables: *** | |
1271 ;;; mode: C++ *** | |
1272 ;;; End: *** | |
1273 */ |