Mountain  1.0.0
Simple C++ 2D Game Framework
Mountain::File Class Reference

Defines a file on the filesystem. More...

#include <file.hpp>

+ Inheritance diagram for Mountain::File:
+ Collaboration diagram for Mountain::File:

Public Types

enum  Type : uint8_t {
  Unknown, AudioTrack, Texture, Font,
  Xml, VertexShader, FragmentShader, ComputeShader,
  Glsl
}
 Type of file according to file extension.
 

Public Member Functions

MOUNTAIN_API File (std::filesystem::path &&filepath)
 Constructs a File corresponding to the given path.
 
MOUNTAIN_API ~File () override
 Destructs the File instance by calling PostUnload.
 
MOUNTAIN_API bool_t Load () override
 Loads the contents of this File. More...
 
MOUNTAIN_API void Load (const char_t *data, size_t size)
 Loads the given contents in this File. Note: This doesn't have anything to do with the file system. This only loads the given data in this resource.
 
MOUNTAIN_API void Unload () override
 Unloads the contents of this File.
 
MOUNTAIN_API void OpenInExplorer () const override
 Opens this File in the file explorer.
 
MOUNTAIN_API void OpenFile () const
 Opens this File on the user's computer using the default software for its file extension.
 
MOUNTAIN_API Type GetType () const
 Returns the Type of this File.
 
MOUNTAIN_API void Delete () const
 Deletes the corresponding filesystem file.
 
MOUNTAIN_API bool_t Exists ()
 Get whether this file exists on the file system or is just a virtual file representation.
 
MOUNTAIN_API std::string GetNameNoExtension () const
 Returns the name of this File without the file extension.
 
MOUNTAIN_API std::string GetPathNoExtension () const
 Returns the name of this File without the file extension.
 
MOUNTAIN_API std::string GetExtension () const
 Returns the file extension of this File.
 
template<typename T = char_t>
const TGetData () const
 Returns a const pointer to the raw loaded data.
 
template<typename T = char_t>
TGetData ()
 Returns a pointer to the raw loaded data.
 
MOUNTAIN_API int64_t GetSize () const
 Returns the size of the loaded data.
 
MOUNTAIN_API void SetName (const std::string &newName) override
 Sets the name of this File.
 
MOUNTAIN_API Pointer< Resource > GetResource () const
 Returns the stored Pointer to the Resource loaded from this File. More...
 
- Public Member Functions inherited from Mountain::Entry
MOUNTAIN_API Entry (std::filesystem::path &&path)
 Constructs an Entry corresponding to the given path.
 
virtual MOUNTAIN_API ~Entry ()=default
 Default Entry destruction.
 
virtual MOUNTAIN_API bool_t Reload ()
 Reloads the contents of this Entry. More...
 
MOUNTAIN_API const std::filesystem::path & GetPath () const
 Returns the corresponding filesystem path.
 
MOUNTAIN_API std::string GetPathString () const
 Returns the string representation of GetPath.
 
MOUNTAIN_API std::string GetName () const
 Returns this Entry name.
 
MOUNTAIN_API bool_t GetLoaded () const
 Returns whether this Entry has been loaded.
 
virtual void SetParent (Pointer< Directory > &&newParent)
 Sets the new path of this Entry.
 
MOUNTAIN_API Pointer< DirectoryGetParent ()
 Returns a Pointer to the parent Directory of this Entry, with a strong reference stored in the FileManager.
 

Protected Member Functions

void UpdateUtilityValues () override
 Updates fields of this class using the new value of m_Path.
 

Friends

class ResourceManager
 

Additional Inherited Members

- Protected Attributes inherited from Mountain::Entry
std::filesystem::path m_Path
 The underlying filesystem path of this Entry.
 
std::string m_Name
 The name of this Entry.
 
bool_t m_Loaded = false
 Whether this Entry has been loaded. More...
 
Pointer< Directorym_Parent
 The parent of this Entry.
 

Detailed Description

Defines a file on the filesystem.

This is meant to be used with Pointers and with the FileManager.

Definition at line 18 of file file.hpp.

Member Function Documentation

◆ GetResource()

MOUNTAIN_API Pointer<Resource> Mountain::File::GetResource ( ) const

Returns the stored Pointer to the Resource loaded from this File.

Note that a Resource doesn't need to be loaded from a File and can instead be loaded from raw data. This implies that the return value of this function can be a nullptr.

◆ Load()

MOUNTAIN_API bool_t Mountain::File::Load ( )
overridevirtual

Loads the contents of this File.

Returns
false if an error occured while loading.

Implements Mountain::Entry.


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