Mountain  1.0.0
Simple C++ 2D Game Framework
file_manager.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <filesystem>
4 #include <map>
5 
6 #include "Mountain/core.hpp"
8 #include "Mountain/file/file.hpp"
12 
15 
16 namespace Mountain
17 {
23  class FileManager final
24  {
25  STATIC_CLASS(FileManager)
26 
27  public:
29  MOUNTAIN_API static Pointer<File> Add(std::filesystem::path path);
30 
32  MOUNTAIN_API static Pointer<File> Load(std::filesystem::path path);
33 
35  MOUNTAIN_API static Pointer<Directory> AddDirectory(std::filesystem::path path);
36 
39  MOUNTAIN_API static Pointer<Directory> LoadDirectory(std::filesystem::path path);
40 
42  [[nodiscard]]
43  MOUNTAIN_API static bool_t Contains(const std::filesystem::path& path);
44 
49  template <Concepts::EntryT T = File>
50  [[nodiscard]]
51  static Pointer<T> Get(const std::filesystem::path& path);
52 
57  MOUNTAIN_API static void Rename(const std::filesystem::path& path, const std::filesystem::path& newPath);
58 
63  MOUNTAIN_API static void Rename(const Pointer<Entry>& entry, const std::filesystem::path& newPath);
64 
68  template <Concepts::EntryT T = File>
69  [[nodiscard]]
70  static Pointer<T> Find();
71 
78  template <Concepts::EntryT T = File>
79  [[nodiscard]]
80  static Pointer<T> Find(std::function<bool_t(Pointer<T>)>&& predicate);
81 
85  template <Concepts::EntryT T = File>
86  [[nodiscard]]
87  static std::vector<Pointer<T>> FindAll();
88 
90  template <Concepts::EntryT T = File>
91  static void FindAll(List<Pointer<T>>* result);
92 
99  template <Concepts::EntryT T = File>
100  [[nodiscard]]
101  static List<Pointer<T>> FindAll(std::function<bool_t(Pointer<T>)>&& predicate);
102 
104  template <Concepts::EntryT T = File>
105  static void FindAll(std::function<bool_t(Pointer<T>)>&& predicate, List<Pointer<T>>* result);
106 
108  MOUNTAIN_API static void Unload(const std::filesystem::path& path);
109 
111  MOUNTAIN_API static void Unload(const Pointer<Entry>& entry);
112 
114  MOUNTAIN_API static void UnloadAll();
115 
116  private:
117  MOUNTAIN_API static inline std::map<std::filesystem::path, Pointer<Entry>> m_Entries;
118  };
119 }
120 
121 #include "Mountain/file/file_manager.inl"
Defines the Mountain::List class.
static MOUNTAIN_API Pointer< File > Load(std::filesystem::path path)
Creates the File corresponding to the given path and loads it.
Defines the Mountain::File class.
static MOUNTAIN_API Pointer< Directory > LoadDirectory(std::filesystem::path path)
Creates the Directory corresponding to the given path and loads it.
Defines the Mountain::Logger static class.
A dynamic array implementation. Wrapper around the std::vector class.
Definition: list.hpp:24
static MOUNTAIN_API void Rename(const std::filesystem::path &path, const std::filesystem::path &newPath)
Renames the Entry with the specified path to another path.
static MOUNTAIN_API Pointer< File > Add(std::filesystem::path path)
Creates the File corresponding to the given path without loading it.
static Pointer< T > Find()
Finds the first Entry of type T.
Custom Mountain smart pointer. Represents both a std::shared_ptr and a std::weak_ptr.
Static class used to add, load, get, or unload Files and Directories.
Defines the Mountain::Directory class.
static MOUNTAIN_API bool_t Contains(const std::filesystem::path &path)
Checks whether the FileManager contains the specified Entry path.
static Pointer< T > Get(const std::filesystem::path &path)
Tries to get the Entry with the given path.
Defines the Mountain::Pointer class.
static MOUNTAIN_API void Unload(const std::filesystem::path &path)
Unloads the Entry corresponding to the given path.
static MOUNTAIN_API Pointer< Directory > AddDirectory(std::filesystem::path path)
Creates a Directory corresponding to the given path without loading it.
static std::vector< Pointer< T > > FindAll()
Finds all Entries of type T.
static MOUNTAIN_API void UnloadAll()
Unloads all stored entries.
Contains all declarations of the Mountain Framework.
Definition: audio.hpp:22