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

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

#include <ramfs.hpp>

Inheritance diagram for LibXR::RamFS::File:
[legend]
Collaboration diagram for LibXR::RamFS::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 LibXR::RamFS::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_
 当前文件存储形态 / Current file storage kind.
 

Friends

class RamFS
 

Additional Inherited Members

- Protected Member Functions inherited from LibXR::RamFS::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 LibXR::RamFS::FsNode
const char * name_ = nullptr
 节点名称缓冲区 / Retained node-name buffer.
 
FsNodeType type_
 节点运行时类型 / Runtime node type.
 
Dirparent_
 父目录;根目录保持为空 / Parent directory; stays null for the root.
 
Tree::Node< FsNode * > tree_node_
 

Detailed Description

文件节点片段 / File-node fragment

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

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

Definition at line 9 of file ramfs.hpp.

Member Typedef Documentation

◆ ExecFun

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

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

Definition at line 110 of file ramfs.hpp.

Constructor & Destructor Documentation

◆ File() [1/2]

RamFS::File::File ( )
private

构造一个空文件壳 / Construct one empty file shell

构造一个空文件壳 Construct one empty file shell

Definition at line 63 of file ramfs.cpp.

63: FsNode(FsNodeType::FILE), addr_(nullptr), arg_(nullptr), size_(0) {}
size_t size_
数据负载字节数 / Payload size in bytes.
Definition ramfs.hpp:190
void * arg_
可执行文件上下文块 / Executable context block.
Definition ramfs.hpp:189
void * addr_
可写数据地址 / Writable payload address.
Definition ramfs.hpp:184
FsNode(FsNodeType node_type)
用指定节点类型构造基类部分 / Construct the base node with a given node type
Definition ramfs.cpp:47

◆ File() [2/2]

RamFS::File::File ( const char * name)
explicitprivate

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

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

Parameters
name文件名 / File name

Definition at line 70 of file ramfs.cpp.

70: File() { this->name_ = DuplicateName(name); }
File()
构造一个空文件壳 / Construct one empty file shell
Definition ramfs.cpp:63
const char * name_
节点名称缓冲区 / Retained node-name buffer.
Definition ramfs.hpp:25
static char * DuplicateName(const char *name)
复制并持有一个节点名称 / Duplicate and retain one node name
Definition ramfs.cpp:29

Member Function Documentation

◆ Data() [1/4]

template<typename DataType , SizeLimitMode LimitMode = SizeLimitMode::MORE>
decltype(auto) LibXR::RamFS::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 52 of file ramfs.hpp.

55 : uint8_t
56 {
57 READ_ONLY,
59 EXEC,
60 };
61
@ READ_ONLY
只读外部数据映射 / Read-only external-data view
@ READ_WRITE
可写外部数据映射 / Read-write external-data view
@ EXEC
可执行命令入口 / Executable command entry

◆ Data() [2/4]

RawData LibXR::RamFS::File::Data ( )
inlinenodiscard

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

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

Definition at line 95 of file ramfs.hpp.

◆ Data() [3/4]

template<typename DataType , SizeLimitMode LimitMode = SizeLimitMode::MORE>
decltype(auto) LibXR::RamFS::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 79 of file ramfs.hpp.

◆ Data() [4/4]

ConstRawData LibXR::RamFS::File::Data ( ) const
inlinenodiscard

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

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

Definition at line 101 of file ramfs.hpp.

◆ DataAccessPanic()

static void LibXR::RamFS::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 122 of file ramfs.hpp.

134{
143class RamFS
144{
145 public:
153 RamFS(const char* name = "ramfs");
154
158 enum class FsNodeType : uint8_t
159 {
160 FILE,
161 DIR,
162 CUSTOM,
163 };
164
165 class Dir;
166
167 private:
171 using Tree = RBTree<const char*>;
172
176 enum class FileType : uint8_t
177 {
178 READ_ONLY,
179 READ_WRITE,
180 EXEC,
181 };
182
190 static int CompareStr(const char* const& a, const char* const& b);
191
192 public:
196#include "fs_node.hpp"
200#include "file.hpp"
204#include "custom.hpp"
208#include "dir.hpp"
212#include "factory.hpp"
213
214 private:
224 static char* DuplicateName(const char* name);
225};
226} // namespace LibXR
RamFS 的目录节点片段 / Directory-node fragment of RamFS
Definition dir.hpp:9
RamFS(const char *name="ramfs")
构造 RamFS,并创建根目录和 bin 目录 / Construct RamFS with root and bin directories
Definition ramfs.cpp:10
FsNodeType
文件系统节点类型 / File-system node type
Definition ramfs.hpp:38
@ CUSTOM
用户自定义节点 / User-defined node
@ DIR
目录 / Directory
RBTree< const char * > Tree
RamFS 目录索引树类型 / Directory index tree type used by RamFS.
Definition ramfs.hpp:50
static int CompareStr(const char *const &a, const char *const &b)
RamFS 名称比较函数 / Name comparator used by RamFS trees.
Definition ramfs.cpp:20
FileType
文件内部存储形态 / Internal storage kind of one file node
Definition ramfs.hpp:56

◆ IsExecutable()

bool LibXR::RamFS::File::IsExecutable ( ) const
inlinenodiscard

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

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

Definition at line 28 of file ramfs.hpp.

◆ IsReadOnly()

bool LibXR::RamFS::File::IsReadOnly ( ) const
inlinenodiscard

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

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

Definition at line 16 of file ramfs.hpp.

◆ IsReadWrite()

bool LibXR::RamFS::File::IsReadWrite ( ) const
inlinenodiscard

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

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

Definition at line 22 of file ramfs.hpp.

◆ ReadableDataPtr()

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

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

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

Definition at line 135 of file ramfs.hpp.

147{
156class RamFS
157{
158 public:
166 RamFS(const char* name = "ramfs");
167
171 enum class FsNodeType : uint8_t
172 {
173 FILE,
174 DIR,
175 CUSTOM,
176 };
177
178 class Dir;
179
180 private:
184 using Tree = RBTree<const char*>;
185
189 enum class FileType : uint8_t
190 {
191 READ_ONLY,
192 READ_WRITE,
193 EXEC,
194 };
195
203 static int CompareStr(const char* const& a, const char* const& b);
204
205 public:
209#include "fs_node.hpp"
213#include "file.hpp"
217#include "custom.hpp"
221#include "dir.hpp"
225#include "factory.hpp"
226
227 private:
237 static char* DuplicateName(const char* name);
238};
239} // namespace LibXR

◆ Run()

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

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

执行可执行文件节点 Run one executable file node

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

Definition at line 79 of file ramfs.cpp.

80{
81 ASSERT(file_type_ == FileType::EXEC);
82 ASSERT(exec_ != nullptr);
83 return exec_(arg_, argc, argv);
84}
ExecFun exec_
可执行入口函数 / Executable entry function.
Definition ramfs.hpp:186
FileType file_type_
当前文件存储形态 / Current file storage kind.
Definition ramfs.hpp:191

◆ WritableDataPtr()

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

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

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

Definition at line 155 of file ramfs.hpp.

167{
176class RamFS
177{
178 public:
186 RamFS(const char* name = "ramfs");
187
191 enum class FsNodeType : uint8_t
192 {
193 FILE,
194 DIR,
195 CUSTOM,
196 };
197
198 class Dir;
199
200 private:
204 using Tree = RBTree<const char*>;
205
209 enum class FileType : uint8_t
210 {
211 READ_ONLY,
212 READ_WRITE,
213 EXEC,
214 };
215
223 static int CompareStr(const char* const& a, const char* const& b);
224
225 public:
229#include "fs_node.hpp"
233#include "file.hpp"
237#include "custom.hpp"
241#include "dir.hpp"
245#include "factory.hpp"
246
247 private:
257 static char* DuplicateName(const char* name);
258};
259} // namespace LibXR

Friends And Related Symbol Documentation

◆ RamFS

friend class RamFS
friend

Definition at line 194 of file ramfs.hpp.

Field Documentation

◆ [union]

union { ... } LibXR::RamFS::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* LibXR::RamFS::File::addr_

可写数据地址 / Writable payload address.

Definition at line 184 of file ramfs.hpp.

◆ addr_const_

const void* LibXR::RamFS::File::addr_const_

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

Definition at line 185 of file ramfs.hpp.

◆ arg_

void* LibXR::RamFS::File::arg_ = nullptr
private

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

Definition at line 189 of file ramfs.hpp.

◆ exec_

ExecFun LibXR::RamFS::File::exec_

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

Definition at line 186 of file ramfs.hpp.

◆ file_type_

FileType LibXR::RamFS::File::file_type_
private
Initial value:

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

Definition at line 191 of file ramfs.hpp.

◆ size_

size_t LibXR::RamFS::File::size_ = 0
private

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

Definition at line 190 of file ramfs.hpp.


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