Shkyera Engine
Easy to use, game engine for Python
Filesystem.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <filesystem>
4 #include <map>
5 #include <memory>
6 #include <string>
7 #include <vector>
8 
9 namespace shkyera {
10 
16 
21 class File {
22  public:
28  File(std::filesystem::path path);
29 
35  std::filesystem::path getPath() const;
36 
42  std::string getName() const;
43 
44  std::string getNameWithoutExtension() const;
45 
51  FILE_TYPE getType() const;
52 
53  private:
54  std::filesystem::path _path;
56 };
57 
62 class Directory {
63  public:
69  Directory(std::filesystem::path path);
70 
74  void update();
75 
81  std::string getName() const;
82 
88  std::filesystem::path getPath() const;
89 
95  std::vector<std::shared_ptr<Directory>> getSubDirectories() const;
96 
102  std::vector<std::shared_ptr<File>> getFiles() const;
103 
109  void createDirectory(std::string name);
110 
116  void createFile(std::string name);
117 
123  static void setRoot(std::shared_ptr<Directory> root);
124 
130  static std::shared_ptr<Directory> getRoot();
131 
138  static std::shared_ptr<File> getFile(std::filesystem::path path);
139 
140  private:
141  std::filesystem::path _path;
142  std::vector<std::shared_ptr<File>> _files;
143  std::vector<std::shared_ptr<Directory>> _directories;
144 
145  static std::shared_ptr<Directory> _rootDirectory;
146  static std::map<std::filesystem::path, std::shared_ptr<File>> _mapFiles;
147 };
148 
149 } // namespace shkyera
A class representing a directory in the filesystem.
Definition: Filesystem.hpp:62
static std::map< std::filesystem::path, std::shared_ptr< File > > _mapFiles
Map of file paths to file objects.
Definition: Filesystem.hpp:146
std::vector< std::shared_ptr< File > > getFiles() const
Get a list of files within this directory.
Definition: Filesystem.cpp:47
std::filesystem::path _path
The path to the directory.
Definition: Filesystem.hpp:141
std::vector< std::shared_ptr< Directory > > _directories
List of subdirectories in the directory.
Definition: Filesystem.hpp:143
static std::shared_ptr< File > getFile(std::filesystem::path path)
Get a file by its path from the filesystem.
Definition: Filesystem.cpp:72
static std::shared_ptr< Directory > _rootDirectory
The root directory of the filesystem.
Definition: Filesystem.hpp:145
std::vector< std::shared_ptr< File > > _files
List of files in the directory.
Definition: Filesystem.hpp:142
Directory(std::filesystem::path path)
Constructor for a Directory object.
Definition: Filesystem.cpp:24
void update()
Update the content of the directory by listing subdirectories and files.
Definition: Filesystem.cpp:26
static void setRoot(std::shared_ptr< Directory > root)
Set the root directory of the filesystem.
Definition: Filesystem.cpp:69
std::vector< std::shared_ptr< Directory > > getSubDirectories() const
Get a list of subdirectories within this directory.
Definition: Filesystem.cpp:46
static std::shared_ptr< Directory > getRoot()
Get the root directory of the filesystem.
Definition: Filesystem.cpp:70
std::string getName() const
Get the name of the directory.
Definition: Filesystem.cpp:44
void createFile(std::string name)
Create a new file within this directory.
Definition: Filesystem.cpp:59
void createDirectory(std::string name)
Create a new subdirectory within this directory.
Definition: Filesystem.cpp:49
std::filesystem::path getPath() const
Get the path to the directory.
Definition: Filesystem.cpp:45
A class representing a file in the filesystem.
Definition: Filesystem.hpp:21
FILE_TYPE getType() const
Get the type of the file.
Definition: Filesystem.cpp:22
std::string getNameWithoutExtension() const
Definition: Filesystem.cpp:21
std::filesystem::path getPath() const
Get the path to the file.
Definition: Filesystem.cpp:19
std::filesystem::path _path
The path to the file.
Definition: Filesystem.hpp:54
File(std::filesystem::path path)
Constructor for a File object.
Definition: Filesystem.cpp:8
FILE_TYPE _type
The type of the file.
Definition: Filesystem.hpp:55
std::string getName() const
Get the name of the file, including the extension.
Definition: Filesystem.cpp:20
Definition: Entity.cpp:3
FILE_TYPE
An enumeration representing file types.
Definition: Filesystem.hpp:15
@ IMAGE
Definition: Filesystem.hpp:15
@ OTHER
Definition: Filesystem.hpp:15
@ PYTHON
Definition: Filesystem.hpp:15