libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::RamFS::Dir Class Reference

目录节点片段 / Directory-node fragment More...

#include <ramfs.hpp>

Inheritance diagram for LibXR::RamFS::Dir:
[legend]
Collaboration diagram for LibXR::RamFS::Dir:
[legend]

Public Member Functions

void Add (File &file)
 添加直属文件节点 / Add a direct child file node
 
void Add (Dir &dir)
 添加直属目录节点 / Add a direct child directory node
 
void Add (Custom &custom)
 添加直属自定义节点 / Add a direct child custom node
 
FsNode * FindNode (const char *name)
 查找直属子节点 / Find a direct child node
 
File * FindFile (const char *name)
 查找直属文件 / Find a direct child file
 
File * FindFileRev (const char *name)
 递归查找文件 / Find a file recursively
 
Dir * FindDir (const char *name)
 查找直属目录,支持 "." 和 ".." / Find a direct child directory, supporting "." and ".."
 
Dir * FindDirRev (const char *name)
 递归查找目录,支持 "." 和 ".." / Find a directory recursively, supporting "." and ".."
 
Custom * FindCustom (const char *name)
 查找直属自定义节点 / Find a direct child custom node
 
Custom * FindCustomRev (const char *name)
 递归查找自定义节点 / Find a custom node recursively
 
template<typename Func >
ErrorCode Foreach (Func func)
 遍历直属子节点 / Iterate over direct child nodes
 
- Public Member Functions inherited from LibXR::RamFS::FsNode
FsNodeType GetNodeType () const
 获取节点类型 / Get the node type
 
const char * GetName () const
 获取节点名称 / Get the node name
 

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

Detailed Description

目录节点片段 / Directory-node fragment

RamFS 的目录节点片段 / Directory-node fragment of RamFS

目录节点,管理直属子节点 / Directory node that owns a child namespace

Definition at line 9 of file ramfs.hpp.

Member Function Documentation

◆ Add() [1/3]

void LibXR::RamFS::Dir::Add ( Custom & custom)
inline

添加直属自定义节点 / Add a direct child custom node

Parameters
custom自定义节点 / Custom node

Definition at line 28 of file ramfs.hpp.

◆ Add() [2/3]

void LibXR::RamFS::Dir::Add ( Dir & dir)
inline

添加直属目录节点 / Add a direct child directory node

Parameters
dir目录节点 / Directory node

Definition at line 22 of file ramfs.hpp.

◆ Add() [3/3]

void LibXR::RamFS::Dir::Add ( File & file)
inline

添加直属文件节点 / Add a direct child file node

Parameters
file文件节点 / File node

Definition at line 16 of file ramfs.hpp.

◆ FindCustom()

RamFS::Custom * RamFS::Dir::FindCustom ( const char * name)

查找直属自定义节点 / Find a direct child custom node

查找直属自定义节点 Find one direct child custom node

Parameters
name节点名称 / Node name
Returns
自定义节点指针;未找到返回 nullptr / Custom node pointer, or nullptr
Parameters
name节点名称 / Node name
Returns
自定义节点;未找到返回 nullptr Custom node, or nullptr if not found

Definition at line 293 of file ramfs.cpp.

294{
295 return static_cast<Custom*>(FindNodeByType(name, FsNodeType::CUSTOM));
296}
RamFS 的自定义节点片段 / Custom-node fragment of RamFS
Definition custom.hpp:10
@ CUSTOM
用户自定义节点 / User-defined node

◆ FindCustomRev()

RamFS::Custom * RamFS::Dir::FindCustomRev ( const char * name)

递归查找自定义节点 / Find a custom node recursively

递归查找自定义节点 Find one custom node recursively

Parameters
name节点名称 / Node name
Returns
自定义节点指针;未找到返回 nullptr / Custom node pointer, or nullptr
Parameters
name节点名称 / Node name
Returns
自定义节点;未找到返回 nullptr Custom node, or nullptr if not found

Definition at line 305 of file ramfs.cpp.

306{
307 return static_cast<Custom*>(FindNodeRevByType(name, FsNodeType::CUSTOM));
308}

◆ FindDir()

RamFS::Dir * RamFS::Dir::FindDir ( const char * name)

查找直属目录,支持 "." 和 ".." / Find a direct child directory, supporting "." and ".."

查找直属目录节点,支持 "." 和 ".." Find one direct child directory node, supporting "." and ".."

Parameters
name目录名 / Directory name
Returns
目录指针;未找到返回 nullptr / Directory pointer, or nullptr
Parameters
name目录名称 / Directory name
Returns
目录节点;未找到返回 nullptr Directory node, or nullptr if not found

Definition at line 239 of file ramfs.cpp.

240{
241 if (name == nullptr)
242 {
243 return nullptr;
244 }
245
246 if (name[0] == '.' && name[1] == '\0')
247 {
248 return this;
249 }
250
251 if (name[0] == '.' && name[1] == '.' && name[2] == '\0')
252 {
253 return parent_;
254 }
255
256 return static_cast<Dir*>(FindNodeByType(name, FsNodeType::DIR));
257}
RamFS 的目录节点片段 / Directory-node fragment of RamFS
Definition dir.hpp:9
Dir * parent_
父目录;根目录保持为空 / Parent directory; stays null for the root.
Definition ramfs.hpp:27
@ DIR
目录 / Directory

◆ FindDirRev()

RamFS::Dir * RamFS::Dir::FindDirRev ( const char * name)

递归查找目录,支持 "." 和 ".." / Find a directory recursively, supporting "." and ".."

递归查找目录节点,支持 "." 和 ".." Find one directory node recursively, supporting "." and ".."

Parameters
name目录名 / Directory name
Returns
目录指针;未找到返回 nullptr / Directory pointer, or nullptr
Parameters
name目录名称 / Directory name
Returns
目录节点;未找到返回 nullptr Directory node, or nullptr if not found

Definition at line 266 of file ramfs.cpp.

267{
268 if (name == nullptr)
269 {
270 return nullptr;
271 }
272
273 if (name[0] == '.' && name[1] == '\0')
274 {
275 return this;
276 }
277
278 if (name[0] == '.' && name[1] == '.' && name[2] == '\0')
279 {
280 return parent_;
281 }
282
283 return static_cast<Dir*>(FindNodeRevByType(name, FsNodeType::DIR));
284}

◆ FindFile()

RamFS::File * RamFS::Dir::FindFile ( const char * name)

查找直属文件 / Find a direct child file

查找直属文件节点 Find one direct child file node

Parameters
name文件名 / File name
Returns
文件指针;未找到返回 nullptr / File pointer, or nullptr
Parameters
name文件名 / File name
Returns
文件节点;未找到返回 nullptr File node, or nullptr if not found

Definition at line 215 of file ramfs.cpp.

216{
217 return static_cast<File*>(FindNodeByType(name, FsNodeType::FILE));
218}
RamFS 的文件节点片段 / File-node fragment of RamFS
Definition file.hpp:9

◆ FindFileRev()

RamFS::File * RamFS::Dir::FindFileRev ( const char * name)

递归查找文件 / Find a file recursively

递归查找文件节点 Find one file node recursively

Parameters
name文件名 / File name
Returns
文件指针;未找到返回 nullptr / File pointer, or nullptr
Parameters
name文件名 / File name
Returns
文件节点;未找到返回 nullptr File node, or nullptr if not found

Definition at line 227 of file ramfs.cpp.

228{
229 return static_cast<File*>(FindNodeRevByType(name, FsNodeType::FILE));
230}

◆ FindNode()

RamFS::FsNode * RamFS::Dir::FindNode ( const char * name)

查找直属子节点 / Find a direct child node

在当前目录查找直属子节点 Find one direct child node in the current directory

Parameters
name节点名称 / Node name
Returns
子节点指针;未找到返回 nullptr / Child node pointer, or nullptr
Parameters
name节点名称 / Node name
Returns
找到的节点;未找到返回 nullptr Matching node, or nullptr if not found

Definition at line 134 of file ramfs.cpp.

135{
136 if (name == nullptr)
137 {
138 return nullptr;
139 }
140
141 auto* node = rbt_.Search<FsNode*>(name);
142 return node != nullptr ? node->data_ : nullptr;
143}
RamFS 的公共节点基类片段 / Common node-base fragment of RamFS
Definition fs_node.hpp:9
Node< Data > * Search(const Key &key)
搜索红黑树中的节点 / Search for a node in the Red-Black Tree.
Definition rbt.hpp:120

◆ Foreach()

template<typename Func >
ErrorCode LibXR::RamFS::Dir::Foreach ( Func func)
inline

遍历直属子节点 / Iterate over direct child nodes

Template Parameters
Func回调类型 / Callback type
Parameters
func回调函数,返回非 OK 时停止遍历 / Callback; non-OK stops iteration
Returns
遍历结果 / Iteration result

Definition at line 88 of file ramfs.hpp.

Friends And Related Symbol Documentation

◆ RamFS

friend class RamFS
friend

Definition at line 130 of file ramfs.hpp.


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