| 23 | } |
| 24 | |
| 25 | bool mitk::PropertyListDeserializer::Deserialize() |
| 26 | { |
| 27 | bool error(false); |
| 28 | |
| 29 | tinyxml2::XMLDocument document; |
| 30 | if (tinyxml2::XML_SUCCESS != document.LoadFile(m_Filename.c_str())) |
| 31 | { |
| 32 | MITK_ERROR << "Could not open/read/parse " << m_Filename << "\nTinyXML reports: " << document.ErrorStr() |
| 33 | << std::endl; |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | // find version node --> note version in some variable |
| 38 | int fileVersion = 1; |
| 39 | auto *versionObject = document.FirstChildElement("Version"); |
| 40 | if (versionObject) |
| 41 | { |
| 42 | if (versionObject->QueryIntAttribute("FileVersion", &fileVersion) != tinyxml2::XML_SUCCESS) |
| 43 | { |
| 44 | MITK_ERROR << "Property file " << m_Filename << " does not contain version information! Trying version 1 format." |
| 45 | << std::endl; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | std::stringstream propertyListDeserializerClassName; |
| 50 | propertyListDeserializerClassName << "PropertyListDeserializerV" << fileVersion; |
| 51 | |
| 52 | std::list<itk::LightObject::Pointer> readers = |
| 53 | itk::ObjectFactoryBase::CreateAllInstance(propertyListDeserializerClassName.str().c_str()); |
| 54 | if (readers.size() < 1) |
| 55 | { |
| 56 | MITK_ERROR << "No property list reader found for file version " << fileVersion; |
| 57 | } |
| 58 | if (readers.size() > 1) |
| 59 | { |
| 60 | MITK_WARN << "Multiple property list readers found for file version " << fileVersion |
| 61 | << ". Using arbitrary first one."; |
| 62 | } |
| 63 | |
| 64 | for (auto iter = readers.begin(); iter != readers.end(); ++iter) |
| 65 | { |
| 66 | if (auto *reader = dynamic_cast<PropertyListDeserializer *>(iter->GetPointer())) |
| 67 | { |
| 68 | reader->SetFilename(m_Filename); |
| 69 | bool success = reader->Deserialize(); |
| 70 | error |= !success; |
| 71 | m_PropertyList = reader->GetOutput(); |
| 72 | |
| 73 | if (error) |
| 74 | { |
| 75 | MITK_ERROR << "There were errors while loading property list file " << m_Filename |
| 76 | << ". Your data may be corrupted"; |
| 77 | } |
| 78 | break; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | return !error; |
no test coverage detected