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

目录类,继承自 RBTree 节点,用于管理文件、子目录和设备 Directory class, inheriting from RBTree node, used for managing files, subdirectories, and devices 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)
 添加文件到当前目录 Adds a file to the current directory
 
void Add (Dir &dir)
 添加子目录到当前目录 Adds a subdirectory to the current directory
 
void Add (Device &dev)
 添加设备到当前目录 Adds a device to the current directory
 
FileFindFile (const char *name)
 查找当前目录中的文件 Finds a file in the current directory
 
FileFindFileRev (const char *name)
 递归查找文件 Recursively searches for a file
 
DirFindDir (const char *name)
 查找当前目录中的子目录 Finds a subdirectory in the current directory
 
DirFindDirRev (const char *name)
 递归查找子目录 Recursively searches for a subdirectory
 
DeviceFindDeviceRev (const char *name)
 递归查找设备 Recursively searches for a device
 
DeviceFindDevice (const char *name)
 在当前目录中查找设备 Finds a device in the current directory
 
- Public Member Functions inherited from LibXR::RBTree< Key >::Node< DirNode >
 Node ()
 默认构造函数,初始化数据为空 (Default constructor initializing an empty node).
 
 Node (const DirNode &data)
 使用指定数据构造节点 (Constructor initializing a node with the given data).
 
 Node (Args... args)
 通过参数列表构造节点 (Constructor initializing a node using arguments list).
 
 operator DirNode & ()
 
Nodeoperator= (const DirNode &data)
 
DirNode * operator-> ()
 
const DirNode * operator-> () const
 
DirNode & operator* ()
 

Additional Inherited Members

- Data Fields inherited from LibXR::RBTree< Key >::Node< DirNode >
DirNode data_
 存储的数据 (Stored data).
 
- Data Fields inherited from LibXR::RBTree< Key >::BaseNode
Key key
 节点键值 (Key associated with the node).
 
RbtColor color
 节点颜色 (Color of the node).
 
BaseNodeleft = nullptr
 左子节点 (Left child node).
 
BaseNoderight = nullptr
 右子节点 (Right child node).
 
BaseNodeparent = nullptr
 父节点 (Parent node).
 
size_t size
 节点大小 (Size of the node).
 
- Protected Member Functions inherited from LibXR::RBTree< Key >::BaseNode
 BaseNode (size_t size)
 基本节点构造函数 (Constructor for BaseNode).
 

Detailed Description

目录类,继承自 RBTree 节点,用于管理文件、子目录和设备 Directory class, inheriting from RBTree node, used for managing files, subdirectories, and devices

Definition at line 228 of file ramfs.hpp.

Member Function Documentation

◆ Add() [1/3]

void LibXR::RamFS::Dir::Add ( Device & dev)
inline

添加设备到当前目录 Adds a device to the current directory

Parameters
dev要添加的设备 The device to be added

Definition at line 256 of file ramfs.hpp.

257 {
258 (*this)->rbt.Insert(dev, dev->name);
259 dev->parent = this;
260 }

◆ Add() [2/3]

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

添加子目录到当前目录 Adds a subdirectory to the current directory

Parameters
dir要添加的子目录 The subdirectory to be added

Definition at line 246 of file ramfs.hpp.

247 {
248 (*this)->rbt.Insert(dir, dir->name);
249 dir->parent = this;
250 }

◆ Add() [3/3]

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

添加文件到当前目录 Adds a file to the current directory

Parameters
file要添加的文件 The file to be added

Definition at line 236 of file ramfs.hpp.

237 {
238 (*this)->rbt.Insert(file, file->name);
239 file->parent = this;
240 }

◆ FindDevice()

RamFS::Device * RamFS::Dir::FindDevice ( const char * name)

在当前目录中查找设备 Finds a device in the current directory

Parameters
name设备名 The name of the device
Returns
Device* 指向设备的指针,如果未找到则返回 nullptr Pointer to the device, returns nullptr if not found

Definition at line 184 of file ramfs.cpp.

185{
186 auto ans = (*this)->rbt.Search<FsNode>(name);
187 if (ans && ans->data_.type == FsNodeType::DEVICE)
188 {
189 return reinterpret_cast<Device *>(ans);
190 }
191 else
192 {
193 return nullptr;
194 }
195}

◆ FindDeviceRev()

RamFS::Device * RamFS::Dir::FindDeviceRev ( const char * name)

递归查找设备 Recursively searches for a device

Parameters
name设备名 The name of the device
Returns
Device* 指向设备的指针,如果未找到则返回 nullptr Pointer to the device, returns nullptr if not found

Definition at line 142 of file ramfs.cpp.

143{
144 auto ans = FindDevice(name);
145
146 std::function<ErrorCode(RBTree<const char *>::Node<FsNode> &)> fun;
147
148 fun = [&](RBTree<const char *>::Node<FsNode> &item) -> ErrorCode
149 {
150 FsNode &node = item;
151 if (node.type == FsNodeType::DIR)
152 {
153 Dir *dir = reinterpret_cast<Dir *>(&item);
154
155 ans = dir->FindDevice(name);
156 if (ans)
157 {
158 return ErrorCode::FAILED;
159 }
160
161 dir->data_.rbt.Foreach<FsNode>([&](RBTree<const char *>::Node<FsNode> &child)
162 { return fun(child); });
163
164 return ans ? ErrorCode::FAILED : ErrorCode::OK;
165 }
166 return ErrorCode::OK;
167 };
168
169 if (ans == nullptr)
170 {
171 data_.rbt.Foreach<FsNode>([&](RBTree<const char *>::Node<FsNode> &item)
172 { return fun(item); });
173 }
174 return ans;
175}
红黑树的泛型数据节点,继承自 BaseNode (Generic data node for Red-Black Tree, inheriting from BaseNode).
Definition rbt.hpp:64
红黑树实现,支持泛型键和值,并提供线程安全操作 (Red-Black Tree implementation supporting generic keys and values with thread...
Definition rbt.hpp:24
Device * FindDevice(const char *name)
在当前目录中查找设备 Finds a device in the current directory
Definition ramfs.cpp:184
@ DIR
目录 Directory

◆ FindDir()

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

查找当前目录中的子目录 Finds a subdirectory in the current directory

Parameters
name目录名 The name of the directory
Returns
Dir* 指向目录的指针,如果未找到则返回 nullptr Pointer to the directory, returns nullptr if not found

Definition at line 81 of file ramfs.cpp.

82{
83 if (name[0] == '.' && name[1] == '\0')
84 {
85 return this;
86 }
87
88 if (name[0] == '.' && name[1] == '.' && name[2] == '\0')
89 {
90 return reinterpret_cast<Dir *>(data_.parent);
91 }
92
93 auto ans = (*this)->rbt.Search<RamFS::FsNode>(name);
94
95 if (ans && (*ans)->type == FsNodeType::DIR)
96 {
97 return reinterpret_cast<Dir *>(ans);
98 }
99 else
100 {
101 return nullptr;
102 }
103}
文件系统节点基类,所有文件和目录均继承自该类 Base class for file system nodes; all files and directories inherit from this
Definition ramfs.hpp:73

◆ FindDirRev()

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

递归查找子目录 Recursively searches for a subdirectory

Parameters
name目录名 The name of the directory
Returns
Dir* 指向目录的指针,如果未找到则返回 nullptr Pointer to the directory, returns nullptr if not found

Definition at line 105 of file ramfs.cpp.

106{
107 auto ans = FindDir(name);
108
109 std::function<ErrorCode(RBTree<const char *>::Node<FsNode> &)> fun;
110
111 fun = [&](RBTree<const char *>::Node<FsNode> &item) -> ErrorCode
112 {
113 FsNode &node = item;
114 if (node.type == FsNodeType::DIR)
115 {
116 Dir *dir = reinterpret_cast<Dir *>(&item);
117 if (strcmp(dir->data_.name, name) == 0)
118 {
119 ans = dir;
120 return ErrorCode::OK;
121 }
122 else
123 {
124 dir->data_.rbt.Foreach<FsNode>([&](RBTree<const char *>::Node<FsNode> &child)
125 { return fun(child); });
126
127 return ans ? ErrorCode::FAILED : ErrorCode::OK;
128 }
129 }
130 return ErrorCode::OK;
131 };
132
133 if (ans == nullptr)
134 {
135 data_.rbt.Foreach<FsNode>([&](RBTree<const char *>::Node<FsNode> &item)
136 { return fun(item); });
137 }
138
139 return ans;
140}
Dir * FindDir(const char *name)
查找当前目录中的子目录 Finds a subdirectory in the current directory
Definition ramfs.cpp:81

◆ FindFile()

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

查找当前目录中的文件 Finds a file in the current directory

Parameters
name文件名 The name of the file
Returns
File* 指向文件的指针,如果未找到则返回 nullptr Pointer to the file, returns nullptr if not found

Definition at line 32 of file ramfs.cpp.

33{
34 auto ans = (*this)->rbt.Search<FsNode>(name);
35 if (ans && ans->data_.type == FsNodeType::FILE)
36 {
37 return reinterpret_cast<File *>(ans);
38 }
39 else
40 {
41 return nullptr;
42 }
43}

◆ FindFileRev()

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

递归查找文件 Recursively searches for a file

Parameters
name文件名 The name of the file
Returns
File* 指向文件的指针,如果未找到则返回 nullptr Pointer to the file, returns nullptr if not found

Definition at line 45 of file ramfs.cpp.

46{
47 auto ans = FindFile(name);
48
49 std::function<ErrorCode(RBTree<const char *>::Node<FsNode> &)> fun;
50
51 fun = [&](RBTree<const char *>::Node<FsNode> &item) -> ErrorCode
52 {
53 FsNode &node = item;
54 if (node.type == FsNodeType::DIR)
55 {
56 Dir *dir = reinterpret_cast<Dir *>(&item);
57
58 ans = dir->FindFile(name);
59 if (ans)
60 {
61 return ErrorCode::FAILED;
62 }
63
64 dir->data_.rbt.Foreach<FsNode>([&](RBTree<const char *>::Node<FsNode> &child)
65 { return fun(child); });
66
67 return ans ? ErrorCode::FAILED : ErrorCode::OK;
68 }
69 return ErrorCode::OK;
70 };
71
72 if (ans == nullptr)
73 {
74 data_.rbt.Foreach<FsNode>([&](RBTree<const char *>::Node<FsNode> &item)
75 { return fun(item); });
76 }
77
78 return ans;
79}
File * FindFile(const char *name)
查找当前目录中的文件 Finds a file in the current directory
Definition ramfs.cpp:32

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