AssetManager.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <memory>
5 #include <vector>
6 
9 
10 namespace dai {
11 
15 struct Asset {
16  Asset() = default;
17  explicit Asset(std::string k) : key(std::move(k)) {}
18  const std::string key;
19  std::vector<std::uint8_t> data;
20  std::uint32_t alignment = 1;
21  std::string getRelativeUri();
22 };
23 
24 class AssetsMutable : public Assets {
25  public:
26  void set(std::string, std::uint32_t offset, std::uint32_t size, std::uint32_t alignment);
27 };
28 
29 // Subclass which has its own storage
33 class AssetManager /*: public Assets*/ {
34  std::map<std::string, std::shared_ptr<Asset>> assetMap;
35 
36  public:
41  void addExisting(std::vector<std::shared_ptr<Asset>> assets);
42 
48  std::shared_ptr<dai::Asset> set(Asset asset);
49 
58  std::shared_ptr<dai::Asset> set(const std::string& key, Asset asset);
59 
67  std::shared_ptr<dai::Asset> set(const std::string& key, const dai::Path& path, int alignment = 64);
68 
77  std::shared_ptr<dai::Asset> set(const std::string& key, const std::vector<std::uint8_t>& data, int alignment = 64);
78  std::shared_ptr<dai::Asset> set(const std::string& key, std::vector<std::uint8_t>&& data, int alignment = 64);
79 
83  std::shared_ptr<const Asset> get(const std::string& key) const;
84 
88  std::shared_ptr<Asset> get(const std::string& key);
89 
93  std::vector<std::shared_ptr<const Asset>> getAll() const;
94 
98  std::vector<std::shared_ptr<Asset>> getAll();
99 
103  std::size_t size() const;
104 
109  void remove(const std::string& key);
110 
112  void serialize(AssetsMutable& assets, std::vector<std::uint8_t>& assetStorage, std::string prefix = "") const;
113 };
114 
115 } // namespace dai
dai::AssetsMutable
Definition: AssetManager.hpp:24
dai::AssetManager::addExisting
void addExisting(std::vector< std::shared_ptr< Asset >> assets)
Definition: AssetManager.cpp:78
dai::AssetManager::remove
void remove(const std::string &key)
Definition: AssetManager.cpp:107
dai::Asset::alignment
std::uint32_t alignment
Definition: AssetManager.hpp:20
dai::AssetManager::serialize
void serialize(AssetsMutable &assets, std::vector< std::uint8_t > &assetStorage, std::string prefix="") const
Serializes.
Definition: AssetManager.cpp:111
dai::AssetManager::size
std::size_t size() const
Definition: AssetManager.cpp:103
dai::Asset::data
std::vector< std::uint8_t > data
Definition: AssetManager.hpp:19
dai::AssetManager
AssetManager can store assets and serialize.
Definition: AssetManager.hpp:33
DAI_SPAN_NAMESPACE_NAME::detail::data
constexpr auto data(C &c) -> decltype(c.data())
Definition: span.hpp:177
dai::Asset::Asset
Asset()=default
dai::AssetsMutable::set
void set(std::string, std::uint32_t offset, std::uint32_t size, std::uint32_t alignment)
Definition: AssetManager.cpp:137
dai::Asset
Asset is identified with string key and can store arbitrary binary data.
Definition: AssetManager.hpp:15
dai::Asset::key
const std::string key
Definition: AssetManager.hpp:18
DAI_SPAN_NAMESPACE_NAME::detail::size
constexpr auto size(const C &c) -> decltype(c.size())
Definition: span.hpp:167
dai::Asset::getRelativeUri
std::string getRelativeUri()
Definition: AssetManager.cpp:11
dai::AssetManager::set
std::shared_ptr< dai::Asset > set(Asset asset)
Definition: AssetManager.cpp:15
Assets.hpp
dai::Assets
Definition: Assets.hpp:22
Path.hpp
dai::AssetManager::get
std::shared_ptr< const Asset > get(const std::string &key) const
Definition: AssetManager.cpp:64
std
Definition: Node.hpp:366
dai::Asset::Asset
Asset(std::string k)
Definition: AssetManager.hpp:17
dai::Path
Represents paths on a filesystem; accepts utf-8, Windows utf-16 wchar_t, or std::filesystem::path.
Definition: Path.hpp:27
dai::AssetManager::assetMap
std::map< std::string, std::shared_ptr< Asset > > assetMap
Definition: AssetManager.hpp:34
dai
Definition: CameraExposureOffset.hpp:6
dai::AssetManager::getAll
std::vector< std::shared_ptr< const Asset > > getAll() const
Definition: AssetManager.cpp:87


depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:18