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

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

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

142{
143 auto ans = FindDevice(name);
144 if (ans)
145 {
146 return ans;
147 }
148
149 struct FindDevRevFn
150 {
151 const char *name;
152 RamFS::Device *&ans;
153 ErrorCode operator()(RBTree<const char *>::Node<RamFS::FsNode> &item) const
154 {
155 RamFS::FsNode &node = item;
156 if (node.type == FsNodeType::DIR)
157 {
158 auto *dir = reinterpret_cast<RamFS::Dir *>(&item);
159
160 auto d = dir->FindDevice(name);
161 if (d)
162 {
163 ans = d;
164 return ErrorCode::FAILED;
165 }
166
167 dir->data_.rbt.Foreach<RamFS::FsNode>(FindDevRevFn{name, ans});
168 return ans ? ErrorCode::FAILED : ErrorCode::OK;
169 }
170 return ErrorCode::OK;
171 }
172 };
173
174 data_.rbt.Foreach<FsNode>(FindDevRevFn{name, ans});
175 return ans;
176}
Data data_
存储的数据 (Stored data).
Definition rbt.hpp:99
红黑树实现,支持泛型键和值,并提供线程安全操作 (Red-Black Tree implementation supporting generic keys and values with thread...
Definition rbt.hpp:24
设备类,继承自红黑树节点 DeviceNode Device class inheriting from Red-Black tree node DeviceNode
Definition ramfs.hpp:160
目录类,继承自 RBTree 节点,用于管理文件、子目录和设备 Directory class, inheriting from RBTree node, used for managing files...
Definition ramfs.hpp:229
Device * FindDevice(const char *name)
在当前目录中查找设备 Finds a device in the current directory
Definition ramfs.cpp:185
文件系统节点基类,所有文件和目录均继承自该类 Base class for file system nodes; all files and directories inherit from this
Definition ramfs.hpp:73

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

83{
84 if (name[0] == '.' && name[1] == '\0')
85 {
86 return this;
87 }
88
89 if (name[0] == '.' && name[1] == '.' && name[2] == '\0')
90 {
91 return reinterpret_cast<Dir *>(data_.parent);
92 }
93
94 auto ans = (*this)->rbt.Search<RamFS::FsNode>(name);
95
96 if (ans && (*ans)->type == FsNodeType::DIR)
97 {
98 return reinterpret_cast<Dir *>(ans);
99 }
100 else
101 {
102 return nullptr;
103 }
104}
@ DIR
目录 Directory

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

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

◆ 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 if (ans)
49 {
50 return ans;
51 }
52
53 struct FindFileRevFn
54 {
55 const char *name;
56 RamFS::File *&ans;
57 ErrorCode operator()(RBTree<const char *>::Node<RamFS::FsNode> &item) const
58 {
59 RamFS::FsNode &node = item;
60 if (node.type == FsNodeType::DIR)
61 {
62 auto *dir = reinterpret_cast<RamFS::Dir *>(&item);
63
64 auto f = dir->FindFile(name);
65 if (f)
66 {
67 ans = f;
68 return ErrorCode::FAILED;
69 }
70
71 dir->data_.rbt.Foreach<RamFS::FsNode>(FindFileRevFn{name, ans});
72 return ans ? ErrorCode::FAILED : ErrorCode::OK;
73 }
74 return ErrorCode::OK;
75 }
76 };
77
78 data_.rbt.Foreach<FsNode>(FindFileRevFn{name, ans});
79 return ans;
80}
红黑树的泛型数据节点,继承自 BaseNode (Generic data node for Red-Black Tree, inheriting from BaseNode).
Definition rbt.hpp:64
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: