------------------------------------------------------------------------------ Specialize for string arrays:
| 335 | //------------------------------------------------------------------------------ |
| 336 | // Specialize for string arrays: |
| 337 | int vtkXMLWriterWriteBinaryDataBlocks(vtkXMLWriter* writer, |
| 338 | vtkArrayIteratorTemplate<vtkStdString>* iter, int wordType, size_t outWordSize, size_t numStrings, |
| 339 | int) |
| 340 | { |
| 341 | vtkXMLWriterHelper::SetProgressPartial(writer, 0); |
| 342 | vtkStdString::value_type* allocated_buffer = nullptr; |
| 343 | vtkStdString::value_type* temp_buffer = nullptr; |
| 344 | if (vtkXMLWriterHelper::GetInt32IdTypeBuffer(writer)) |
| 345 | { |
| 346 | temp_buffer = |
| 347 | reinterpret_cast<vtkStdString::value_type*>(vtkXMLWriterHelper::GetInt32IdTypeBuffer(writer)); |
| 348 | } |
| 349 | else if (vtkXMLWriterHelper::GetByteSwapBuffer(writer)) |
| 350 | { |
| 351 | temp_buffer = |
| 352 | reinterpret_cast<vtkStdString::value_type*>(vtkXMLWriterHelper::GetByteSwapBuffer(writer)); |
| 353 | } |
| 354 | else |
| 355 | { |
| 356 | allocated_buffer = new vtkStdString::value_type[writer->GetBlockSize() / outWordSize]; |
| 357 | temp_buffer = allocated_buffer; |
| 358 | } |
| 359 | |
| 360 | // For string arrays, writing as binary requires that the strings are written |
| 361 | // out into a contiguous block. This is essential since the compressor can |
| 362 | // only compress complete blocks of data. |
| 363 | size_t maxCharsPerBlock = writer->GetBlockSize() / outWordSize; |
| 364 | |
| 365 | size_t index = 0; // index in string array. |
| 366 | int result = 1; |
| 367 | vtkIdType stringOffset = 0; // num of chars of string written in previous block. |
| 368 | // this is required since a string may not fit completely in a block. |
| 369 | |
| 370 | while (result && index < numStrings) // write one block at a time. |
| 371 | { |
| 372 | size_t cur_offset = 0; // offset into the temp_buffer. |
| 373 | while (index < numStrings && cur_offset < maxCharsPerBlock) |
| 374 | { |
| 375 | vtkStdString& str = iter->GetValue(static_cast<vtkIdType>(index)); |
| 376 | vtkStdString::size_type length = str.size(); |
| 377 | const char* data = str.c_str(); |
| 378 | data += stringOffset; // advance by the chars already written. |
| 379 | length -= stringOffset; |
| 380 | if (length == 0) |
| 381 | { |
| 382 | // just write the string termination char. |
| 383 | temp_buffer[cur_offset++] = 0x0; |
| 384 | stringOffset = 0; |
| 385 | index++; // advance to the next string |
| 386 | } |
| 387 | else |
| 388 | { |
| 389 | size_t new_offset = cur_offset + length + 1; // (+1) for termination char. |
| 390 | if (new_offset <= maxCharsPerBlock) |
| 391 | { |
| 392 | memcpy(&temp_buffer[cur_offset], data, length); |
| 393 | cur_offset += length; |
| 394 | temp_buffer[cur_offset++] = 0x0; |
no test coverage detected