------------------------------------------------------------------------------
| 364 | |
| 365 | //------------------------------------------------------------------------------ |
| 366 | int vtkXMLReader::OpenVTKString() |
| 367 | { |
| 368 | if (this->StringStream) |
| 369 | { |
| 370 | vtkErrorMacro("string already open."); |
| 371 | return 1; |
| 372 | } |
| 373 | |
| 374 | if (!this->Stream && this->InputString.empty() && |
| 375 | (this->InputArray == nullptr || this->InputArray->GetNumberOfValues() == 0)) |
| 376 | { |
| 377 | vtkErrorMacro("Input string not specified"); |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | if (this->Stream) |
| 382 | { |
| 383 | // Use user-provided stream. |
| 384 | return 1; |
| 385 | } |
| 386 | |
| 387 | // Open the string stream |
| 388 | if (this->InputArray) |
| 389 | { |
| 390 | vtkDebugMacro(<< "Reading from InputArray"); |
| 391 | std::string str(this->InputArray->GetPointer(0), |
| 392 | static_cast<size_t>( |
| 393 | this->InputArray->GetNumberOfTuples() * this->InputArray->GetNumberOfComponents())); |
| 394 | this->StringStream = new std::istringstream(str); |
| 395 | if (!this->StringStream || !(*this->StringStream)) |
| 396 | { |
| 397 | vtkErrorMacro("Error opening string stream"); |
| 398 | delete this->StringStream; |
| 399 | this->StringStream = nullptr; |
| 400 | return 0; |
| 401 | } |
| 402 | } |
| 403 | else if (!this->InputString.empty()) |
| 404 | { |
| 405 | vtkDebugMacro(<< "Reading from InputString"); |
| 406 | this->StringStream = new std::istringstream(this->InputString); |
| 407 | if (!this->StringStream || !(*this->StringStream)) |
| 408 | { |
| 409 | vtkErrorMacro("Error opening string stream"); |
| 410 | delete this->StringStream; |
| 411 | this->StringStream = nullptr; |
| 412 | return 0; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | // Use the string stream. |
| 417 | this->Stream = this->StringStream; |
| 418 | |
| 419 | return 1; |
| 420 | } |
| 421 | |
| 422 | //------------------------------------------------------------------------------ |
| 423 | void vtkXMLReader::CloseStream() |
no test coverage detected