libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::RawData Class Reference

可写原始数据视图 / Mutable raw data view More...

#include <libxr_type.hpp>

Public Member Functions

 RawData (void *addr, size_t size)
 使用指定地址和大小构造 RawData 对象。 Constructs a RawData object with the specified address and size.
 
 RawData ()=default
 默认构造函数,初始化为空数据。 Default constructor initializing to empty data.
 
template<typename DataType >
requires (!std::is_const_v<DataType> && !std::is_same_v<std::remove_cvref_t<DataType>, RawData>)
 RawData (DataType &data)
 从可写对象构造视图 / Construct a view from a writable object
 
 RawData (const RawData &data)=default
 拷贝构造函数。 Copy constructor.
 
 RawData (char *data)
 char * 指针构造 RawData,数据大小为字符串长度(不含 \0)。 Constructs RawData from a char * pointer, with size set to the string length (excluding \0).
 
template<size_t N>
 RawData (char(&data)[N])
 从可写字符数组构造文本视图 / Construct a text view from a writable char array
 
 RawData (std::string &data)
 从可写字符串构造文本视图 / Construct a text view from a writable string
 
RawDataoperator= (const RawData &data)=default
 赋值运算符重载。 Overloaded assignment operator.
 

Data Fields

void * addr_ = nullptr
 数据起始地址 / Data start address
 
size_t size_ = 0
 数据字节数 / Data size in bytes
 

Detailed Description

可写原始数据视图 / Mutable raw data view

Note
该类型不拥有数据,仅保存起始地址和字节数。调用方需要保证被引用对象在视图使用期间 保持有效且可写。 / This type does not own the data. It only stores the start address and byte count. The caller must keep the referenced object alive and writable while the view is in use.

Definition at line 43 of file libxr_type.hpp.

Constructor & Destructor Documentation

◆ RawData() [1/6]

LibXR::RawData::RawData ( void * addr,
size_t size )
inline

使用指定地址和大小构造 RawData 对象。 Constructs a RawData object with the specified address and size.

Parameters
addr数据的起始地址。 The starting address of the data.
size数据的大小(字节)。 The size of the data (in bytes).

Definition at line 55 of file libxr_type.hpp.

55: addr_(addr), size_(size) {}
size_t size_
数据字节数 / Data size in bytes
void * addr_
数据起始地址 / Data start address

◆ RawData() [2/6]

template<typename DataType >
requires (!std::is_const_v<DataType> && !std::is_same_v<std::remove_cvref_t<DataType>, RawData>)
LibXR::RawData::RawData ( DataType & data)
inline

从可写对象构造视图 / Construct a view from a writable object

Template Parameters
DataType对象类型 / Object type
Parameters
data被引用对象 / Referenced object

Definition at line 71 of file libxr_type.hpp.

71 : addr_(&data), size_(sizeof(DataType))
72 {
73 }

◆ RawData() [3/6]

LibXR::RawData::RawData ( const RawData & data)
default

拷贝构造函数。 Copy constructor.

Parameters
data另一个 RawData 对象。 Another RawData object.

◆ RawData() [4/6]

LibXR::RawData::RawData ( char * data)
inline

char * 指针构造 RawData,数据大小为字符串长度(不含 \0)。 Constructs RawData from a char * pointer, with size set to the string length (excluding \0).

Parameters
dataC 风格字符串指针。 A C-style string pointer.

Definition at line 92 of file libxr_type.hpp.

92: addr_(data), size_(data != nullptr ? std::strlen(data) : 0) {}

◆ RawData() [5/6]

template<size_t N>
LibXR::RawData::RawData ( char(&) data[N])
inline

从可写字符数组构造文本视图 / Construct a text view from a writable char array

Template Parameters
N数组长度 / Array length
Parameters
data被引用字符数组 / Referenced char array
Note
若数组最后一个字符恰为 \\0,则仅裁掉这一个尾随终止符;否则保留整个数组长度。 / If the last array element is \\0, only that trailing terminator is trimmed; otherwise the full array extent is kept.

Definition at line 104 of file libxr_type.hpp.

104 : addr_(data), size_(Detail::TrailingNulTrimmedArraySize(data))
105 {
106 }

◆ RawData() [6/6]

LibXR::RawData::RawData ( std::string & data)
inlineexplicit

从可写字符串构造文本视图 / Construct a text view from a writable string

Parameters
data被引用字符串 / Referenced string

Definition at line 112 of file libxr_type.hpp.

113 : addr_(data.empty() ? nullptr : data.data()), size_(data.size())
114 {
115 }

Member Function Documentation

◆ operator=()

RawData & LibXR::RawData::operator= ( const RawData & data)
default

赋值运算符重载。 Overloaded assignment operator.

Parameters
data另一个 RawData 对象。 Another RawData object.
Returns
返回赋值后的 RawData 对象引用。 Returns a reference to the assigned RawData object.

Field Documentation

◆ addr_

void* LibXR::RawData::addr_ = nullptr

数据起始地址 / Data start address

Definition at line 128 of file libxr_type.hpp.

◆ size_

size_t LibXR::RawData::size_ = 0

数据字节数 / Data size in bytes

Definition at line 129 of file libxr_type.hpp.


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