libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::Database::Key< Data > Class Template Reference

模板类,表示数据库中的具体键 (Template class representing a specific key in the database). More...

#include <interface.hpp>

Inheritance diagram for LibXR::Database::Key< Data >:
[legend]
Collaboration diagram for LibXR::Database::Key< Data >:
[legend]

Public Member Functions

 Key (Database &database, const char *name, Data init_value)
 构造函数,初始化键并从数据库加载数据 (Constructor to initialize key and load data from the database).
 
 Key (Database &database, const char *name)
 构造函数,初始化键,并在数据库不存在时赋默认值 (Constructor to initialize key, assigning default value if not found in the database).
 
 Key (const Key &other)=delete
 禁止拷贝数据库键对象 (Copy construction is disabled for database keys).
 
 Key (Key &&other)=delete
 禁止移动数据库键对象 (Move construction is disabled for database keys).
 
Keyoperator= (const Key &other)=delete
 禁止拷贝赋值数据库键对象 (Copy assignment is disabled for database keys).
 
Keyoperator= (Key &&other)=delete
 禁止移动赋值数据库键对象 (Move assignment is disabled for database keys).
 
 operator Data ()
 类型转换运算符,返回存储的数据 (Type conversion operator returning stored data).
 
ErrorCode Save ()
 保存当前键值到数据库 (Save the current key value to the database).
 
ErrorCode Set (Data data)
 设置键的值并更新数据库 (Set the key's value and update the database).
 
ErrorCode Load ()
 从数据库加载键的值 (Load the key's value from the database).
 
ErrorCode operator= (Data data)
 赋值运算符,设置键的值 (Assignment operator to set the key's value).
 
- Public Member Functions inherited from LibXR::Database::KeyBase
 KeyBase (const char *name, RawData raw_data)
 构造函数,初始化键名和原始数据 (Constructor to initialize key name and raw data).
 

Data Fields

Data data_
 键存储的数据 (The data stored in the key).
 
Databasedatabase_
 关联的数据库对象 (Reference to the associated database).
 
- Data Fields inherited from LibXR::Database::KeyBase
const char * name_
 键名 (Key name).
 
RawData raw_data_
 原始数据 (Raw data associated with the key).
 

Detailed Description

template<typename Data>
class LibXR::Database::Key< Data >

模板类,表示数据库中的具体键 (Template class representing a specific key in the database).

Template Parameters
Data存储的数据类型 (The type of data stored).

Definition at line 51 of file interface.hpp.

Constructor & Destructor Documentation

◆ Key() [1/4]

template<typename Data >
LibXR::Database::Key< Data >::Key ( Database & database,
const char * name,
Data init_value )
inline

构造函数,初始化键并从数据库加载数据 (Constructor to initialize key and load data from the database).

If the key does not exist in the database, it is initialized with the provided value. 如果键在数据库中不存在,则使用提供的值进行初始化。

Parameters
database关联的数据库对象 (Reference to the associated database).
name键名 (Key name).
init_value初始化值 (Initial value for the key).

Definition at line 68 of file interface.hpp.

69 : KeyBase(name, RawData(data_)), database_(database)
70 {
71 ErrorCode status = database.Get(*this);
72 if (status != ErrorCode::OK)
73 {
74 data_ = init_value;
75 if (status == ErrorCode::NOT_FOUND)
76 {
77 REQUIRE(database.Add(*this) == ErrorCode::OK);
78 }
79 }
80 }
KeyBase(const char *name, RawData raw_data)
构造函数,初始化键名和原始数据 (Constructor to initialize key name and raw data).
Definition interface.hpp:42
Database & database_
关联的数据库对象 (Reference to the associated database).
Definition interface.hpp:55
Data data_
键存储的数据 (The data stored in the key).
Definition interface.hpp:54
virtual ErrorCode Get(KeyBase &key)=0
从数据库获取键的值 (Retrieve the key's value from the database).
ErrorCode
定义错误码枚举
@ NOT_FOUND
未找到 | Not found
@ OK
操作成功 | Operation successful

◆ Key() [2/4]

template<typename Data >
LibXR::Database::Key< Data >::Key ( Database & database,
const char * name )
inline

构造函数,初始化键,并在数据库不存在时赋默认值 (Constructor to initialize key, assigning default value if not found in the database).

If the key does not exist in the database, it is initialized with zero. 如果键在数据库中不存在,则初始化为零。

Parameters
database关联的数据库对象 (Reference to the associated database).
name键名 (Key name).

Definition at line 92 of file interface.hpp.

93 : KeyBase(name, RawData(data_)), database_(database)
94 {
95 ErrorCode status = database.Get(*this);
96 if (status != ErrorCode::OK)
97 {
98 Memory::FastSet(&data_, 0, sizeof(Data));
99 if (status == ErrorCode::NOT_FOUND)
100 {
101 REQUIRE(database.Add(*this) == ErrorCode::OK);
102 }
103 }
104 }
static void FastSet(void *dst, uint8_t value, size_t size)
快速内存填充 / Fast memory fill

◆ Key() [3/4]

template<typename Data >
LibXR::Database::Key< Data >::Key ( const Key< Data > & other)
delete

禁止拷贝数据库键对象 (Copy construction is disabled for database keys).

Parameters
other被拷贝的键对象 (Database key to copy from).

◆ Key() [4/4]

template<typename Data >
LibXR::Database::Key< Data >::Key ( Key< Data > && other)
delete

禁止移动数据库键对象 (Move construction is disabled for database keys).

Parameters
other被转移的键对象 (Database key to move from).

Member Function Documentation

◆ Load()

template<typename Data >
ErrorCode LibXR::Database::Key< Data >::Load ( )
inline

从数据库加载键的值 (Load the key's value from the database).

Returns
操作结果 (Operation result).

Definition at line 167 of file interface.hpp.

167{ return database_.Get(*this); }

◆ operator Data()

template<typename Data >
LibXR::Database::Key< Data >::operator Data ( )
inline

类型转换运算符,返回存储的数据 (Type conversion operator returning stored data).

Returns
存储的数据 (Stored data).

Definition at line 141 of file interface.hpp.

141{ return data_; }

◆ operator=() [1/3]

template<typename Data >
Key & LibXR::Database::Key< Data >::operator= ( const Key< Data > & other)
delete

禁止拷贝赋值数据库键对象 (Copy assignment is disabled for database keys).

Parameters
other被拷贝的键对象 (Database key to copy from).
Returns
当前键对象引用 (Reference to the current key object).

◆ operator=() [2/3]

template<typename Data >
ErrorCode LibXR::Database::Key< Data >::operator= ( Data data)
inline

赋值运算符,设置键的值 (Assignment operator to set the key's value).

Parameters
data需要存储的新值 (New value to store).
Returns
操作结果 (Operation result).

Definition at line 175 of file interface.hpp.

175{ return Set(data); } // NOLINT
ErrorCode Set(Data data)
设置键的值并更新数据库 (Set the key's value and update the database).

◆ operator=() [3/3]

template<typename Data >
Key & LibXR::Database::Key< Data >::operator= ( Key< Data > && other)
delete

禁止移动赋值数据库键对象 (Move assignment is disabled for database keys).

Parameters
other被转移的键对象 (Database key to move from).
Returns
当前键对象引用 (Reference to the current key object).

◆ Save()

template<typename Data >
ErrorCode LibXR::Database::Key< Data >::Save ( )
inline

保存当前键值到数据库 (Save the current key value to the database).

Returns
操作结果 (Operation result).

Definition at line 148 of file interface.hpp.

148{ return database_.Set(*this, this->raw_data_); }
RawData raw_data_
原始数据 (Raw data associated with the key).
Definition interface.hpp:34
virtual ErrorCode Set(KeyBase &key, RawData data)=0
设置数据库中的键值 (Set the key's value in the database).

◆ Set()

template<typename Data >
ErrorCode LibXR::Database::Key< Data >::Set ( Data data)
inline

设置键的值并更新数据库 (Set the key's value and update the database).

Parameters
data需要存储的新值 (New value to store).
Returns
操作结果 (Operation result).

Definition at line 156 of file interface.hpp.

157 {
158 data_ = data;
159 return Save();
160 }
ErrorCode Save()
保存当前键值到数据库 (Save the current key value to the database).

Field Documentation

◆ data_

template<typename Data >
Data LibXR::Database::Key< Data >::data_

键存储的数据 (The data stored in the key).

Definition at line 54 of file interface.hpp.

◆ database_

template<typename Data >
Database& LibXR::Database::Key< Data >::database_

关联的数据库对象 (Reference to the associated database).

Definition at line 55 of file interface.hpp.


The documentation for this class was generated from the following file: