2376
|
1 /* |
|
2 |
|
3 Copyright (C) 1996 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 |
|
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" |
|
34 #include "ov-struct.h" |
|
35 #include "unwind-prot.h" |
|
36 |
|
37 int octave_struct::t_id = -1; |
|
38 |
|
39 const string octave_struct::t_name ("struct"); |
|
40 |
|
41 |
|
42 octave_value |
2420
|
43 octave_struct::struct_elt_val (const string& nm, bool silent) const |
2376
|
44 { |
|
45 octave_value retval; |
|
46 |
|
47 Pix idx = map.seek (nm); |
|
48 |
|
49 if (idx) |
|
50 retval = map.contents (idx); |
2420
|
51 else if (! silent) |
2376
|
52 error ("structure has no member `%s'", nm.c_str ()); |
|
53 |
|
54 return retval; |
|
55 } |
|
56 |
|
57 octave_value& |
|
58 octave_struct::struct_elt_ref (const string& nm) |
|
59 { |
|
60 return map [nm]; |
|
61 } |
|
62 |
|
63 void |
|
64 octave_struct::print (ostream& os) |
|
65 { |
|
66 // XXX FIXME XXX -- would be nice to print the output in some |
|
67 // standard order. Maybe all substructures first, maybe |
|
68 // alphabetize entries, etc. |
|
69 |
|
70 begin_unwind_frame ("octave_struct_print"); |
|
71 |
|
72 unwind_protect_int (struct_indent); |
|
73 unwind_protect_int (Vstruct_levels_to_print); |
|
74 |
|
75 if (Vstruct_levels_to_print-- > 0) |
|
76 { |
|
77 os.form ("\n%*s{\n", struct_indent, ""); |
|
78 |
|
79 increment_struct_indent (); |
|
80 |
|
81 Pix p = map.first (); |
|
82 |
|
83 while (p) |
|
84 { |
|
85 bool pad_after = false; |
|
86 |
|
87 string key = map.key (p); |
|
88 octave_value val = map.contents (p); |
|
89 |
|
90 map.next (p); |
|
91 |
|
92 os.form ("%*s%s =", struct_indent, "", key.c_str ()); |
|
93 |
|
94 if (val.print_as_scalar ()) |
|
95 os << " "; |
|
96 else if (val.print_as_structure ()) |
|
97 { |
|
98 if (p) |
|
99 pad_after = true; |
|
100 } |
|
101 else |
|
102 { |
|
103 if (p) |
|
104 pad_after = true; |
|
105 |
|
106 os << "\n\n"; |
|
107 } |
|
108 |
|
109 val.print (os); |
|
110 |
|
111 if (pad_after) |
|
112 os << "\n"; |
|
113 } |
|
114 |
|
115 decrement_struct_indent (); |
|
116 |
|
117 os.form ("%*s%s", struct_indent, "", "}\n"); |
|
118 } |
|
119 else |
|
120 os << " <structure>\n"; |
|
121 |
|
122 run_unwind_frame ("octave_struct_print"); |
|
123 } |
|
124 |
|
125 /* |
|
126 ;;; Local Variables: *** |
|
127 ;;; mode: C++ *** |
|
128 ;;; End: *** |
|
129 */ |