libxr  1.0
Want to be the best embedded framework
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
 
FsNodeFindNode (const char *name)
 查找直属子节点 / Find a direct child node
 
FileFindFile (const char *name)
 查找直属文件 / Find a direct child file
 
FileFindFileRev (const char *name)
 递归查找文件 / Find a file recursively
 
DirFindDir (const char *name)
 查找直属目录,支持 "." 和 ".." / Find a direct child directory, supporting "." and ".."
 
DirFindDirRev (const char *name)
 递归查找目录,支持 "." 和 ".." / Find a directory recursively, supporting "." and ".."
 
CustomFindCustom (const char *name)
 查找直属自定义节点 / Find a direct child custom node
 
CustomFindCustomRev (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
 

Private Member Functions

 Dir ()
 构造一个空目录壳 / Construct one empty directory shell
 
 Dir (const char *name)
 构造一个具名目录壳 / Construct one named directory shell
 
void AddNode (FsNode &node)
 把一个节点挂到当前目录下 / Attach one node under the current directory
 
FsNodeFindNodeByType (const char *name, FsNodeType type)
 在当前目录按类型查找直属节点 / Find one direct child node of a given type
 
FsNodeFindNodeRevByType (const char *name, FsNodeType type)
 递归查找指定类型节点 / Find one node of a given type recursively
 

Private Attributes

Tree rbt_
 当前目录直属子节点的名称索引树 / Name index tree of direct child nodes.
 

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_ = 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

目录节点片段 / Directory-node fragment

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

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

Definition at line 9 of file ramfs.hpp.

Constructor & Destructor Documentation

◆ Dir() [1/2]

RamFS::Dir::Dir ( )
private

构造一个空目录壳 / Construct one empty directory shell

构造一个空目录壳 Construct one empty directory shell

Definition at line 110 of file ramfs.cpp.

Tree rbt_
当前目录直属子节点的名称索引树 / Name index tree of direct child nodes.
Definition ramfs.hpp:128
FsNode(FsNodeType node_type)
用指定节点类型构造基类部分 / Construct the base node with a given node type
Definition ramfs.cpp:47
@ DIR
目录 / Directory
static int CompareStr(const char *const &a, const char *const &b)
RamFS 名称比较函数 / Name comparator used by RamFS trees.
Definition ramfs.cpp:20

◆ Dir() [2/2]

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

构造一个具名目录壳 / Construct one named directory shell

构造一个具名目录壳 Construct one named directory shell

Parameters
name目录名称 / Directory name

Definition at line 117 of file ramfs.cpp.

117: Dir() { this->name_ = DuplicateName(name); }
Dir()
构造一个空目录壳 / Construct one empty directory shell
Definition ramfs.cpp:110
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

◆ 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.

◆ AddNode()

void RamFS::Dir::AddNode ( FsNode & node)
private

把一个节点挂到当前目录下 / Attach one node under the current directory

把一个节点挂到当前目录下 Attach one node under the current directory

Parameters
node待挂接节点 / Node to attach

Definition at line 124 of file ramfs.cpp.

125{
126 ASSERT(node.name_ != nullptr);
127 ASSERT(FindNode(node.name_) == nullptr);
128 node.parent_ = this;
129 rbt_.Insert(node.tree_node_, node.name_);
130}
Tree::Node< FsNode * > tree_node_
当前节点挂进目录树时使用的树节点包装 / Tree node wrapper used when inserted into a directory tree.
Definition fs_node.hpp:46
Dir * parent_
父目录;根目录保持为空 / Parent directory; stays null for the root.
Definition fs_node.hpp:26
const char * name_
节点名称缓冲区 / Retained node-name buffer.
Definition fs_node.hpp:24
void Insert(BaseNode &node, KeyType &&key)
在树中插入新节点 (Insert a new node into the tree).
Definition rbt.hpp:235
FsNode * FindNode(const char *name)
查找直属子节点 / Find a direct child node
Definition ramfs.cpp:139

◆ 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 298 of file ramfs.cpp.

299{
300 return static_cast<Custom*>(FindNodeByType(name, FsNodeType::CUSTOM));
301}
RamFS 的自定义节点片段 / Custom-node fragment of RamFS
Definition custom.hpp:10
FsNode * FindNodeByType(const char *name, FsNodeType type)
在当前目录按类型查找直属节点 / Find one direct child node of a given type
Definition ramfs.cpp:158
@ 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 310 of file ramfs.cpp.

311{
312 return static_cast<Custom*>(FindNodeRevByType(name, FsNodeType::CUSTOM));
313}
FsNode * FindNodeRevByType(const char *name, FsNodeType type)
递归查找指定类型节点 / Find one node of a given type recursively
Definition ramfs.cpp:181

◆ 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 244 of file ramfs.cpp.

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

◆ 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 271 of file ramfs.cpp.

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

◆ 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 220 of file ramfs.cpp.

221{
222 return static_cast<File*>(FindNodeByType(name, FsNodeType::FILE));
223}
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 232 of file ramfs.cpp.

233{
234 return static_cast<File*>(FindNodeRevByType(name, FsNodeType::FILE));
235}

◆ 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 139 of file ramfs.cpp.

140{
141 if (name == nullptr)
142 {
143 return nullptr;
144 }
145
146 auto* node = rbt_.Search<FsNode*>(name);
147 return node != nullptr ? node->data_ : nullptr;
148}
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

◆ FindNodeByType()

RamFS::FsNode * RamFS::Dir::FindNodeByType ( const char * name,
FsNodeType type )
private

在当前目录按类型查找直属节点 / Find one direct child node of a given type

在当前目录按类型查找直属节点 Find one direct child node of a given type

Parameters
name节点名称 / Node name
type目标节点类型 / Desired node type
Returns
找到的节点;未找到返回 nullptr / Matching node, or nullptr
Parameters
name节点名称 / Node name
type目标节点类型 / Desired node type
Returns
找到的节点;未找到返回 nullptr Matching node, or nullptr if not found

Definition at line 158 of file ramfs.cpp.

159{
160 auto* ans = FindNode(name);
161 if (ans == nullptr || ans->GetNodeType() != type)
162 {
163 return nullptr;
164 }
165 return ans;
166}

◆ FindNodeRevByType()

RamFS::FsNode * RamFS::Dir::FindNodeRevByType ( const char * name,
FsNodeType type )
private

递归查找指定类型节点 / Find one node of a given type recursively

递归查找指定类型节点 Find one node of a given type recursively

Parameters
name节点名称 / Node name
type目标节点类型 / Desired node type
Returns
找到的节点;未找到返回 nullptr / Matching node, or nullptr
Parameters
name节点名称 / Node name
type目标节点类型 / Desired node type
Returns
找到的节点;未找到返回 nullptr Matching node, or nullptr if not found
Note
当前实现先检查直属节点;若未命中,再通过局部 visitor 继续深入直属子目录。 The current implementation first checks direct children; if that misses, it continues descending into direct child directories through a local visitor.

Definition at line 181 of file ramfs.cpp.

182{
183 auto* ans = FindNodeByType(name, type);
184 if (ans != nullptr)
185 {
186 return ans;
187 }
188
189 struct FindNodeRevFn
190 {
191 const char* name_;
192 FsNodeType type_;
193 FsNode*& ans_;
194
195 ErrorCode operator()(Tree::Node<FsNode*>& item)
196 {
197 auto* node = item.data_;
198 if (node->GetNodeType() != FsNodeType::DIR)
199 {
200 return ErrorCode::OK;
201 }
202
203 ans_ = static_cast<Dir*>(node)->FindNodeRevByType(name_, type_);
204 return ans_ != nullptr ? ErrorCode::FAILED : ErrorCode::OK;
205 }
206 };
207
208 FindNodeRevFn find{name, type, ans};
209 rbt_.Foreach<FsNode*>(find);
210 return ans;
211}
ErrorCode Foreach(Func func)
遍历红黑树并执行用户提供的操作 (Traverse the Red-Black Tree and apply a user-defined function).
Definition rbt.hpp:271
ErrorCode
定义错误码枚举

◆ 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.

Field Documentation

◆ rbt_

Tree LibXR::RamFS::Dir::rbt_
private

当前目录直属子节点的名称索引树 / Name index tree of direct child nodes.

Definition at line 128 of file ramfs.hpp.


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