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);
38 const QString& filePath = QString(),
42 const QString& filePath = QString(),
52 : ReadArchive(filePath),
53 m_loggerPtr(loggerPtr)
59 if (m_loggerPtr !=
nullptr){
60 QString correctedMessage = message;
61 QString correctedMessageSource = messageSource;
75 const int* flagsPtr =
nullptr)
const override
79 return (m_loggerPtr !=
nullptr) && m_loggerPtr->
IsLogConsumed(&slaveCategory, flagsPtr);
92 : WriteArchive(filePath, infoPtr),
93 m_loggerPtr(loggerPtr)
99 if (m_loggerPtr !=
nullptr){
100 QString correctedMessage = message;
101 QString correctedMessageSource = messageSource;
105 return m_loggerPtr->
SendLogMessage(category,
id, correctedMessage, correctedMessageSource, flags);
115 const int* flagsPtr =
nullptr)
const override
119 return (m_loggerPtr !=
nullptr) && m_loggerPtr->
IsLogConsumed(&slaveCategory, flagsPtr);
132 I_ATTR(
bool, m_autoCreateDirectoryAttrPtr);
140template <
class ReadArchive,
class WriteArchive>
143 const QString& filePath,
146 if (IsOperationSupported(&data, &filePath, QF_LOAD | QF_FILE, *m_beQuiteOnLoadAttrPtr)){
149 Q_ASSERT(!archive.IsStoring());
155 if (serializablePtr ==
nullptr){
156 serializablePtr = CompCastPtr<iser::ISerializable>(&data);
159 Q_ASSERT(serializablePtr !=
nullptr);
161 if (serializablePtr->
Serialize(archive)){
165 OnReadError(archive, data, filePath);
173template <
class ReadArchive,
class WriteArchive>
176 const QString& filePath,
179 if (*m_autoCreateDirectoryAttrPtr){
180 QFileInfo fileInfo(filePath);
183 SendErrorMessage(MI_FILE_NOT_EXIST, QObject::tr(
"Cannot create path to file"));
187 if (IsOperationSupported(&data, &filePath, QF_SAVE | QF_FILE,
false)){
189 Q_ASSERT(archive.IsStoring());
195 if(serializablePtr ==
nullptr){
196 serializablePtr = CompCastPtr<iser::ISerializable>(&data);
198 Q_ASSERT(serializablePtr !=
nullptr);
200 if (!CheckMinimalVersion(*serializablePtr, archive.GetVersionInfo())){
201 SendWarningMessage(MI_UNSUPPORTED_VERSION, QObject::tr(
"Archive version is not supported, possible lost of data"));
208 SendInfoMessage(MI_CANNOT_SAVE, QObject::tr(
"Cannot serialize object to file: '%1'").arg(filePath));
218template <
class ReadArchive,
class WriteArchive>
222 const QString& filePath)
const
224 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.
ReadArchiveEx(const QString &filePath, const istd::ILogger *loggerPtr)
virtual bool IsLogConsumed(const istd::IInformationProvider::InformationCategory *, const int *flagsPtr=nullptr) const override
virtual bool SendLogMessage(istd::IInformationProvider::InformationCategory category, int id, const QString &message, const QString &messageSource, int flags=0) const
virtual bool IsLogConsumed(const istd::IInformationProvider::InformationCategory *, const int *flagsPtr=nullptr) const override
virtual bool SendLogMessage(istd::IInformationProvider::InformationCategory category, int id, const QString &message, const QString &messageSource, int flags=0) const
WriteArchiveEx(const QString &filePath, const iser::IVersionInfo *infoPtr, const istd::ILogger *loggerPtr)
Template implementation of file serializer using loading and storing archive implementation.
virtual ifile::IFilePersistence::OperationState LoadFromFile(istd::IChangeable &data, const QString &filePath=QString(), ibase::IProgressManager *progressManagerPtr=NULL) const override
This function loads data data from file filePath.
virtual ifile::IFilePersistence::OperationState SaveToFile(const istd::IChangeable &data, const QString &filePath=QString(), ibase::IProgressManager *progressManagerPtr=NULL) const override
This function saves data data to file filePath.
virtual void OnReadError(const ReadArchive &archive, const istd::IChangeable &data, const QString &filePath) const
Called if read error is occurred.
CFileSerializerCompBase BaseClass
virtual void DecorateMessage(istd::IInformationProvider::InformationCategory category, int id, int flags, QString &message, QString &messageSource) const override
Decorate message parts before outputting.
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.
Common interface for classes sending some log info.
virtual bool SendLogMessage(IInformationProvider::InformationCategory category, int id, const QString &message, const QString &messageSource, int flags=0) const
Send any message to log.
virtual bool IsLogConsumed(const IInformationProvider::InformationCategory *categoryPtr=NULL, const int *flagsPtr=NULL) const
Check if any log message is consumed.
Contains interfaces and implementations of file system related components.