3353
|
1 /* |
|
2 |
|
3 Copyright (C) 1999 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 #include <strstream.h> |
|
33 |
|
34 #include "lo-utils.h" |
|
35 |
|
36 #include "defun.h" |
|
37 #include "error.h" |
|
38 #include "ov-cell.h" |
|
39 #include "unwind-prot.h" |
|
40 |
|
41 DEFINE_OCTAVE_ALLOCATOR (octave_cell); |
|
42 |
|
43 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cell, "cell"); |
|
44 |
|
45 octave_value |
|
46 octave_cell::do_index_op (const octave_value_list& idx) |
|
47 { |
|
48 octave_value retval; |
|
49 |
|
50 #if 0 |
|
51 if (idx.length () == 1) |
|
52 { |
|
53 idx_vector i = idx (0).index_vector (); |
|
54 |
|
55 retval = octave_value_list (lst.index (i)); |
|
56 } |
|
57 else |
|
58 error ("lists may only be indexed by a single scalar"); |
|
59 #endif |
|
60 |
|
61 return retval; |
|
62 } |
|
63 |
|
64 void |
|
65 octave_cell::assign (const octave_value_list& idx, const octave_value& rhs) |
|
66 { |
|
67 #if 0 |
|
68 if (idx.length () == 1) |
|
69 { |
|
70 int i = idx(0).int_value (true); |
|
71 |
|
72 if (! error_state) |
|
73 { |
|
74 int n = lst.length (); |
|
75 |
|
76 if (i > 0 && (Vresize_on_range_error || i <= n)) |
|
77 lst(i-1) = rhs; |
|
78 else |
|
79 error ("list index = %d out of range", i); |
|
80 } |
|
81 else |
|
82 error ("list index must be an integer"); |
|
83 } |
|
84 else |
|
85 error ("lists may only be indexed by a single scalar"); |
|
86 #endif |
|
87 } |
|
88 |
|
89 void |
|
90 octave_cell::print (ostream& os, bool) const |
|
91 { |
|
92 print_raw (os); |
|
93 } |
|
94 |
|
95 void |
|
96 octave_cell::print_raw (ostream& os, bool) const |
|
97 { |
|
98 unwind_protect::begin_frame ("octave_cell_print"); |
|
99 |
|
100 int nr = cell_val.rows (); |
|
101 int nc = cell_val.columns(); |
|
102 |
|
103 if (nr > 0 && nc > 0) |
|
104 { |
|
105 indent (os); |
|
106 os << "{"; |
|
107 newline (os); |
|
108 |
|
109 increment_indent_level (); |
|
110 |
|
111 for (int j = 0; j < nc; j++) |
|
112 { |
|
113 for (int i = 0; i < nr; i++) |
|
114 { |
|
115 ostrstream buf; |
|
116 buf << "[" << i+1 << "," << j+1 << "]" << ends; |
|
117 const char *nm = buf.str (); |
|
118 |
|
119 octave_value val = cell_val(i,j); |
|
120 |
|
121 val.print_with_name (os, nm); |
|
122 |
|
123 delete [] nm; |
|
124 } |
|
125 } |
|
126 |
|
127 decrement_indent_level (); |
|
128 |
|
129 indent (os); |
|
130 |
|
131 os << "}"; |
|
132 } |
|
133 else |
|
134 os << "{}"; |
|
135 |
|
136 newline (os); |
|
137 |
|
138 unwind_protect::run_frame ("octave_cell_print"); |
|
139 } |
|
140 |
|
141 bool |
|
142 octave_cell::print_name_tag (ostream& os, const string& name) const |
|
143 { |
|
144 indent (os); |
|
145 if (is_empty ()) |
|
146 os << name << " = "; |
|
147 else |
|
148 { |
|
149 os << name << " ="; |
|
150 newline (os); |
|
151 } |
|
152 return false; |
|
153 } |
|
154 |
|
155 /* |
|
156 ;;; Local Variables: *** |
|
157 ;;; mode: C++ *** |
|
158 ;;; End: *** |
|
159 */ |