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