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

Handles a group of files (directory) More...

#include <filesystem.h>

Inheritance diagram for MaxOS::filesystem::Directory:
MaxOS::filesystem::format::Fat32Directory MaxOS::filesystem::format::ext2::Ext2Directory

Public Member Functions

virtual ~Directory ()
 Destructor for Directory, frees all files and subdirectories.
 
virtual void read_from_disk ()
 read the directory from the disk
 
common::Vector< File * > files ()
 Get the files in the directory.
 
common::Vector< Directory * > subdirectories ()
 Get the subdirectories in the directory.
 
Fileopen_file (const string &name)
 Open a file in the directory.
 
Directoryopen_subdirectory (const string &name)
 Open a directory in the directory.
 
virtual Filecreate_file (const string &name)
 Create a file in the directory.
 
virtual void remove_file (const string &name)
 Delete a file in the directory.
 
void rename_file (File *file, const string &new_name)
 Rename a file in the directory.
 
virtual void rename_file (const string &old_name, const string &new_name)
 Rename a file in the directory.
 
void rename_subdirectory (Directory *directory, const string &new_name)
 Rename a subdirectory in the directory.
 
virtual void rename_subdirectory (const string &old_name, const string &new_name)
 Rename a subdirectory in the directory.
 
virtual Directorycreate_subdirectory (const string &name)
 Create a directory in the directory.
 
virtual void remove_subdirectory (const string &name)
 Try to remove a directory in the directory.
 
string name ()
 Get the name of the directory.
 
size_t size ()
 Get the size of the directory.
 

Protected Attributes

common::Vector< File * > m_files
 The files in this directory.
 
common::Vector< Directory * > m_subdirectories
 The subdirectories in this directory.
 
string m_name
 The name of this directory.
 

Detailed Description

Handles a group of files (directory)

Definition at line 57 of file filesystem.h.

Constructor & Destructor Documentation

◆ ~Directory()

Directory::~Directory ( )
virtual

Destructor for Directory, frees all files and subdirectories.

Definition at line 100 of file filesystem.cpp.

100 {
101
102 // Free the files
103 for (auto &file: m_files)
104 delete file;
105
106 // Free the subdirectories
107 for (auto &subdirectory: m_subdirectories)
109
110}
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
common::Vector< Directory * > m_subdirectories
The subdirectories in this directory.
Definition filesystem.h:60
common::Vector< File * > m_files
The files in this directory.
Definition filesystem.h:59

References m_files, and m_subdirectories.

Member Function Documentation

◆ create_file()

File * Directory::create_file ( const string name)
virtual

Create a file in the directory.

Parameters
nameThe name of the file to create
Returns
A new file object or null if it could not be created

Reimplemented in MaxOS::filesystem::format::ext2::Ext2Directory, and MaxOS::filesystem::format::Fat32Directory.

Definition at line 151 of file filesystem.cpp.

151 {
152 return nullptr;
153}

Referenced by MaxOS::filesystem::DirectoryResource::write().

◆ create_subdirectory()

Directory * Directory::create_subdirectory ( const string name)
virtual

Create a directory in the directory.

Parameters
nameThe name of the directory to create
Returns
The new directory object or null if it could not be created

Reimplemented in MaxOS::filesystem::format::ext2::Ext2Directory, and MaxOS::filesystem::format::Fat32Directory.

Definition at line 197 of file filesystem.cpp.

197 {
198 return nullptr;
199}

Referenced by MaxOS::filesystem::DirectoryResource::write().

◆ files()

common::Vector< File * > Directory::files ( )

Get the files in the directory.

Returns
A list of all the files in the directory

Definition at line 124 of file filesystem.cpp.

124 {
125 return m_files;
126}

References m_files.

◆ name()

◆ open_file()

File * Directory::open_file ( const string name)

Open a file in the directory.

Parameters
nameThe name of the file to open
Returns

Definition at line 134 of file filesystem.cpp.

134 {
135
136 // Try to find the file
137 for (auto &file: m_files)
138 if (file->name() == name)
139 return file;
140
141 // File not found
142 return nullptr;
143}
string name()
Get the name of the directory.

References m_files, and name().

Referenced by MaxOS::filesystem::FileSystem::exists().

◆ open_subdirectory()

Directory * Directory::open_subdirectory ( const string name)

Open a directory in the directory.

Parameters
nameThe name of the directory to open
Returns
The directory object or null if it could not be opened

Definition at line 178 of file filesystem.cpp.

178 {
179
180 // Try to find the directory
181 for (auto &subdirectory: m_subdirectories)
182 if (subdirectory->name() == name) {
183 subdirectory->read_from_disk();
184 return subdirectory;
185 }
186
187 // Directory not found
188 return nullptr;
189}

References m_subdirectories, and name().

Referenced by MaxOS::filesystem::FileSystem::get_directory().

◆ read_from_disk()

◆ remove_file()

void Directory::remove_file ( const string name)
virtual

Delete a file in the directory.

Parameters
nameThe name of the file to remove

Reimplemented in MaxOS::filesystem::format::ext2::Ext2Directory, and MaxOS::filesystem::format::Fat32Directory.

Definition at line 160 of file filesystem.cpp.

160 {
161}

Referenced by MaxOS::filesystem::DirectoryResource::write().

◆ remove_subdirectory()

void Directory::remove_subdirectory ( const string name)
virtual

Try to remove a directory in the directory.

Parameters
nameThe name of the directory to remove

Reimplemented in MaxOS::filesystem::format::ext2::Ext2Directory, and MaxOS::filesystem::format::Fat32Directory.

Definition at line 205 of file filesystem.cpp.

205 {
206}

Referenced by MaxOS::filesystem::DirectoryResource::write().

◆ rename_file() [1/2]

void Directory::rename_file ( const string old_name,
const string new_name 
)
virtual

Rename a file in the directory.

Parameters
old_nameThe file to rename
new_nameThe new name of the file

Reimplemented in MaxOS::filesystem::format::ext2::Ext2Directory.

Definition at line 252 of file filesystem.cpp.

252 {
253
254 ASSERT(false, "not implemented");
255
256}
#define ASSERT(condition, format,...)
If the specified condition is not met then the kernel will crash with the specified message.
Definition logger.h:100

References ASSERT.

◆ rename_file() [2/2]

void Directory::rename_file ( File file,
const string new_name 
)

Rename a file in the directory.

Parameters
fileThe file to rename
new_nameThe new name of the file

Definition at line 240 of file filesystem.cpp.

240 {
241
242 rename_file(file->name(), new_name);
243
244}
void rename_file(File *file, const string &new_name)
Rename a file in the directory.
string name()
Get the name of the file.

References MaxOS::filesystem::File::name(), and rename_file().

Referenced by rename_file().

◆ rename_subdirectory() [1/2]

void Directory::rename_subdirectory ( const string old_name,
const string new_name 
)
virtual

Rename a subdirectory in the directory.

Parameters
old_nameThe directory to rename
new_nameThe new name of the directory

Reimplemented in MaxOS::filesystem::format::ext2::Ext2Directory.

Definition at line 276 of file filesystem.cpp.

276 {
277 ASSERT(false, "not implemented");
278}

References ASSERT.

◆ rename_subdirectory() [2/2]

void Directory::rename_subdirectory ( Directory directory,
const string new_name 
)

Rename a subdirectory in the directory.

Parameters
directoryThe directory to rename
new_nameThe new name of the directory

Definition at line 264 of file filesystem.cpp.

264 {
265
266 rename_subdirectory(directory->name(), new_name);
267
268}
void rename_subdirectory(Directory *directory, const string &new_name)
Rename a subdirectory in the directory.

References name(), and rename_subdirectory().

Referenced by rename_subdirectory().

◆ size()

size_t Directory::size ( )

Get the size of the directory.

Returns
The size of the directory (sum of all the files in bytes)

Definition at line 223 of file filesystem.cpp.

223 {
224
225 // Sum the size of all the files
226 size_t size = 0;
227 for (auto &file: m_files)
228 size += file->size();
229
230 return size;
231
232}
size_t size()
Get the size of the directory.

References m_files, and size().

Referenced by size().

◆ subdirectories()

common::Vector< Directory * > Directory::subdirectories ( )

Get the subdirectories in the directory.

Returns
The subdirectories in the directory

Definition at line 168 of file filesystem.cpp.

168 {
169 return m_subdirectories;
170}

References m_subdirectories.

Member Data Documentation

◆ m_files

◆ m_name

string MaxOS::filesystem::Directory::m_name
protected

◆ m_subdirectories


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