initial commit
This commit is contained in:
27
client/core/persistence/PersistentBinaryObject.h
Normal file
27
client/core/persistence/PersistentBinaryObject.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
class QDataStream;
|
||||
|
||||
namespace core {
|
||||
|
||||
// 二进制记录的统一持久化基类:魔数/版本、QDataStream 版本、.tmp 原子替换、父目录创建。
|
||||
//
|
||||
// 领域类型(如 Project::Entity)应保持为可拷贝的值类型,不要继承本类;为每种存储格式写一个
|
||||
// 小的适配器类(如 EntityBinaryRecord)继承本类并实现 writeBody/readBody 即可。
|
||||
class PersistentBinaryObject {
|
||||
public:
|
||||
virtual ~PersistentBinaryObject() = default;
|
||||
|
||||
[[nodiscard]] bool saveToFile(const QString& absolutePath) const;
|
||||
[[nodiscard]] bool loadFromFile(const QString& absolutePath);
|
||||
|
||||
protected:
|
||||
virtual quint32 recordMagic() const = 0;
|
||||
virtual quint32 recordFormatVersion() const = 0;
|
||||
virtual void writeBody(QDataStream& ds) const = 0;
|
||||
virtual bool readBody(QDataStream& ds) = 0;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
Reference in New Issue
Block a user