| 276 | //============================================================================== |
| 277 | template <typename ElementType> |
| 278 | String Matrix<ElementType>::toString() const |
| 279 | { |
| 280 | StringArray entries; |
| 281 | int sizeMax = 0; |
| 282 | |
| 283 | auto* p = data.begin(); |
| 284 | |
| 285 | for (size_t i = 0; i < rows; ++i) |
| 286 | { |
| 287 | for (size_t j = 0; j < columns; ++j) |
| 288 | { |
| 289 | String entry (*p++, 4); |
| 290 | sizeMax = jmax (sizeMax, entry.length()); |
| 291 | |
| 292 | entries.add (entry); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | sizeMax = ((sizeMax + 1) / 4 + 1) * 4; |
| 297 | |
| 298 | MemoryOutputStream result; |
| 299 | |
| 300 | auto n = static_cast<size_t> (entries.size()); |
| 301 | |
| 302 | for (size_t i = 0; i < n; ++i) |
| 303 | { |
| 304 | result << entries[(int) i].paddedRight (' ', sizeMax); |
| 305 | |
| 306 | if (i % columns == (columns - 1)) |
| 307 | result << newLine; |
| 308 | } |
| 309 | |
| 310 | return result.toString(); |
| 311 | } |
| 312 | |
| 313 | template class Matrix<float>; |
| 314 | template class Matrix<double>; |