目录类,继承自 RBTree 节点,用于管理文件、子目录和设备 Directory class, inheriting from RBTree node, used for managing files, subdirectories, and devices
More...
#include <ramfs.hpp>
|
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
|
|
File * | FindFile (const char *name) |
| 查找当前目录中的文件 Finds a file in the current directory
|
|
File * | FindFileRev (const char *name) |
| 递归查找文件 Recursively searches for a file
|
|
Dir * | FindDir (const char *name) |
| 查找当前目录中的子目录 Finds a subdirectory in the current directory
|
|
Dir * | FindDirRev (const char *name) |
| 递归查找子目录 Recursively searches for a subdirectory
|
|
Device * | FindDeviceRev (const char *name) |
| 递归查找设备 Recursively searches for a device
|
|
Device * | FindDevice (const char *name) |
| 在当前目录中查找设备 Finds a device in the current directory
|
|
| 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 & () |
|
Node & | operator= (const DirNode &data) |
|
DirNode * | operator-> () |
|
const DirNode * | operator-> () const |
|
DirNode & | operator* () |
|
目录类,继承自 RBTree 节点,用于管理文件、子目录和设备 Directory class, inheriting from RBTree node, used for managing files, subdirectories, and devices
Definition at line 249 of file ramfs.hpp.
◆ 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 277 of file ramfs.hpp.
278 {
279 (*this)->rbt.Insert(dev, dev->name);
280 dev->parent = this;
281 }
◆ 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 267 of file ramfs.hpp.
268 {
269 (*this)->rbt.Insert(dir, dir->name);
270 dir->parent = this;
271 }
◆ 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 257 of file ramfs.hpp.
258 {
259 (*this)->rbt.Insert(file, file->name);
260 file->parent = this;
261 }
◆ FindDevice()
Device * LibXR::RamFS::Dir::FindDevice |
( |
const char * | name | ) |
|
|
inline |
在当前目录中查找设备 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 470 of file ramfs.hpp.
471 {
472 auto ans = (*this)->rbt.Search<FsNode>(name);
474 {
475 return reinterpret_cast<Device *>(ans);
476 }
477 else
478 {
479 return nullptr;
480 }
481 }
◆ FindDeviceRev()
Device * LibXR::RamFS::Dir::FindDeviceRev |
( |
const char * | name | ) |
|
|
inline |
递归查找设备 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 428 of file ramfs.hpp.
429 {
431
432 std::function<ErrorCode(RBTree<const char *>::Node<FsNode> &)> fun;
433
434 fun = [&](RBTree<const char *>::Node<FsNode> &item) -> ErrorCode
435 {
436 FsNode &node = item;
438 {
439 Dir *dir = reinterpret_cast<Dir *>(&item);
440
441 ans = dir->FindDevice(name);
442 if (ans)
443 {
444 return ErrorCode::FAILED;
445 }
446
447 dir->data_.rbt.Foreach<FsNode>([&](RBTree<const char *>::Node<FsNode> &child)
448 { return fun(child); });
449
450 return ans ? ErrorCode::FAILED : ErrorCode::OK;
451 }
452 return ErrorCode::OK;
453 };
454
455 if (ans == nullptr)
456 {
457 data_.rbt.Foreach<FsNode>([&](RBTree<const char *>::Node<FsNode> &item)
458 { return fun(item); });
459 }
460 return ans;
461 }
Device * FindDevice(const char *name)
在当前目录中查找设备 Finds a device in the current directory
◆ FindDir()
Dir * LibXR::RamFS::Dir::FindDir |
( |
const char * | name | ) |
|
|
inline |
查找当前目录中的子目录 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 353 of file ramfs.hpp.
354 {
355 if (name[0] == '.' && name[1] == '\0')
356 {
357 return this;
358 }
359
360 if (name[0] == '.' && name[1] == '.' && name[2] == '\0')
361 {
362 return reinterpret_cast<Dir *
>(
data_.parent);
363 }
364
365 auto ans = (*this)->rbt.Search<RamFS::FsNode>(name);
366
368 {
369 return reinterpret_cast<Dir *>(ans);
370 }
371 else
372 {
373 return nullptr;
374 }
375 }
◆ FindDirRev()
Dir * LibXR::RamFS::Dir::FindDirRev |
( |
const char * | name | ) |
|
|
inline |
递归查找子目录 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 384 of file ramfs.hpp.
385 {
387
388 std::function<ErrorCode(RBTree<const char *>::Node<FsNode> &)> fun;
389
390 fun = [&](RBTree<const char *>::Node<FsNode> &item) -> ErrorCode
391 {
392 FsNode &node = item;
394 {
395 Dir *dir = reinterpret_cast<Dir *>(&item);
396 if (strcmp(dir->data_.name, name) == 0)
397 {
398 ans = dir;
399 return ErrorCode::OK;
400 }
401 else
402 {
403 dir->data_.rbt.Foreach<FsNode>([&](RBTree<const char *>::Node<FsNode> &child)
404 { return fun(child); });
405
406 return ans ? ErrorCode::FAILED : ErrorCode::OK;
407 }
408 }
409 return ErrorCode::OK;
410 };
411
412 if (ans == nullptr)
413 {
414 data_.rbt.Foreach<FsNode>([&](RBTree<const char *>::Node<FsNode> &item)
415 { return fun(item); });
416 }
417
418 return ans;
419 }
Dir * FindDir(const char *name)
查找当前目录中的子目录 Finds a subdirectory in the current directory
◆ FindFile()
File * LibXR::RamFS::Dir::FindFile |
( |
const char * | name | ) |
|
|
inline |
查找当前目录中的文件 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 290 of file ramfs.hpp.
291 {
292 auto ans = (*this)->rbt.Search<FsNode>(name);
294 {
295 return reinterpret_cast<File *>(ans);
296 }
297 else
298 {
299 return nullptr;
300 }
301 }
◆ FindFileRev()
File * LibXR::RamFS::Dir::FindFileRev |
( |
const char * | name | ) |
|
|
inline |
递归查找文件 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 310 of file ramfs.hpp.
311 {
313
314 std::function<ErrorCode(RBTree<const char *>::Node<FsNode> &)> fun;
315
316 fun = [&](RBTree<const char *>::Node<FsNode> &item) -> ErrorCode
317 {
318 FsNode &node = item;
320 {
321 Dir *dir = reinterpret_cast<Dir *>(&item);
322
323 ans = dir->FindFile(name);
324 if (ans)
325 {
326 return ErrorCode::FAILED;
327 }
328
329 dir->data_.rbt.Foreach<FsNode>([&](RBTree<const char *>::Node<FsNode> &child)
330 { return fun(child); });
331
332 return ans ? ErrorCode::FAILED : ErrorCode::OK;
333 }
334 return ErrorCode::OK;
335 };
336
337 if (ans == nullptr)
338 {
339 data_.rbt.Foreach<FsNode>([&](RBTree<const char *>::Node<FsNode> &item)
340 { return fun(item); });
341 }
342
343 return ans;
344 }
File * FindFile(const char *name)
查找当前目录中的文件 Finds a file in the current directory
The documentation for this class was generated from the following file: