Mountain  1.0.0
Simple C++ 2D Game Framework
file.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <filesystem>
4 
5 #include "Mountain/core.hpp"
9 
12 
13 namespace Mountain
14 {
18  class File : public Entry
19  {
20  public:
22  enum class Type : uint8_t
23  {
24  Unknown,
25  AudioTrack,
26  Texture,
27  Font,
28  Xml,
29  VertexShader,
30  FragmentShader,
32  Glsl
33  };
34 
36  [[nodiscard]]
37  MOUNTAIN_API explicit File(std::filesystem::path&& filepath);
38 
40  MOUNTAIN_API ~File() override;
41 
42  DEFAULT_COPY_MOVE_OPERATIONS(File)
43 
44 
45  MOUNTAIN_API bool_t Load() override;
48 
51  MOUNTAIN_API void Load(const char_t* data, size_t size);
52 
54  MOUNTAIN_API void Unload() override;
55 
57  MOUNTAIN_API void OpenInExplorer() const override;
58 
60  MOUNTAIN_API void OpenFile() const;
61 
63  MOUNTAIN_API Type GetType() const;
64 
66  MOUNTAIN_API void Delete() const;
67 
69  MOUNTAIN_API bool_t Exists();
70 
72  [[nodiscard]]
73  MOUNTAIN_API std::string GetNameNoExtension() const;
74 
76  [[nodiscard]]
77  MOUNTAIN_API std::string GetPathNoExtension() const;
78 
80  [[nodiscard]]
81  MOUNTAIN_API std::string GetExtension() const;
82 
84  template <typename T = char_t>
85  [[nodiscard]]
86  const T* GetData() const;
87 
89  template <typename T = char_t>
90  [[nodiscard]]
91  T* GetData();
92 
94  [[nodiscard]]
95  MOUNTAIN_API int64_t GetSize() const;
96 
98  MOUNTAIN_API void SetName(const std::string& newName) override;
99 
104  [[nodiscard]]
105  MOUNTAIN_API Pointer<Resource> GetResource() const;
106 
107  protected:
108  void UpdateUtilityValues() override;
109 
110  private:
111  std::string m_NameNoExtension;
112  std::string m_Extension;
113  std::string m_PathNoExtension;
114  Type m_Type = Type::Unknown;
115 
116  int8_t* m_Data = nullptr;
117  int64_t m_Size = 0;
118 
121  Pointer<Resource> m_Resource;
122 
123  // We need this in order to set m_Resource from the ResourceManager
124  // which is the only class that needs to modify this field
125  friend class ResourceManager;
126  };
127 }
128 
129 // Voluntary include after the class definition because using Pointer<File> means we need to include File at some point
130 #include "Mountain/file/file.inl"
Defines the Mountain::Entry class.
MOUNTAIN_API bool_t Load() override
Loads the contents of this File.
MOUNTAIN_API bool_t Exists()
Get whether this file exists on the file system or is just a virtual file representation.
Type
Type of file according to file extension.
Definition: file.hpp:22
File system entry. Can be either a File or a Directory.
Definition: entry.hpp:16
Defines the Mountain::Resource class.
MOUNTAIN_API void SetName(const std::string &newName) override
Sets the name of this File.
Static class used to add, load, get, or unload Resources.
MOUNTAIN_API File(std::filesystem::path &&filepath)
Constructs a File corresponding to the given path.
const T * GetData() const
Returns a const pointer to the raw loaded data.
MOUNTAIN_API void OpenInExplorer() const override
Opens this File in the file explorer.
void UpdateUtilityValues() override
Updates fields of this class using the new value of m_Path.
Represents an image in memory.
Definition: texture.hpp:18
MOUNTAIN_API void Delete() const
Deletes the corresponding filesystem file.
MOUNTAIN_API std::string GetExtension() const
Returns the file extension of this File.
MOUNTAIN_API int64_t GetSize() const
Returns the size of the loaded data.
MOUNTAIN_API std::string GetPathNoExtension() const
Returns the name of this File without the file extension.
Defines the Mountain::Pointer class.
MOUNTAIN_API std::string GetNameNoExtension() const
Returns the name of this File without the file extension.
MOUNTAIN_API void Unload() override
Unloads the contents of this File.
Holds the necessary information to draw text using a Font.
Definition: font.hpp:15
MOUNTAIN_API Type GetType() const
Returns the Type of this File.
MOUNTAIN_API void OpenFile() const
Opens this File on the user&#39;s computer using the default software for its file extension.
MOUNTAIN_API ~File() override
Destructs the File instance by calling PostUnload.
Defines a file on the filesystem.
Definition: file.hpp:18
MOUNTAIN_API Pointer< Resource > GetResource() const
Returns the stored Pointer to the Resource loaded from this File.
Contains all declarations of the Mountain Framework.
Definition: audio.hpp:22