Assets.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 // standard
4 #include <cstdint>
5 #include <exception>
6 #include <unordered_map>
7 
8 // project
10 
11 namespace dai {
12 
13 // This class represent a single asset
14 struct AssetView {
15  std::uint8_t* data;
16  std::uint32_t size;
17  std::uint32_t alignment = 1;
18  AssetView(std::uint8_t* d, std::uint32_t s, std::uint32_t a = 1) : data(d), size(s), alignment(a) {}
19 };
20 
21 // This is a serializable class, which acts as readonly access to assets
22 class Assets {
23  protected:
24  std::uint8_t* pStorageStart = nullptr;
25 
26  struct AssetInternal {
27  std::uint32_t offset, size, alignment;
29  };
30 
31  // maps string to Asset
32  std::unordered_map<std::string, AssetInternal> map;
33 
34  public:
35  void setStorage(std::uint8_t* ps) {
36  pStorageStart = ps;
37  }
38 
39  bool has(const std::string& key) {
40  return (map.count(key) > 0);
41  }
42 
43  AssetView get(const std::string& key) {
44  AssetInternal internal = map.at(key);
45  return {pStorageStart + internal.offset, internal.size, internal.alignment};
46  }
47 
48  std::vector<std::pair<std::string, AssetView>> getAll() {
49  std::vector<std::pair<std::string, AssetView>> allAssets;
50  for(const auto& kv : map) {
51  allAssets.emplace_back(kv.first, get(kv.first));
52  }
53  return allAssets;
54  }
55 
57 };
58 
59 } // namespace dai
dai::AssetView::data
std::uint8_t * data
Definition: Assets.hpp:15
dai::AssetView::AssetView
AssetView(std::uint8_t *d, std::uint32_t s, std::uint32_t a=1)
Definition: Assets.hpp:18
dai::Assets::AssetInternal::alignment
std::uint32_t alignment
Definition: Assets.hpp:27
dai::Assets::get
AssetView get(const std::string &key)
Definition: Assets.hpp:43
dai::AssetView::size
std::uint32_t size
Definition: Assets.hpp:16
dai::Assets::has
bool has(const std::string &key)
Definition: Assets.hpp:39
dai::Assets::map
std::unordered_map< std::string, AssetInternal > map
Definition: Assets.hpp:32
dai::AssetView
Definition: Assets.hpp:14
dai::Assets::AssetInternal::offset
std::uint32_t offset
Definition: Assets.hpp:27
dai::Assets
Definition: Assets.hpp:22
dai::Assets::setStorage
void setStorage(std::uint8_t *ps)
Definition: Assets.hpp:35
dai::Assets::getAll
std::vector< std::pair< std::string, AssetView > > getAll()
Definition: Assets.hpp:48
Serialization.hpp
dai::Assets::DEPTHAI_SERIALIZE
DEPTHAI_SERIALIZE(Assets, map)
dai::AssetView::alignment
std::uint32_t alignment
Definition: Assets.hpp:17
dai
Definition: CameraExposureOffset.hpp:6
dai::Assets::pStorageStart
std::uint8_t * pStorageStart
Definition: Assets.hpp:24
dai::Assets::AssetInternal
Definition: Assets.hpp:26
dai::Assets::AssetInternal::DEPTHAI_SERIALIZE
DEPTHAI_SERIALIZE(AssetInternal, offset, size, alignment)
dai::Assets::AssetInternal::size
std::uint32_t size
Definition: Assets.hpp:27


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