29 lines
717 B
C++
29 lines
717 B
C++
#ifndef __WeakStore_H__
|
||
#define __WeakStore_H__
|
||
|
||
#include "Sys.h"
|
||
#include "Stream.h"
|
||
|
||
// 弱存储。
|
||
// 采用全局变量或者堆分配的变量在系统启动时会被清空。
|
||
// 弱存储在main函数内栈分配,位于栈的最后部分,不会因为重启而被清空
|
||
class WeakStore
|
||
{
|
||
public:
|
||
string Magic; // 幻数。用于唯一标识
|
||
uint MagicLength;
|
||
ByteArray Data; // 数据
|
||
|
||
// 初始化
|
||
WeakStore(string magic = NULL, byte* ptr = NULL, uint len = 0);
|
||
|
||
// 检查并确保初始化,返回原来是否已初始化
|
||
bool Check();
|
||
void Init();
|
||
|
||
// 重载索引运算符[],定位到数据部分的索引。
|
||
byte& operator[](int i) const;
|
||
};
|
||
|
||
#endif
|