10#include <QtCore/QObject>
27template <
class ReadArchive,
class WriteArchive>
34 I_ASSIGN(m_autoCreateDirectoryAttrPtr,
"AutoCreatePath",
"Create directory/file path automatically if not exists",
true,
false);
35 I_ASSIGN(m_serializeAcfHeaderAttrPtr,
"SerializeIcfHeader",
"Enable or disable serializing of standard ICF header with version information",
true,
true);
36 I_ASSIGN(m_rootTagAttrPtr,
"RootTag",
"XML tag used as document root",
true,
"Icf");
42 const QString& filePath = QString(),
46 const QString& filePath = QString(),
59 : ReadArchive(filePath, serializeHeader, rootTag),
60 m_loggerPtr(loggerPtr)
68 const int* flagsPtr =
nullptr)
const override
72 return (m_loggerPtr !=
nullptr) && m_loggerPtr->
IsLogConsumed(&slaveCategory, flagsPtr);
77 const QString& message,
78 const QString& messageSource,
79 int flags = 0)
const override
81 if (m_loggerPtr !=
nullptr){
82 QString correctedMessage = message;
83 QString correctedMessageSource = messageSource;
103 const QString& filePath,
105 bool serializeHeader,
108 : WriteArchive(filePath, infoPtr, serializeHeader, rootTag),
109 m_loggerPtr(loggerPtr)
117 const int* flagsPtr =
nullptr)
const override
121 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,
false)){
171 ReadArchiveEx archive(filePath, *m_serializeAcfHeaderAttrPtr, rootTag,
this);
173 Q_ASSERT(archive.IsChanging());
179 if (serializablePtr ==
nullptr){
183 Q_ASSERT(serializablePtr !=
nullptr);
185 if (serializablePtr->
Serialize(archive)){
186 return iproc::CTaskState::Status::Ready;
189 OnReadError(archive, data, filePath);
193 return iproc::CTaskState::Status::Failed;
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.IsChanging());
221 if (serializablePtr ==
nullptr){
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"));
231 return iproc::CTaskState::Status::Ready;
234 SendInfoMessage(MI_CANNOT_SAVE, QObject::tr(
"Cannot serialize object to file: '%1'").arg(filePath));
238 return iproc::CTaskState::Status::Failed;
244template <
class ReadArchive,
class WriteArchive>
247 SendWarningMessage(MI_CANNOT_LOAD, QObject::tr(
"Cannot load object from XML file %1").arg(filePath));
Dest * CompCastPtr(istd::IPolymorphic *objectPtr)
Cast to specified interface trying to use component interface query.
Base implementation of file serializer.
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 iproc::CTaskState LoadFromFile(istd::IChangeable &data, const QString &filePath=QString(), iproc::IProgressManager *progressManagerPtr=nullptr) const override
This function loads data data from file filePath.
CFileSerializerCompBase BaseClass
virtual iproc::CTaskState SaveToFile(const istd::IChangeable &data, const QString &filePath=QString(), iproc::IProgressManager *progressManagerPtr=nullptr) const override
This function saves data data to file filePath.
bool SendLogMessage(istd::IInformationProvider::InformationCategory category, int id, const QString &message, const QString &messageSource, int flags=0) const override
Send any message to log.
void DecorateMessage(istd::IInformationProvider::InformationCategory category, int id, int flags, QString &message, QString &messageSource) const override
Decorate message parts before outputting.
bool IsLogConsumed(const istd::IInformationProvider::InformationCategory *categoryPtr=nullptr, const int *flagsPtr=nullptr) const override
Check if any log message is consumed.
Represent state of asynchronous operation.
Consume information about progress of some process.
Process tag used to group data in archive stream.
@ 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.