BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
Backup.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Support/XML/Backup.h
6 //! @brief Defines GUI::Util namespace
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_SUPPORT_XML_BACKUP_H
16 #define BORNAGAIN_GUI_SUPPORT_XML_BACKUP_H
17 
18 #include "Base/Util/Assert.h"
20 
21 namespace GUI::Util {
22 
23 template <typename T>
24 QByteArray createBackup(const T* t)
25 {
26  QByteArray backup;
27  QXmlStreamWriter w(&backup);
28  w.writeStartElement("backup");
29  Streamer s(&w);
30  const_cast<T*>(t)->serialize(s);
31  w.writeEndElement();
32  return backup;
33 }
34 
35 template <typename T>
36 void restoreBackup(T* t, const QByteArray& backup)
37 {
38  QXmlStreamReader r(backup);
39  Streamer sr(&r);
40  r.readNextStartElement();
41  ASSERT(r.name() == "backup");
42  t->serialize(sr);
43 }
44 
45 template <typename T>
46 void copyContents(const T* source, T* dest)
47 {
49 }
50 
51 } // namespace GUI::Util
52 
53 #endif // BORNAGAIN_GUI_SUPPORT_XML_BACKUP_H
Defines class Streamer.
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36
void restoreBackup(T *t, const QByteArray &backup)
Definition: Backup.h:36
QByteArray createBackup(const T *t)
Definition: Backup.h:24
void copyContents(const T *source, T *dest)
Definition: Backup.h:46