| 4488 | // Code: vtkFoamIOobject |
| 4489 | |
| 4490 | void vtkFoamIOobject::ReadHeader() |
| 4491 | { |
| 4492 | this->Superclass::ReadExpecting("FoamFile"); |
| 4493 | this->Superclass::ReadExpecting('{'); |
| 4494 | |
| 4495 | vtkFoamDict headerDict; |
| 4496 | headerDict.SetStreamOption(this->GetStreamOption()); |
| 4497 | headerDict.Read(*this, true); // Read as sub-dict. Throw exception in case of error |
| 4498 | |
| 4499 | const vtkFoamEntry* eptr; |
| 4500 | |
| 4501 | // Essentials |
| 4502 | if ((eptr = headerDict.Lookup("class")) == nullptr) |
| 4503 | { |
| 4504 | throw vtkFoamError() << "No 'class' in FoamFile header"; |
| 4505 | } |
| 4506 | this->headerClassName_ = eptr->ToString(); |
| 4507 | |
| 4508 | if ((eptr = headerDict.Lookup("object")) == nullptr) |
| 4509 | { |
| 4510 | throw vtkFoamError() << "No 'object' in FoamFile header"; |
| 4511 | } |
| 4512 | this->objectName_ = eptr->ToString(); |
| 4513 | |
| 4514 | if ((eptr = headerDict.Lookup("format")) == nullptr) |
| 4515 | { |
| 4516 | // Note (2021-03-19): may make this optional in the future, defaulting to ascii |
| 4517 | throw vtkFoamError() << "No 'format' (ascii|binary) in FoamFile header"; |
| 4518 | } |
| 4519 | this->SetBinaryFormat("binary" == eptr->ToString()); // case sensitive |
| 4520 | |
| 4521 | // The arch entry has "label=(32|64) scalar=(32|64)" |
| 4522 | // If missing/incomplete, use fallback values from reader (defined in constructor and Close) |
| 4523 | if ((eptr = headerDict.Lookup("arch")) != nullptr) |
| 4524 | { |
| 4525 | const std::string archValue(eptr->ToString()); |
| 4526 | |
| 4527 | // Match "label=(32|64)" |
| 4528 | { |
| 4529 | auto pos = archValue.find("label="); |
| 4530 | if (pos != std::string::npos) |
| 4531 | { |
| 4532 | pos += 6; // Skip past "label=" |
| 4533 | if (archValue.compare(pos, 2, "32") == 0) |
| 4534 | { |
| 4535 | this->SetLabel64(false); |
| 4536 | } |
| 4537 | else if (archValue.compare(pos, 2, "64") == 0) |
| 4538 | { |
| 4539 | this->SetLabel64(true); |
| 4540 | } |
| 4541 | } |
| 4542 | } |
| 4543 | |
| 4544 | // Match "scalar=(32|64)" |
| 4545 | { |
| 4546 | auto pos = archValue.find("scalar="); |
| 4547 | if (pos != std::string::npos) |
no test coverage detected