Mercurial > octave
comparison src/ov-cell.cc @ 3928:e8627dc4bdf2
[project @ 2002-05-03 19:56:01 by jwe]
author | jwe |
---|---|
date | Fri, 03 May 2002 19:56:02 +0000 |
parents | 0ff7323dab8b |
children | f9ea3dcf58ee |
comparison
equal
deleted
inserted
replaced
3927:e7ad1397d67b | 3928:e8627dc4bdf2 |
---|---|
37 #include "error.h" | 37 #include "error.h" |
38 #include "ov-cell.h" | 38 #include "ov-cell.h" |
39 #include "oct-obj.h" | 39 #include "oct-obj.h" |
40 #include "unwind-prot.h" | 40 #include "unwind-prot.h" |
41 #include "utils.h" | 41 #include "utils.h" |
42 #include "ov-base-mat.h" | |
43 #include "ov-base-mat.cc" | |
44 #include "ov-re-mat.h" | |
45 #include "ov-scalar.h" | |
46 | |
47 template class octave_base_matrix<Cell>; | |
42 | 48 |
43 DEFINE_OCTAVE_ALLOCATOR (octave_cell); | 49 DEFINE_OCTAVE_ALLOCATOR (octave_cell); |
44 | 50 |
45 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cell, "cell"); | 51 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_cell, "cell"); |
46 | 52 |
47 octave_value | |
48 octave_cell::do_index_op (const octave_value_list& idx) | |
49 { | |
50 octave_value retval; | |
51 | |
52 int len = idx.length (); | |
53 | |
54 switch (len) | |
55 { | |
56 case 2: | |
57 { | |
58 idx_vector i = idx (0).index_vector (); | |
59 idx_vector j = idx (1).index_vector (); | |
60 | |
61 retval = cell_val.index (i, j); | |
62 } | |
63 break; | |
64 | |
65 case 1: | |
66 { | |
67 idx_vector i = idx (0).index_vector (); | |
68 | |
69 retval = cell_val.index (i); | |
70 } | |
71 break; | |
72 | |
73 default: | |
74 { | |
75 std::string n = type_name (); | |
76 | |
77 error ("invalid number of indices (%d) for %s value", | |
78 len, n.c_str ()); | |
79 } | |
80 break; | |
81 } | |
82 | |
83 return retval; | |
84 } | |
85 | |
86 void | 53 void |
87 octave_cell::assign (const octave_value_list& idx, const octave_value& rhs) | 54 octave_cell::assign (const octave_value_list& idx, const octave_value& rhs) |
88 { | 55 { |
89 #if 0 | 56 if (rhs.is_cell ()) |
90 if (idx.length () == 1) | 57 octave_base_matrix<Cell>::assign (idx, rhs.cell_value ()); |
91 { | |
92 int i = idx(0).int_value (true); | |
93 | |
94 if (! error_state) | |
95 { | |
96 int n = lst.length (); | |
97 | |
98 if (i > 0 && (Vresize_on_range_error || i <= n)) | |
99 lst(i-1) = rhs; | |
100 else | |
101 error ("list index = %d out of range", i); | |
102 } | |
103 else | |
104 error ("list index must be an integer"); | |
105 } | |
106 else | 58 else |
107 error ("lists may only be indexed by a single scalar"); | 59 octave_base_matrix<Cell>::assign (idx, Cell (rhs)); |
108 #endif | |
109 } | |
110 | |
111 void | |
112 octave_cell::print (std::ostream& os, bool) const | |
113 { | |
114 print_raw (os); | |
115 } | |
116 | |
117 void | |
118 octave_cell::print_raw (std::ostream& os, bool) const | |
119 { | |
120 unwind_protect::begin_frame ("octave_cell_print"); | |
121 | |
122 int nr = cell_val.rows (); | |
123 int nc = cell_val.columns(); | |
124 | |
125 if (nr > 0 && nc > 0) | |
126 { | |
127 indent (os); | |
128 os << "{"; | |
129 newline (os); | |
130 | |
131 increment_indent_level (); | |
132 | |
133 for (int j = 0; j < nc; j++) | |
134 { | |
135 for (int i = 0; i < nr; i++) | |
136 { | |
137 std::ostrstream buf; | |
138 buf << "[" << i+1 << "," << j+1 << "]" << std::ends; | |
139 const char *nm = buf.str (); | |
140 | |
141 octave_value val = cell_val(i,j); | |
142 | |
143 val.print_with_name (os, nm); | |
144 | |
145 delete [] nm; | |
146 } | |
147 } | |
148 | |
149 decrement_indent_level (); | |
150 | |
151 indent (os); | |
152 | |
153 os << "}"; | |
154 } | |
155 else | |
156 os << "{}"; | |
157 | |
158 newline (os); | |
159 | |
160 unwind_protect::run_frame ("octave_cell_print"); | |
161 } | |
162 | |
163 bool | |
164 octave_cell::print_name_tag (std::ostream& os, const std::string& name) const | |
165 { | |
166 indent (os); | |
167 if (is_empty ()) | |
168 os << name << " = "; | |
169 else | |
170 { | |
171 os << name << " ="; | |
172 newline (os); | |
173 } | |
174 return false; | |
175 } | 60 } |
176 | 61 |
177 DEFUN (iscell, args, , | 62 DEFUN (iscell, args, , |
178 "-*- texinfo -*-\n\ | 63 "-*- texinfo -*-\n\ |
179 @deftypefn {Built-in Function} {} iscell (@var{x})\n\ | 64 @deftypefn {Built-in Function} {} iscell (@var{x})\n\ |