Program Listing for File AssetManager.hpp

Return to documentation for file (include/depthai/pipeline/AssetManager.hpp)

#pragma once

#include <filesystem>
#include <map>
#include <memory>
#include <vector>

#include "depthai/pipeline/Assets.hpp"

namespace dai {

struct Asset {
    Asset() = default;
    explicit Asset(std::string k) : key(std::move(k)) {}
    const std::string key;
    std::vector<std::uint8_t> data;
    std::uint32_t alignment = 1;
    std::string getRelativeUri();
};

class AssetsMutable : public Assets {
   public:
    void set(std::string, std::uint32_t offset, std::uint32_t size, std::uint32_t alignment);
};

// Subclass which has its own storage
class AssetManager /*: public Assets*/ {
    std::map<std::string, std::shared_ptr<Asset>> assetMap;
    std::string rootPath;

    std::string getRelativeKey(std::string key) const;

   public:
    AssetManager();
    AssetManager(std::string rootPath);
    void addExisting(std::vector<std::shared_ptr<Asset>> assets);

    std::string getRootPath();

    void setRootPath(const std::string& rootPath);

    std::shared_ptr<dai::Asset> set(Asset asset);

    std::shared_ptr<dai::Asset> set(const std::string& key, Asset asset);

    std::shared_ptr<dai::Asset> set(const std::string& key, const std::filesystem::path& path, int alignment = 64);

    std::shared_ptr<dai::Asset> set(const std::string& key, const std::vector<std::uint8_t>& data, int alignment = 64);
    std::shared_ptr<dai::Asset> set(const std::string& key, std::vector<std::uint8_t>&& data, int alignment = 64);

    std::shared_ptr<const Asset> get(const std::string& key) const;

    std::shared_ptr<Asset> get(const std::string& key);

    std::vector<std::shared_ptr<const Asset>> getAll() const;

    std::vector<std::shared_ptr<Asset>> getAll();

    std::size_t size() const;

    void remove(const std::string& key);

    void serialize(AssetsMutable& assets, std::vector<std::uint8_t>& assetStorage, std::string prefix = "") const;
};

}  // namespace dai