Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkPropertyListDeserializer.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 #include <tinyxml.h>
16 
18 {
19 }
20 
22 {
23 }
24 
26 {
27  bool error(false);
28 
29  TiXmlDocument document(m_Filename);
30  if (!document.LoadFile())
31  {
32  MITK_ERROR << "Could not open/read/parse " << m_Filename << "\nTinyXML reports: " << document.ErrorDesc()
33  << std::endl;
34  return false;
35  }
36 
37  // find version node --> note version in some variable
38  int fileVersion = 1;
39  TiXmlElement *versionObject = document.FirstChildElement("Version");
40  if (versionObject)
41  {
42  if (versionObject->QueryIntAttribute("FileVersion", &fileVersion) != TIXML_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;
83 }
84 
86 {
87  return m_PropertyList;
88 }
#define MITK_ERROR
Definition: mitkLogMacros.h:20
virtual bool Deserialize()
Reads a propertylist from file.
#define MITK_WARN
Definition: mitkLogMacros.h:19
virtual PropertyList::Pointer GetOutput()