Mercurial > octave-nkf
comparison src/pr-output.cc @ 4901:35bfb4e0b96b
[project @ 2004-06-14 18:33:02 by jwe]
author | jwe |
---|---|
date | Mon, 14 Jun 2004 18:33:02 +0000 |
parents | b92d59213e63 |
children | 90f51232d751 |
comparison
equal
deleted
inserted
replaced
4900:cf470c996819 | 4901:35bfb4e0b96b |
---|---|
2085 increment_index (ra_idx, dims, 2); | 2085 increment_index (ra_idx, dims, 2); |
2086 } | 2086 } |
2087 } | 2087 } |
2088 } | 2088 } |
2089 | 2089 |
2090 template <class T> | |
2091 class | |
2092 octave_print_conv | |
2093 { | |
2094 public: | |
2095 typedef T print_conv_type; | |
2096 }; | |
2097 | |
2098 #define PRINT_CONV(T1, T2) \ | |
2099 template <> \ | |
2100 class \ | |
2101 octave_print_conv<T1> \ | |
2102 { \ | |
2103 public: \ | |
2104 typedef T2 print_conv_type; \ | |
2105 } | |
2106 | |
2107 PRINT_CONV (octave_int8, octave_int16); | |
2108 PRINT_CONV (octave_uint8, octave_uint16); | |
2109 | |
2110 #undef PRINT_CONV | |
2111 | |
2112 template <class T> | |
2113 void | |
2114 octave_print_internal (std::ostream& os, const intNDArray<T>& nda, | |
2115 bool pr_as_read_syntax = false, | |
2116 int extra_indent = 0) | |
2117 { | |
2118 // XXX FIXME XXX -- this mostly duplicates the code in the | |
2119 // PRINT_ND_ARRAY macro. | |
2120 | |
2121 if (nda.is_empty ()) | |
2122 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); | |
2123 else if (nda.length () == 1) | |
2124 { | |
2125 os << typename octave_print_conv<T>::print_conv_type (nda(0)); | |
2126 } | |
2127 else | |
2128 { | |
2129 int ndims = nda.ndims (); | |
2130 | |
2131 dim_vector dims = nda.dims (); | |
2132 | |
2133 Array<int> ra_idx (ndims, 0); | |
2134 | |
2135 int m = 1; | |
2136 | |
2137 for (int i = 2; i < ndims; i++) | |
2138 m *= dims(i); | |
2139 | |
2140 int nr = dims(0); | |
2141 int nc = dims(1); | |
2142 | |
2143 for (int i = 0; i < m; i++) | |
2144 { | |
2145 std::string nm = "ans"; | |
2146 | |
2147 if (m > 1) | |
2148 { | |
2149 nm += "(:,:,"; | |
2150 | |
2151 OSSTREAM buf; | |
2152 | |
2153 for (int k = 2; k < ndims; k++) | |
2154 { | |
2155 buf << ra_idx(k) + 1; | |
2156 | |
2157 if (k < ndims - 1) | |
2158 buf << ","; | |
2159 else | |
2160 buf << ")"; | |
2161 } | |
2162 | |
2163 buf << OSSTREAM_ENDS; | |
2164 | |
2165 nm += OSSTREAM_STR (buf); | |
2166 | |
2167 OSSTREAM_FREEZE (buf); | |
2168 } | |
2169 | |
2170 Array<idx_vector> idx (ndims); | |
2171 | |
2172 idx(0) = idx_vector (':'); | |
2173 idx(1) = idx_vector (':'); | |
2174 | |
2175 for (int k = 2; k < ndims; k++) | |
2176 idx(k) = idx_vector (ra_idx(k) + 1); | |
2177 | |
2178 Array2<T> page (nda.index (idx), nr, nc); | |
2179 | |
2180 // XXX FIXME XXX -- need to do some more work to put these | |
2181 // in neatly aligned columns... | |
2182 | |
2183 int n_rows = page.rows (); | |
2184 int n_cols = page.cols (); | |
2185 | |
2186 os << nm << " =\n\n"; | |
2187 | |
2188 for (int ii = 0; ii < n_rows; ii++) | |
2189 { | |
2190 for (int jj = 0; jj < n_cols; jj++) | |
2191 os << " " << typename octave_print_conv<T>::print_conv_type (page(ii,jj)); | |
2192 | |
2193 os << "\n"; | |
2194 } | |
2195 | |
2196 if (i < m - 1) | |
2197 os << "\n"; | |
2198 | |
2199 if (i < m) | |
2200 increment_index (ra_idx, dims, 2); | |
2201 } | |
2202 } | |
2203 } | |
2204 | |
2205 // XXX FIXME XXX -- this is not the right spot for this... | |
2206 | |
2207 template void | |
2208 octave_print_internal (std::ostream&, const intNDArray<octave_int8>&, | |
2209 bool, int); | |
2210 | |
2211 template void | |
2212 octave_print_internal (std::ostream&, const intNDArray<octave_int16>&, | |
2213 bool, int); | |
2214 | |
2215 template void | |
2216 octave_print_internal (std::ostream&, const intNDArray<octave_int32>&, | |
2217 bool, int); | |
2218 | |
2219 template void | |
2220 octave_print_internal (std::ostream&, const intNDArray<octave_int64>&, | |
2221 bool, int); | |
2222 | |
2223 template void | |
2224 octave_print_internal (std::ostream&, const intNDArray<octave_uint8>&, | |
2225 bool, int); | |
2226 | |
2227 template void | |
2228 octave_print_internal (std::ostream&, const intNDArray<octave_uint16>&, | |
2229 bool, int); | |
2230 | |
2231 template void | |
2232 octave_print_internal (std::ostream&, const intNDArray<octave_uint32>&, | |
2233 bool, int); | |
2234 | |
2235 template void | |
2236 octave_print_internal (std::ostream&, const intNDArray<octave_uint64>&, | |
2237 bool, int); | |
2238 | |
2239 template <class T> | |
2240 void | |
2241 octave_print_internal (std::ostream& os, const octave_int<T>& val, | |
2242 bool pr_as_read_syntax) | |
2243 { | |
2244 // XXX FIXME XXX -- we need to handle various formats here... | |
2245 | |
2246 os << typename octave_print_conv<octave_int<T> >::print_conv_type (val); | |
2247 } | |
2248 | |
2249 // XXX FIXME XXX -- this is not the right spot for this... | |
2250 | |
2251 template void | |
2252 octave_print_internal (std::ostream&, const octave_int8&, bool); | |
2253 | |
2254 template void | |
2255 octave_print_internal (std::ostream&, const octave_int16&, bool); | |
2256 | |
2257 template void | |
2258 octave_print_internal (std::ostream&, const octave_int32&, bool); | |
2259 | |
2260 template void | |
2261 octave_print_internal (std::ostream&, const octave_int64&, bool); | |
2262 | |
2263 template void | |
2264 octave_print_internal (std::ostream&, const octave_uint8&, bool); | |
2265 | |
2266 template void | |
2267 octave_print_internal (std::ostream&, const octave_uint16&, bool); | |
2268 | |
2269 template void | |
2270 octave_print_internal (std::ostream&, const octave_uint32&, bool); | |
2271 | |
2272 template void | |
2273 octave_print_internal (std::ostream&, const octave_uint64&, bool); | |
2274 | |
2090 extern void | 2275 extern void |
2091 octave_print_internal (std::ostream&, const Cell&, bool, int, bool) | 2276 octave_print_internal (std::ostream&, const Cell&, bool, int, bool) |
2092 { | 2277 { |
2093 panic_impossible (); | 2278 panic_impossible (); |
2094 } | 2279 } |