Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::filesystem::VFSResourceRegistry Class Reference

A resource registry for both Files & Directories. More...

#include <vfsresource.h>

Inheritance diagram for MaxOS::filesystem::VFSResourceRegistry:
MaxOS::processes::BaseResourceRegistry

Public Member Functions

 VFSResourceRegistry (VirtualFileSystem *vfs)
 Construct a new VFS Resource Registry object.
 
processes::Resourceget_resource (const string &name) final
 Gets a resource from the registry by name.
 
processes::Resourcecreate_resource (const string &name, size_t flags) final
 Try to create a new resource with the specified name, will fail if the name is in use.
 

Detailed Description

A resource registry for both Files & Directories.

Definition at line 72 of file vfsresource.h.

Constructor & Destructor Documentation

◆ VFSResourceRegistry()

VFSResourceRegistry::VFSResourceRegistry ( VirtualFileSystem vfs)
explicit

Construct a new VFS Resource Registry object.

Parameters
vfsThe virtual file system to use

Definition at line 324 of file vfsresource.cpp.

325: BaseResourceRegistry(resource_type_t::FILESYSTEM),
326 m_vfs(vfs)
327{
328
329}
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
Manages the creation, retention and destruction of resources of a certain type. Should be subclassed ...
Definition resource.h:54

Member Function Documentation

◆ create_resource()

Resource * VFSResourceRegistry::create_resource ( const string name,
size_t  flags 
)
finalvirtual

Try to create a new resource with the specified name, will fail if the name is in use.

Parameters
nameThe name of the resource to create
flagsOptional flags to pass (unused by default but registry type specific)
Returns
The resource created or nullptr if failed to create the resource

Reimplemented from MaxOS::processes::BaseResourceRegistry.

Definition at line 394 of file vfsresource.cpp.

394 {
395
396 string path = Path::absolute_path(name);
398
399 // Resource already opened
401 if(resource != nullptr)
402 return resource;
403
404 // Open the resource
405 bool is_file = Path::is_file(path);
406 if(is_file)
407 return open_as_resource(path, m_vfs->create_file(path));
408 else
409 return open_as_resource(path, m_vfs->create_directory(path));
410
411}
static bool is_file(const string &path)
Check if a path is a file.
Definition path.cpp:42
static string join_path(const string &base, const string &extended)
Joins two paths together.
Definition path.cpp:208
static string absolute_path(const string &path)
Calculates path with out any "../" or "./".
Definition path.cpp:170
Directory * create_directory(string path)
Attempts to open the parent directory and creates the sub directory at the end of the path.
Definition vfs.cpp:293
File * create_file(const string &path)
Attempts to open the parent directory and create the file at the end of the path.
Definition vfs.cpp:425
virtual Resource * get_resource(const string &name)
Gets a resource from the registry by name.
Definition resource.cpp:128
static Process * current_process()
Gets the process on the currently executing core.

References MaxOS::filesystem::Path::absolute_path(), MaxOS::filesystem::VirtualFileSystem::create_directory(), MaxOS::filesystem::VirtualFileSystem::create_file(), MaxOS::processes::GlobalScheduler::current_process(), MaxOS::processes::BaseResourceRegistry::get_resource(), MaxOS::filesystem::Path::is_file(), and MaxOS::filesystem::Path::join_path().

◆ get_resource()

Resource * VFSResourceRegistry::get_resource ( const string name)
finalvirtual

Gets a resource from the registry by name.

Parameters
nameThe name of the resource to find
Returns
The resource or nullptr if the resource was not found

Reimplemented from MaxOS::processes::BaseResourceRegistry.

Definition at line 376 of file vfsresource.cpp.

376 {
377
378 string path = Path::absolute_path(name);
380
381 // Resource already opened
383 if(resource != nullptr)
384 return resource;
385
386 // Open the resource
387 bool is_file = Path::is_file(path);
388 if(is_file)
389 return open_as_resource(path, m_vfs->open_file(path));
390 else
391 return open_as_resource(path, m_vfs->open_directory(path));
392}
Directory * open_directory(const string &path)
Try to open a directory on the virtual file system and read it's contents.
Definition vfs.cpp:245
File * open_file(const string &path, size_t offset=0)
Try to open a file on the virtual file system with a given offset.
Definition vfs.cpp:459

References MaxOS::filesystem::Path::absolute_path(), MaxOS::processes::GlobalScheduler::current_process(), MaxOS::processes::BaseResourceRegistry::get_resource(), MaxOS::filesystem::Path::is_file(), MaxOS::filesystem::Path::join_path(), MaxOS::filesystem::VirtualFileSystem::open_directory(), and MaxOS::filesystem::VirtualFileSystem::open_file().


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