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" |
2979
|
34 #include "oct-lvalue.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 |
2962
|
49 octave_struct::do_struct_elt_index_op (const string& nm, |
|
50 const octave_value_list& idx, |
|
51 bool silent) |
|
52 { |
|
53 // XXX DO_ME XXX |
|
54 } |
|
55 |
|
56 octave_value |
|
57 octave_struct::do_struct_elt_index_op (const string& nm, bool silent) |
2376
|
58 { |
|
59 octave_value retval; |
|
60 |
|
61 Pix idx = map.seek (nm); |
|
62 |
|
63 if (idx) |
|
64 retval = map.contents (idx); |
2420
|
65 else if (! silent) |
2376
|
66 error ("structure has no member `%s'", nm.c_str ()); |
|
67 |
|
68 return retval; |
|
69 } |
|
70 |
2979
|
71 octave_lvalue |
2948
|
72 octave_struct::struct_elt_ref (octave_value *, const string& nm) |
2376
|
73 { |
2979
|
74 return octave_lvalue (&map [nm]); |
2376
|
75 } |
|
76 |
|
77 void |
2901
|
78 octave_struct::print (ostream& os, bool) const |
|
79 { |
|
80 print_raw (os); |
|
81 } |
|
82 |
|
83 void |
|
84 octave_struct::print_raw (ostream& os, bool) const |
2376
|
85 { |
|
86 // XXX FIXME XXX -- would be nice to print the output in some |
|
87 // standard order. Maybe all substructures first, maybe |
|
88 // alphabetize entries, etc. |
|
89 |
2985
|
90 unwind_protect::begin_frame ("octave_struct_print"); |
2376
|
91 |
|
92 unwind_protect_int (Vstruct_levels_to_print); |
|
93 |
|
94 if (Vstruct_levels_to_print-- > 0) |
|
95 { |
2901
|
96 indent (os); |
|
97 os << "{"; |
|
98 newline (os); |
2376
|
99 |
2901
|
100 increment_indent_level (); |
2376
|
101 |
2901
|
102 for (Pix p = map.first (); p; map.next (p)) |
2376
|
103 { |
|
104 string key = map.key (p); |
|
105 octave_value val = map.contents (p); |
|
106 |
2901
|
107 val.print_with_name (os, key); |
2376
|
108 } |
|
109 |
2901
|
110 decrement_indent_level (); |
2376
|
111 |
2901
|
112 indent (os); |
|
113 os << "}"; |
|
114 newline (os); |
2376
|
115 } |
|
116 else |
2901
|
117 { |
|
118 os << " <structure>"; |
|
119 newline (os); |
|
120 } |
2376
|
121 |
2985
|
122 unwind_protect::run_frame ("octave_struct_print"); |
2376
|
123 } |
|
124 |
2901
|
125 bool |
|
126 octave_struct::print_name_tag (ostream& os, const string& name) const |
|
127 { |
|
128 indent (os); |
|
129 os << name << " ="; |
2916
|
130 newline (os); |
2901
|
131 return false; |
|
132 } |
|
133 |
2376
|
134 /* |
|
135 ;;; Local Variables: *** |
|
136 ;;; mode: C++ *** |
|
137 ;;; End: *** |
|
138 */ |