2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include <iostream.h> |
|
32 |
|
33 #include "error.h" |
2954
|
34 #include "oct-var-ref.h" |
2376
|
35 #include "ov-struct.h" |
|
36 #include "unwind-prot.h" |
2948
|
37 #include "variables.h" |
2376
|
38 |
2477
|
39 octave_allocator |
|
40 octave_struct::allocator (sizeof (octave_struct)); |
2376
|
41 |
2477
|
42 int |
|
43 octave_struct::t_id (-1); |
2376
|
44 |
2477
|
45 const string |
|
46 octave_struct::t_name ("struct"); |
2376
|
47 |
|
48 octave_value |
2420
|
49 octave_struct::struct_elt_val (const string& nm, bool silent) const |
2376
|
50 { |
|
51 octave_value retval; |
|
52 |
|
53 Pix idx = map.seek (nm); |
|
54 |
|
55 if (idx) |
|
56 retval = map.contents (idx); |
2420
|
57 else if (! silent) |
2376
|
58 error ("structure has no member `%s'", nm.c_str ()); |
|
59 |
|
60 return retval; |
|
61 } |
|
62 |
2948
|
63 octave_variable_reference |
|
64 octave_struct::struct_elt_ref (octave_value *, const string& nm) |
2376
|
65 { |
2948
|
66 return octave_variable_reference (&map [nm]); |
2376
|
67 } |
|
68 |
|
69 void |
2901
|
70 octave_struct::print (ostream& os, bool) const |
|
71 { |
|
72 print_raw (os); |
|
73 } |
|
74 |
|
75 void |
|
76 octave_struct::print_raw (ostream& os, bool) const |
2376
|
77 { |
|
78 // XXX FIXME XXX -- would be nice to print the output in some |
|
79 // standard order. Maybe all substructures first, maybe |
|
80 // alphabetize entries, etc. |
|
81 |
|
82 begin_unwind_frame ("octave_struct_print"); |
|
83 |
|
84 unwind_protect_int (Vstruct_levels_to_print); |
|
85 |
|
86 if (Vstruct_levels_to_print-- > 0) |
|
87 { |
2901
|
88 indent (os); |
|
89 os << "{"; |
|
90 newline (os); |
2376
|
91 |
2901
|
92 increment_indent_level (); |
2376
|
93 |
2901
|
94 for (Pix p = map.first (); p; map.next (p)) |
2376
|
95 { |
|
96 string key = map.key (p); |
|
97 octave_value val = map.contents (p); |
|
98 |
2901
|
99 val.print_with_name (os, key); |
2376
|
100 } |
|
101 |
2901
|
102 decrement_indent_level (); |
2376
|
103 |
2901
|
104 indent (os); |
|
105 os << "}"; |
|
106 newline (os); |
2376
|
107 } |
|
108 else |
2901
|
109 { |
|
110 os << " <structure>"; |
|
111 newline (os); |
|
112 } |
2376
|
113 |
|
114 run_unwind_frame ("octave_struct_print"); |
|
115 } |
|
116 |
2901
|
117 bool |
|
118 octave_struct::print_name_tag (ostream& os, const string& name) const |
|
119 { |
|
120 indent (os); |
|
121 os << name << " ="; |
2916
|
122 newline (os); |
2901
|
123 return false; |
|
124 } |
|
125 |
2376
|
126 /* |
|
127 ;;; Local Variables: *** |
|
128 ;;; mode: C++ *** |
|
129 ;;; End: *** |
|
130 */ |