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