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

只读原始数据视图 / Immutable raw data view More...

#include <libxr_type.hpp>

Public Member Functions

 ConstRawData (const void *addr, size_t size)
 使用指定地址和大小构造 ConstRawData 对象。 Constructs a ConstRawData object with the specified address and size.
 
 ConstRawData ()=default
 默认构造函数,初始化为空数据。 Default constructor initializing to empty data.
 
template<typename DataType >
requires (!std::is_pointer_v<std::remove_cvref_t<DataType>> && !std::is_same_v<std::remove_cvref_t<DataType>, ConstRawData> && !std::is_same_v<std::remove_cvref_t<DataType>, RawData>)
 ConstRawData (const DataType &data)
 从任意对象构造只读视图 / Construct a read-only view from any object
 
 ConstRawData (const ConstRawData &data)=default
 拷贝构造函数。 Copy constructor.
 
 ConstRawData (const RawData &data)
 RawData 构造 ConstRawData,数据地址和大小保持不变。 Constructs ConstRawData from RawData, keeping the same data address and size.
 
template<typename CharPtr >
requires (std::is_pointer_v<std::remove_reference_t<CharPtr>> && std::is_same_v<std::remove_cv_t< std::remove_pointer_t<std::remove_reference_t<CharPtr>>>, char> && !std::is_volatile_v<std::remove_pointer_t<std::remove_reference_t<CharPtr>>>)
 ConstRawData (CharPtr data)
 char* / const char* 文本指针构造 ConstRawData,数据大小为字符串长度(不含 \0)。 Constructs ConstRawData from a char* / const char* text pointer, with size set to the string length (excluding \0).
 
 ConstRawData (const std::string &data)
 从只读字符串构造文本视图 / Construct a text view from a read-only string
 
 ConstRawData (std::string_view data)
 从字符串视图构造文本视图 / Construct a text view from a string view
 
template<size_t N>
 ConstRawData (char(&data)[N])
 从字符数组构造 ConstRawData;若最后一个字符是 \\0,仅忽略这一尾随终止符。
 
template<size_t N>
 ConstRawData (const char(&data)[N])
 
ConstRawDataoperator= (const ConstRawData &data)=default
 赋值运算符重载。 Overloaded assignment operator.
 

Data Fields

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

Detailed Description

只读原始数据视图 / Immutable 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 while the view is in use.

Definition at line 141 of file libxr_type.hpp.

Constructor & Destructor Documentation

◆ ConstRawData() [1/9]

LibXR::ConstRawData::ConstRawData ( const void * addr,
size_t size )
inline

使用指定地址和大小构造 ConstRawData 对象。 Constructs a ConstRawData 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 153 of file libxr_type.hpp.

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

◆ ConstRawData() [2/9]

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

从任意对象构造只读视图 / Construct a read-only view from any object

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

Definition at line 170 of file libxr_type.hpp.

171 : addr_(reinterpret_cast<const DataType*>(&data)), size_(sizeof(DataType))
172 {
173 }

◆ ConstRawData() [3/9]

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

拷贝构造函数。 Copy constructor.

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

◆ ConstRawData() [4/9]

LibXR::ConstRawData::ConstRawData ( const RawData & data)
inline

RawData 构造 ConstRawData,数据地址和大小保持不变。 Constructs ConstRawData from RawData, keeping the same data address and size.

Parameters
dataRawData 对象。 A RawData object.

Definition at line 192 of file libxr_type.hpp.

192: addr_(data.addr_), size_(data.size_) {}

◆ ConstRawData() [5/9]

template<typename CharPtr >
requires (std::is_pointer_v<std::remove_reference_t<CharPtr>> && std::is_same_v<std::remove_cv_t< std::remove_pointer_t<std::remove_reference_t<CharPtr>>>, char> && !std::is_volatile_v<std::remove_pointer_t<std::remove_reference_t<CharPtr>>>)
LibXR::ConstRawData::ConstRawData ( CharPtr data)
inline

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

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

Definition at line 208 of file libxr_type.hpp.

209 : addr_(data),
210 size_(data != nullptr ? std::strlen(static_cast<const char*>(data)) : 0)
211 {
212 }

◆ ConstRawData() [6/9]

LibXR::ConstRawData::ConstRawData ( const std::string & data)
inlineexplicit

从只读字符串构造文本视图 / Construct a text view from a read-only string

Parameters
data被引用字符串 / Referenced string

Definition at line 218 of file libxr_type.hpp.

219 : addr_(data.empty() ? nullptr : data.data()), size_(data.size())
220 {
221 }

◆ ConstRawData() [7/9]

LibXR::ConstRawData::ConstRawData ( std::string_view data)
inlineexplicit

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

Parameters
data被引用字符串视图 / Referenced string view

Definition at line 227 of file libxr_type.hpp.

228 : addr_(data.empty() ? nullptr : data.data()), size_(data.size())
229 {
230 }

◆ ConstRawData() [8/9]

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

从字符数组构造 ConstRawData;若最后一个字符是 \\0,仅忽略这一尾随终止符。

Constructs ConstRawData from a character array; if the last element is \\0, only that trailing terminator is ignored.

Template Parameters
N数组大小。 The array size.
Parameters
data需要存储的字符数组。 The character array to be stored.

Definition at line 243 of file libxr_type.hpp.

244 : addr_(reinterpret_cast<const void*>(data)),
245 size_(Detail::TrailingNulTrimmedArraySize(data))
246 {
247 }

◆ ConstRawData() [9/9]

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

Definition at line 250 of file libxr_type.hpp.

251 : addr_(reinterpret_cast<const void*>(data)),
252 size_(Detail::TrailingNulTrimmedArraySize(data))
253 {
254 }

Member Function Documentation

◆ operator=()

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

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

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

Field Documentation

◆ addr_

const void* LibXR::ConstRawData::addr_ = nullptr

数据起始地址 / Data start address

Definition at line 267 of file libxr_type.hpp.

◆ size_

size_t LibXR::ConstRawData::size_ = 0

数据字节数 / Data size in bytes

Definition at line 268 of file libxr_type.hpp.


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