| 253 | |
| 254 | template <typename ValueT> |
| 255 | vtkSparseArray<ValueT>* ReadSparseArrayAscii(istream& stream) |
| 256 | { |
| 257 | // Create the array ... |
| 258 | vtkSmartPointer<vtkSparseArray<ValueT>> array = vtkSmartPointer<vtkSparseArray<ValueT>>::New(); |
| 259 | |
| 260 | // Read the stream header ... |
| 261 | vtkArrayExtents extents; |
| 262 | vtkArrayExtents::SizeT non_null_size = 0; |
| 263 | ReadHeader(stream, extents, non_null_size, array); |
| 264 | |
| 265 | if (non_null_size > extents.GetSize()) |
| 266 | throw std::runtime_error("Too many values for a sparse array."); |
| 267 | |
| 268 | // Read the array nullptr value ... |
| 269 | std::string line_buffer; |
| 270 | std::getline(stream, line_buffer); |
| 271 | if (!stream) |
| 272 | throw std::runtime_error("Premature end-of-stream reading nullptr value."); |
| 273 | |
| 274 | std::istringstream line_stream(line_buffer); |
| 275 | ValueT null_value; |
| 276 | ExtractValue(line_stream, null_value); |
| 277 | if (!line_stream) |
| 278 | throw std::runtime_error("Missing nullptr value."); |
| 279 | array->SetNullValue(null_value); |
| 280 | |
| 281 | // Setup storage for the stream contents ... |
| 282 | array->ReserveStorage(non_null_size); |
| 283 | std::vector<vtkArray::CoordinateT*> coordinates(array->GetDimensions()); |
| 284 | for (vtkArray::DimensionT j = 0; j != array->GetDimensions(); ++j) |
| 285 | coordinates[j] = array->GetCoordinateStorage(j); |
| 286 | ValueT* value = array->GetValueStorage(); |
| 287 | |
| 288 | // Read the stream contents ... |
| 289 | vtkArray::SizeT value_count = 0; |
| 290 | for (; value_count < non_null_size; ++value_count) |
| 291 | { |
| 292 | std::getline(stream, line_buffer); |
| 293 | |
| 294 | if (!stream) |
| 295 | break; |
| 296 | |
| 297 | line_stream.clear(); |
| 298 | line_stream.str(line_buffer); |
| 299 | |
| 300 | for (vtkArray::DimensionT j = 0; j != array->GetDimensions(); ++j) |
| 301 | { |
| 302 | line_stream >> *(coordinates[j] + value_count); |
| 303 | if (!extents[j].Contains(*(coordinates[j] + value_count))) |
| 304 | throw std::runtime_error("Coordinate out-of-bounds."); |
| 305 | if (!line_stream) |
| 306 | throw std::runtime_error("Missing coordinate."); |
| 307 | } |
| 308 | |
| 309 | ExtractValue(line_stream, *(value + value_count)); |
| 310 | if (!line_stream) |
| 311 | throw std::runtime_error("Missing value."); |
| 312 | } |
nothing calls this directly
no test coverage detected