Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include <tinyxml.h>
20 
22 {
23 }
24 
26 {
27 }
28 
30 {
31  bool error(false);
32 
33  TiXmlDocument document(m_Filename);
34  if (!document.LoadFile())
35  {
36  MITK_ERROR << "Could not open/read/parse " << m_Filename << "\nTinyXML reports: " << document.ErrorDesc()
37  << std::endl;
38  return false;
39  }
40 
41  // find version node --> note version in some variable
42  int fileVersion = 1;
43  TiXmlElement *versionObject = document.FirstChildElement("Version");
44  if (versionObject)
45  {
46  if (versionObject->QueryIntAttribute("FileVersion", &fileVersion) != TIXML_SUCCESS)
47  {
48  MITK_ERROR << "Property file " << m_Filename << " does not contain version information! Trying version 1 format."
49  << std::endl;
50  }
51  }
52 
53  std::stringstream propertyListDeserializerClassName;
54  propertyListDeserializerClassName << "PropertyListDeserializerV" << fileVersion;
55 
56  std::list<itk::LightObject::Pointer> readers =
57  itk::ObjectFactoryBase::CreateAllInstance(propertyListDeserializerClassName.str().c_str());
58  if (readers.size() < 1)
59  {
60  MITK_ERROR << "No property list reader found for file version " << fileVersion;
61  }
62  if (readers.size() > 1)
63  {
64  MITK_WARN << "Multiple property list readers found for file version " << fileVersion
65  << ". Using arbitrary first one.";
66  }
67 
68  for (auto iter = readers.begin(); iter != readers.end(); ++iter)
69  {
70  if (PropertyListDeserializer *reader = dynamic_cast<PropertyListDeserializer *>(iter->GetPointer()))
71  {
72  reader->SetFilename(m_Filename);
73  bool success = reader->Deserialize();
74  error |= !success;
75  m_PropertyList = reader->GetOutput();
76 
77  if (error)
78  {
79  MITK_ERROR << "There were errors while loading property list file " << m_Filename
80  << ". Your data may be corrupted";
81  }
82  break;
83  }
84  }
85 
86  return !error;
87 }
88 
90 {
91  return m_PropertyList;
92 }
#define MITK_ERROR
Definition: mitkLogMacros.h:24
virtual bool Deserialize()
Reads a propertylist from file.
Deserializes a mitk::PropertyList.
#define MITK_WARN
Definition: mitkLogMacros.h:23
virtual PropertyList::Pointer GetOutput()