1
/***************************************************************************
2
* Copyright (c) 2011 Jürgen Riegel <juergen.riegel@web.de> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
34
/// Here the FreeCAD includes sorted by Base,App,Gui......
35
#include "Persistence.h"
40
TYPESYSTEM_SOURCE_ABSTRACT(Base::Persistence, Base::BaseClass)
43
//**************************************************************************
44
// Construction/Destruction
47
//**************************************************************************
48
// separator for other implementation aspects
50
unsigned int Persistence::getMemSize() const
52
// you have to implement this method in all descending classes!
57
void Persistence::Save(Writer& /*writer*/) const
59
// you have to implement this method in all descending classes!
63
void Persistence::Restore(XMLReader& /*reader*/)
65
// you have to implement this method in all descending classes!
69
void Persistence::SaveDocFile(Writer& /*writer*/) const
72
void Persistence::RestoreDocFile(Reader& /*reader*/)
75
std::string Persistence::encodeAttribute(const std::string& str)
113
void Persistence::dumpToStream(std::ostream& stream, int compression)
115
// we need to close the zipstream to get a good result, the only way to do this is to delete the
116
// ZipWriter. Hence the scope...
119
Base::ZipWriter writer(stream);
120
writer.setLevel(compression);
121
writer.putNextEntry("Persistence.xml");
122
writer.setMode("BinaryBrep");
124
// save the content (we need to encapsulate it with xml tags to be able to read single
125
// element xmls like happen for properties)
126
writer.Stream() << "<Content>" << std::endl;
128
writer.Stream() << "</Content>";
133
void Persistence::restoreFromStream(std::istream& stream)
135
zipios::ZipInputStream zipstream(stream);
136
Base::XMLReader reader("", zipstream);
138
if (!reader.isValid()) {
139
throw Base::ValueError("Unable to construct reader");
142
reader.readElement("Content");
144
reader.readFiles(zipstream);