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

RamFS 的文件节点片段 / File-node fragment of RamFS More...

#include <file.hpp>

Inheritance diagram for File:
[legend]
Collaboration diagram for File:
[legend]

Public Member Functions

bool IsReadOnly () const
 判断文件是否只读 / Check whether the file is read-only
 
bool IsReadWrite () const
 判断文件是否可写 / Check whether the file is writable
 
bool IsExecutable () const
 判断文件是否可执行 / Check whether the file is executable
 
int Run (int argc, char **argv)
 执行可执行文件 / Run an executable file
 
template<typename DataType , SizeLimitMode LimitMode = SizeLimitMode::MORE>
decltype(auto) Data ()
 访问类型化数据 / Access typed data
 
template<typename DataType , SizeLimitMode LimitMode = SizeLimitMode::MORE>
decltype(auto) Data () const
 从 const 文件对象访问类型化只读数据 / Access typed read-only data from a const file object
 
RawData Data ()
 访问可写原始数据,要求文件为 READ_WRITE / Access writable raw data; requires READ_WRITE
 
ConstRawData Data () const
 访问只读原始数据 / Access read-only raw data
 
- Public Member Functions inherited from FsNode
FsNodeType GetNodeType () const
 获取节点类型 / Get the node type
 
const char * GetName () const
 获取节点名称 / Get the node name
 

Private Types

using ExecFun = int (*)(void* raw, int argc, char** argv)
 可执行文件调用入口类型 / Executable entry function type
 

Private Member Functions

template<typename DataType >
const DataType * ReadableDataPtr () const
 获取只读数据地址 Get the readable data pointer
 
template<typename DataType >
DataType * WritableDataPtr ()
 获取可写数据地址 Get the writable data pointer
 
 File ()
 构造一个空文件壳 / Construct one empty file shell
 
 File (const char *name)
 构造一个具名文件壳 / Construct one named file shell
 

Static Private Member Functions

static void DataAccessPanic ()
 处理不应到达的 File 数据访问路径 Handle one File data-access path that should be unreachable
 

Private Attributes

union { 
 
   void *   addr_ 
 可写数据地址 / Writable payload address. More...
 
   const void *   addr_const_ 
 只读数据地址 / Read-only payload address. More...
 
   ExecFun   exec_ 
 可执行入口函数 / Executable entry function. More...
 
};  
 文件负载联合体 / File payload union
 
void * arg_ = nullptr
 可执行文件上下文块 / Executable context block.
 
size_t size_ = 0
 数据负载字节数 / Payload size in bytes.
 
FileType file_type_ = FileType::READ_ONLY
 当前文件存储形态 / Current file storage kind.
 

Friends

class RamFS
 

Additional Inherited Members

- Protected Member Functions inherited from FsNode
 FsNode (FsNodeType node_type)
 用指定节点类型构造基类部分 / Construct the base node with a given node type
 
 FsNode (const FsNode &other)
 拷贝构造节点基类部分 / Copy-construct the base-node portion
 
FsNodeoperator= (const FsNode &)=delete
 
- Protected Attributes inherited from FsNode
const char * name_ = nullptr
 节点名称缓冲区 / Retained node-name buffer.
 
FsNodeType type_
 节点运行时类型 / Runtime node type.
 
Dirparent_ = nullptr
 父目录;根目录保持为空 / Parent directory; stays null for the root.
 
Tree::Node< FsNode * > tree_node_
 当前节点挂进目录树时使用的树节点包装 / Tree node wrapper used when inserted into a directory tree.
 

Detailed Description

RamFS 的文件节点片段 / File-node fragment of RamFS

内存文件或可执行文件 / Memory file or executable file

Definition at line 8 of file file.hpp.

Member Typedef Documentation

◆ ExecFun

using File::ExecFun = int (*)(void* raw, int argc, char** argv)
private

可执行文件调用入口类型 / Executable entry function type

Definition at line 112 of file file.hpp.

Constructor & Destructor Documentation

◆ File()

File::File ( const char * name)
explicitprivate

构造一个具名文件壳 / Construct one named file shell

Parameters
name文件名 / File name

Member Function Documentation

◆ Data() [1/4]

template<typename DataType , SizeLimitMode LimitMode = SizeLimitMode::MORE>
decltype(auto) File::Data ( )
inline

访问类型化数据 / Access typed data

Data<T>() 返回可写引用并要求 READ_WRITE / Data<T>() returns a writable reference and requires READ_WRITE. Data<const T>() 返回只读引用 / Data<const T>() returns a read-only reference for both READ_ONLY and READ_WRITE.

Template Parameters
DataType数据类型;使用 const T 表示只读访问 / Data type; use const T for read-only access.
LimitMode大小检查模式 / Size-check mode
Returns
类型化数据引用 / Typed data reference

Definition at line 51 of file file.hpp.

52 {
53 using RequestedType = std::remove_reference_t<DataType>;
54 using StoredType = std::remove_cv_t<RequestedType>;
55 static_assert(!std::is_reference_v<DataType>);
56 static_assert(!std::is_volatile_v<RequestedType>);
57
58 ASSERT(LibXR::SizeLimitCheck(LimitMode, sizeof(StoredType), size_));
59 if constexpr (std::is_const_v<RequestedType>)
60 {
62 }
63 else
64 {
66 }
67 }
DataType * WritableDataPtr()
获取可写数据地址 Get the writable data pointer
Definition file.hpp:157
const DataType * ReadableDataPtr() const
获取只读数据地址 Get the readable data pointer
Definition file.hpp:137
size_t size_
数据负载字节数 / Payload size in bytes.
Definition file.hpp:192
constexpr bool SizeLimitCheck(SizeLimitMode mode, size_t limit, size_t size) noexcept
尺寸约束的纯判断函数

◆ Data() [2/4]

RawData File::Data ( )
inlinenodiscard

访问可写原始数据,要求文件为 READ_WRITE / Access writable raw data; requires READ_WRITE

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

Definition at line 94 of file file.hpp.

95 {
96 return RawData(WritableDataPtr<void>(), size_);
97 }

◆ Data() [3/4]

template<typename DataType , SizeLimitMode LimitMode = SizeLimitMode::MORE>
decltype(auto) File::Data ( ) const
inline

从 const 文件对象访问类型化只读数据 / Access typed read-only data from a const file object

Template Parameters
DataType数据类型 / Data type
LimitMode大小检查模式 / Size-check mode
Returns
类型化只读数据引用 / Typed read-only data reference

Definition at line 78 of file file.hpp.

79 {
80 using RequestedType = std::remove_reference_t<DataType>;
81 using StoredType = std::remove_cv_t<RequestedType>;
82 static_assert(!std::is_reference_v<DataType>);
83 static_assert(!std::is_volatile_v<RequestedType>);
84
85 ASSERT(LibXR::SizeLimitCheck(LimitMode, sizeof(StoredType), size_));
87 }

◆ Data() [4/4]

ConstRawData File::Data ( ) const
inlinenodiscard

访问只读原始数据 / Access read-only raw data

Returns
只读原始数据视图 / Read-only raw data view

Definition at line 103 of file file.hpp.

104 {
105 return ConstRawData(ReadableDataPtr<void>(), size_);
106 }

◆ DataAccessPanic()

static void File::DataAccessPanic ( )
inlinestaticprivate

处理不应到达的 File 数据访问路径 Handle one File data-access path that should be unreachable

Note
这里保留强约束终止语义,但不再依赖“断言后继续解引用空指针”来满足返回类型, 从而避免发布构建中的未定义行为。 This keeps the strong-failure semantics while no longer relying on "assert then dereference a null pointer" to satisfy the return type, avoiding undefined behavior in release builds.

Definition at line 124 of file file.hpp.

125 {
126 REQUIRE(false);
127 std::abort();
128 }

◆ IsExecutable()

bool File::IsExecutable ( ) const
inlinenodiscard

判断文件是否可执行 / Check whether the file is executable

Returns
可执行返回 true / True if the file is executable

Definition at line 27 of file file.hpp.

27{ return file_type_ == FileType::EXEC; }
FileType file_type_
当前文件存储形态 / Current file storage kind.
Definition file.hpp:193

◆ IsReadOnly()

bool File::IsReadOnly ( ) const
inlinenodiscard

判断文件是否只读 / Check whether the file is read-only

Returns
只读返回 true / True if the file is read-only

Definition at line 15 of file file.hpp.

15{ return file_type_ == FileType::READ_ONLY; }

◆ IsReadWrite()

bool File::IsReadWrite ( ) const
inlinenodiscard

判断文件是否可写 / Check whether the file is writable

Returns
可写返回 true / True if the file is writable

Definition at line 21 of file file.hpp.

21{ return file_type_ == FileType::READ_WRITE; }

◆ ReadableDataPtr()

template<typename DataType >
const DataType * File::ReadableDataPtr ( ) const
inlineprivate

获取只读数据地址 Get the readable data pointer

Template Parameters
DataType目标数据类型 / Target data type
Returns
只读数据指针 / Read-only data pointer

Definition at line 137 of file file.hpp.

138 {
139 if (file_type_ == FileType::READ_WRITE)
140 {
141 return static_cast<const DataType*>(addr_);
142 }
143 if (file_type_ == FileType::READ_ONLY)
144 {
145 return static_cast<const DataType*>(addr_const_);
146 }
148 }
const void * addr_const_
只读数据地址 / Read-only payload address.
Definition file.hpp:187
void * addr_
可写数据地址 / Writable payload address.
Definition file.hpp:186
static void DataAccessPanic()
处理不应到达的 File 数据访问路径 Handle one File data-access path that should be unreachable
Definition file.hpp:124

◆ Run()

int File::Run ( int argc,
char ** argv )

执行可执行文件 / Run an executable file

Parameters
argc参数数量 / Argument count
argv参数数组 / Argument vector
Returns
执行返回值 / Execution return value

◆ WritableDataPtr()

template<typename DataType >
DataType * File::WritableDataPtr ( )
inlineprivate

获取可写数据地址 Get the writable data pointer

Template Parameters
DataType目标数据类型 / Target data type
Returns
可写数据指针 / Writable data pointer

Definition at line 157 of file file.hpp.

158 {
159 if (file_type_ != FileType::READ_WRITE)
160 {
162 }
163 return static_cast<DataType*>(addr_);
164 }

Friends And Related Symbol Documentation

◆ RamFS

friend class RamFS
friend

Definition at line 195 of file file.hpp.

Field Documentation

◆ [union]

union { ... } File

文件负载联合体 / File payload union

The same storage is interpreted either as mutable data, const data, or an executable entry depending on file_type_. 这块存储会根据 file_type_ 被解释成可写数据、只读数据或可执行入口。

◆ addr_

void* File::addr_

可写数据地址 / Writable payload address.

Definition at line 186 of file file.hpp.

◆ addr_const_

const void* File::addr_const_

只读数据地址 / Read-only payload address.

Definition at line 187 of file file.hpp.

◆ arg_

void* File::arg_ = nullptr
private

可执行文件上下文块 / Executable context block.

Definition at line 191 of file file.hpp.

◆ exec_

ExecFun File::exec_

可执行入口函数 / Executable entry function.

Definition at line 188 of file file.hpp.

◆ file_type_

FileType File::file_type_ = FileType::READ_ONLY
private

当前文件存储形态 / Current file storage kind.

Definition at line 193 of file file.hpp.

◆ size_

size_t File::size_ = 0
private

数据负载字节数 / Payload size in bytes.

Definition at line 192 of file file.hpp.


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