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:
Collaboration diagram for LibXR::RamFS::Dir:

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
 
File * FindFile (const char *name)
 查找当前目录中的文件 Finds a file in the current directory
 
File * FindFileRev (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 249 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 277 of file ramfs.hpp.

278 {
279 (*this)->rbt.Insert(dev, dev->name);
280 dev->parent = this;
281 }
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值

◆ 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);
473 if (ans && ans->data_.type == FsNodeType::DEVICE)
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 {
430 auto ans = FindDevice(name);
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;
437 if (node.type == FsNodeType::DIR)
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 }
DirNode data_
存储的数据 (Stored data).
Definition rbt.hpp:99
Device * FindDevice(const char *name)
在当前目录中查找设备 Finds a device in the current directory
Definition ramfs.hpp:470
@ DIR
目录 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
367 if (ans && (*ans)->type == FsNodeType::DIR)
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 {
386 auto ans = FindDir(name);
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;
393 if (node.type == FsNodeType::DIR)
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
Definition ramfs.hpp:353

◆ 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);
293 if (ans && ans->data_.type == FsNodeType::FILE)
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 {
312 auto ans = FindFile(name);
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;
319 if (node.type == FsNodeType::DIR)
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
Definition ramfs.hpp:290

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