Shkyera Engine
Easy to use, game engine for Python
shkyera::Directory Class Reference

A class representing a directory in the filesystem. More...

#include <Filesystem.hpp>

Public Member Functions

 Directory (std::filesystem::path path)
 Constructor for a Directory object. More...
 
void update ()
 Update the content of the directory by listing subdirectories and files. More...
 
std::string getName () const
 Get the name of the directory. More...
 
std::filesystem::path getPath () const
 Get the path to the directory. More...
 
std::vector< std::shared_ptr< Directory > > getSubDirectories () const
 Get a list of subdirectories within this directory. More...
 
std::vector< std::shared_ptr< File > > getFiles () const
 Get a list of files within this directory. More...
 
void createDirectory (std::string name)
 Create a new subdirectory within this directory. More...
 
void createFile (std::string name)
 Create a new file within this directory. More...
 

Static Public Member Functions

static void setRoot (std::shared_ptr< Directory > root)
 Set the root directory of the filesystem. More...
 
static std::shared_ptr< DirectorygetRoot ()
 Get the root directory of the filesystem. More...
 
static std::shared_ptr< FilegetFile (std::filesystem::path path)
 Get a file by its path from the filesystem. More...
 

Private Attributes

std::filesystem::path _path
 The path to the directory. More...
 
std::vector< std::shared_ptr< File > > _files
 List of files in the directory. More...
 
std::vector< std::shared_ptr< Directory > > _directories
 List of subdirectories in the directory. More...
 

Static Private Attributes

static std::shared_ptr< Directory_rootDirectory = nullptr
 The root directory of the filesystem. More...
 
static std::map< std::filesystem::path, std::shared_ptr< File > > _mapFiles = {}
 Map of file paths to file objects. More...
 

Detailed Description

A class representing a directory in the filesystem.

Constructor & Destructor Documentation

◆ Directory()

shkyera::Directory::Directory ( std::filesystem::path  path)

Constructor for a Directory object.

Parameters
pathThe path to the directory.

Member Function Documentation

◆ createDirectory()

void shkyera::Directory::createDirectory ( std::string  name)

Create a new subdirectory within this directory.

Parameters
nameThe name of the new subdirectory.

◆ createFile()

void shkyera::Directory::createFile ( std::string  name)

Create a new file within this directory.

Parameters
nameThe name of the new file.

◆ getFile()

std::shared_ptr< File > shkyera::Directory::getFile ( std::filesystem::path  path)
static

Get a file by its path from the filesystem.

Parameters
pathThe path to the file.
Returns
The shared pointer to the file.

◆ getFiles()

std::vector< std::shared_ptr< File > > shkyera::Directory::getFiles ( ) const

Get a list of files within this directory.

Returns
A vector of shared pointers to files.

◆ getName()

std::string shkyera::Directory::getName ( ) const

Get the name of the directory.

Returns
The name of the directory.

◆ getPath()

std::filesystem::path shkyera::Directory::getPath ( ) const

Get the path to the directory.

Returns
The path to the directory.

◆ getRoot()

std::shared_ptr< Directory > shkyera::Directory::getRoot ( )
static

Get the root directory of the filesystem.

Returns
The shared pointer to the root directory.

◆ getSubDirectories()

std::vector< std::shared_ptr< Directory > > shkyera::Directory::getSubDirectories ( ) const

Get a list of subdirectories within this directory.

Returns
A vector of shared pointers to subdirectories.

◆ setRoot()

void shkyera::Directory::setRoot ( std::shared_ptr< Directory root)
static

Set the root directory of the filesystem.

Parameters
rootThe shared pointer to the root directory.

◆ update()

void shkyera::Directory::update ( )

Update the content of the directory by listing subdirectories and files.

Member Data Documentation

◆ _directories

std::vector<std::shared_ptr<Directory> > shkyera::Directory::_directories
private

List of subdirectories in the directory.

◆ _files

std::vector<std::shared_ptr<File> > shkyera::Directory::_files
private

List of files in the directory.

◆ _mapFiles

std::map< std::filesystem::path, std::shared_ptr< File > > shkyera::Directory::_mapFiles = {}
staticprivate

Map of file paths to file objects.

◆ _path

std::filesystem::path shkyera::Directory::_path
private

The path to the directory.

◆ _rootDirectory

std::shared_ptr< Directory > shkyera::Directory::_rootDirectory = nullptr
staticprivate

The root directory of the filesystem.


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