MCPcopy Create free account
hub / github.com/MITK/MITK / Serialize

Method Serialize

Modules/SceneSerializationBase/src/mitkPropertyListSerializer.cpp:27–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27std::string mitk::PropertyListSerializer::Serialize()
28{
29 m_FailedProperties = PropertyList::New();
30
31 if (m_PropertyList.IsNull() || m_PropertyList->IsEmpty())
32 {
33 MITK_ERROR << "Not serializing nullptr or empty PropertyList";
34 return "";
35 }
36
37 // tmpname
38 static unsigned long count = 1;
39 unsigned long n = count++;
40 std::ostringstream name;
41 for (int i = 0; i < 6; ++i)
42 {
43 name << char('a' + (n % 26));
44 n /= 26;
45 }
46 std::string filename;
47 filename.append(name.str());
48
49 std::string fullname(m_WorkingDirectory);
50 fullname += "/";
51 fullname += filename;
52 fullname = itksys::SystemTools::ConvertToOutputPath(fullname.c_str());
53
54 // Trim quotes
55 std::string::size_type length = fullname.length();
56
57 if (length >= 2 && fullname[0] == '"' && fullname[length - 1] == '"')
58 fullname = fullname.substr(1, length - 2);
59
60 tinyxml2::XMLDocument document;
61 document.InsertEndChild(document.NewDeclaration());
62
63 auto *version = document.NewElement("Version");
64 version->SetAttribute("Writer", __FILE__);
65 version->SetAttribute("Revision", "$Revision: 17055 $");
66 version->SetAttribute("FileVersion", 1);
67 document.InsertEndChild(version);
68
69 // add XML contents
70 const PropertyList::PropertyMap *propmap = m_PropertyList->GetMap();
71 for (auto iter = propmap->begin(); iter != propmap->end(); ++iter)
72 {
73 std::string key = iter->first;
74 const BaseProperty *property = iter->second;
75 auto *element = SerializeOneProperty(document, key, property);
76 if (element)
77 {
78 document.InsertEndChild(element);
79 // TODO test serializer for error
80 }
81 else
82 {
83 m_FailedProperties->ReplaceProperty(key, const_cast<BaseProperty *>(property));
84 }

Callers 1

SerializeOnePropertyMethod · 0.45

Calls 6

NewFunction · 0.50
IsNullMethod · 0.45
IsEmptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
ReplacePropertyMethod · 0.45

Tested by

no test coverage detected