MOS
assets.hpp
1 #pragma once
2 
3 #include <filesystem>
4 #include <map>
5 #include <memory>
6 #include <mos/aud/buffer.hpp>
7 #include <mos/aud/stream.hpp>
8 #include <unordered_map>
9 
10 namespace mos::aud {
11 
13 class Assets final {
14 public:
15  using Buffer_map = std::unordered_map<std::string, Shared_buffer>;
16  using Buffer_pair = std::pair<std::string, Shared_buffer>;
17 
18  explicit Assets(const std::filesystem::path& directory = "assets/");
19  ~Assets() = default;
20 
21  Assets(const Assets &assets) = delete;
22  Assets(const Assets &&assets) = delete;
23 
24  Assets &operator=(const Assets &assets) = delete;
25  Assets &operator=(const Assets &&assets) = delete;
26 
28  auto audio_buffer(const std::filesystem::path &path) -> Shared_buffer;
29 
31  auto clear_unused() -> void;
32 
34  auto clear() -> void;
35 
37  auto directory() const -> std::filesystem::path;
38 
39 private:
40  const std::string directory_;
41  Buffer_map buffers_;
42 };
43 } // namespace mos::aud
Cache for heavy audio assets.
Definition: assets.hpp:13
auto audio_buffer(const std::filesystem::path &path) -> Shared_buffer
Loads an *.ogg file into a buffer and caches it.
auto clear_unused() -> void
Remove unused buffers.
auto directory() const -> std::filesystem::path
Directory of assets.
auto clear() -> void
Remove all buffers.
Definition: filter.hpp:13