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