6#include <QtCore/QObject>
25template <
class ReadArchive,
class WriteArchive>
32 I_ASSIGN(m_autoCreateDirectoryAttrPtr,
"AutoCreatePath",
"Create directory/file path automatically if not exists",
true,
false);
33 I_ASSIGN(m_serializeAcfHeaderAttrPtr,
"SerializeAcfHeader",
"Enable or disable serializing of standard ACF header with version information",
true,
true);
34 I_ASSIGN(m_rootTagAttrPtr,
"RootTag",
"XML tag used as document root",
true,
"Acf");
40 const QString& filePath = QString(),
44 const QString& filePath = QString(),
57 : ReadArchive(filePath, serializeHeader, rootTag),
58 m_loggerPtr(loggerPtr)
66 const int* flagsPtr =
nullptr)
const override
70 return (m_loggerPtr !=
nullptr) && m_loggerPtr->
IsLogConsumed(&slaveCategory, flagsPtr);
76 const QString& message,
77 const QString& messageSource,
78 int flags = 0)
const override
80 if (m_loggerPtr !=
nullptr){
81 QString correctedMessage = message;
82 QString correctedMessageSource = messageSource;
102 const QString& filePath,
104 bool serializeHeader,
107 :WriteArchive(filePath, infoPtr, serializeHeader, rootTag),
108 m_loggerPtr(loggerPtr)
116 const int* flagsPtr =
nullptr)
const override
120 return (m_loggerPtr !=
nullptr) && m_loggerPtr->
IsLogConsumed(&slaveCategory, flagsPtr);
126 const QString& message,
127 const QString& messageSource,
128 int flags = 0)
const override
130 if (m_loggerPtr !=
nullptr){
131 QString correctedMessage = message;
132 QString correctedMessageSource = messageSource;
136 return m_loggerPtr->
SendLogMessage(category,
id, correctedMessage, correctedMessageSource, flags);
152 I_ATTR(
bool, m_autoCreateDirectoryAttrPtr);
153 I_ATTR(
bool, m_serializeAcfHeaderAttrPtr);
154 I_ATTR(QByteArray, m_rootTagAttrPtr);
162template <
class ReadArchive,
class WriteArchive>
165 const QString& filePath,
168 if (IsOperationSupported(&data, &filePath, QF_LOAD | QF_FILE, *m_beQuiteOnLoadAttrPtr)){
171 ReadArchiveEx archive(filePath, *m_serializeAcfHeaderAttrPtr, rootTag,
this);
173 Q_ASSERT(!archive.IsStoring());
179 if (serializablePtr ==
nullptr){
180 serializablePtr = CompCastPtr<iser::ISerializable>(&data);
183 Q_ASSERT(serializablePtr !=
nullptr);
185 if (serializablePtr->
Serialize(archive)){
189 OnReadError(archive, data, filePath);
197template <
class ReadArchive,
class WriteArchive>
200 const QString& filePath,
203 if (*m_autoCreateDirectoryAttrPtr){
204 QFileInfo fileInfo(filePath);
207 SendErrorMessage(MI_FILE_NOT_EXIST, QObject::tr(
"Cannot create path to file"));
211 if (IsOperationSupported(&data, &filePath, QF_SAVE | QF_FILE,
false)){
214 WriteArchiveEx archive(filePath, GetVersionInfo(), *m_serializeAcfHeaderAttrPtr, rootTag,
this);
215 Q_ASSERT(archive.IsStoring());
221 if(serializablePtr ==
nullptr){
222 serializablePtr = CompCastPtr<iser::ISerializable>(&data);
224 Q_ASSERT(serializablePtr !=
nullptr);
226 if (!CheckMinimalVersion(*serializablePtr, archive.GetVersionInfo())){
227 SendWarningMessage(MI_UNSUPPORTED_VERSION, QObject::tr(
"Archive version is not supported, possible lost of data"));
234 SendInfoMessage(MI_CANNOT_SAVE, QObject::tr(
"Cannot serialize object to file: '%1'").arg(filePath));
244template <
class ReadArchive,
class WriteArchive>
248 const QString& filePath)
const
250 SendWarningMessage(MI_CANNOT_LOAD, QString(QObject::tr(
"Cannot load object from file ")) + filePath);
Consume information about progress of some process.
Base implementation of file serializer.
OperationState
Result of operation.
virtual bool IsLogConsumed(const istd::IInformationProvider::InformationCategory *, const int *flagsPtr=nullptr) const override
ReadArchiveEx(const QString &filePath, bool serializeHeader, const iser::CArchiveTag &rootTag, const TXmlFileSerializerComp *loggerPtr)
virtual bool SendLogMessage(istd::IInformationProvider::InformationCategory category, int id, const QString &message, const QString &messageSource, int flags=0) const override
WriteArchiveEx(const QString &filePath, const iser::IVersionInfo *infoPtr, bool serializeHeader, const iser::CArchiveTag &rootTag, const TXmlFileSerializerComp *loggerPtr)
virtual bool SendLogMessage(istd::IInformationProvider::InformationCategory category, int id, const QString &message, const QString &messageSource, int flags=0) const override
virtual bool IsLogConsumed(const istd::IInformationProvider::InformationCategory *, const int *flagsPtr=nullptr) const override
Template implementation of file serializer using loading and storing archive implementation.
virtual void OnReadError(const ReadArchive &archive, const istd::IChangeable &data, const QString &filePath) const
Called if read error is occurred.
virtual ifile::IFilePersistence::OperationState LoadFromFile(istd::IChangeable &data, const QString &filePath=QString(), ibase::IProgressManager *progressManagerPtr=nullptr) const override
This function loads data data from file filePath.
CFileSerializerCompBase BaseClass
virtual ifile::IFilePersistence::OperationState SaveToFile(const istd::IChangeable &data, const QString &filePath=QString(), ibase::IProgressManager *progressManagerPtr=nullptr) const override
This function saves data data to file filePath.
virtual bool SendLogMessage(istd::IInformationProvider::InformationCategory category, int id, const QString &message, const QString &messageSource, int flags=0) const override
Send any message to log.
virtual void DecorateMessage(istd::IInformationProvider::InformationCategory category, int id, int flags, QString &message, QString &messageSource) const override
Decorate message parts before outputting.
virtual bool IsLogConsumed(const istd::IInformationProvider::InformationCategory *categoryPtr=NULL, const int *flagsPtr=NULL) const override
Check if any log message is consumed.
Process tag used to group data in archive stream.
@ TT_GROUP
Normal tag used for grouping of tags or processed elements.
Common class for all classes which objects can be archived or restored from archive.
virtual bool Serialize(IArchive &archive)=0
Load or store state of this object as a archive stream.
Provides access to version information.
static bool EnsurePathExists(const QString &filePath)
Ensure that the given path exists.
Common interface for data model objects, which can be changed.
Contains interfaces and implementations of file system related components.