aboutsummaryrefslogtreecommitdiff
path: root/lib/embed.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/embed.h')
-rw-r--r--lib/embed.h88
1 files changed, 0 insertions, 88 deletions
diff --git a/lib/embed.h b/lib/embed.h
deleted file mode 100644
index b57d830..0000000
--- a/lib/embed.h
+++ /dev/null
@@ -1,88 +0,0 @@
-#pragma once
-
-#include <array>
-#include <string_view>
-#include "compressionctx.h"
-
-namespace embed
-{
-
-template <std::size_t N>
-class Resources
-{
-public:
- constexpr explicit Resources(
- const std::array<const char *, N> &entries,
- const std::array<std::span<const uint8_t>, N> &values)
- : m_entries(entries)
- , m_values(values)
- {
- }
-
- [[nodiscard]] constexpr int id(const std::string_view &path) const
- {
- for(std::size_t i = 0; i < m_entries.size(); ++i) {
- if(m_entries.at(i) == path)
- return i;
- }
- return -1;
- }
- [[nodiscard]] constexpr std::span<const uint8_t> value(const int id_) const
- {
- if(id_ == -1)
- return {};
- else
- return m_values.at(id_);
- }
- [[nodiscard]] constexpr std::span<const uint8_t> value(const std::string_view &path) const
- {
- return value(id(path));
- }
-
- [[deprecated("With no compression, this function returns a copy; use ::value instead")]]
- [[nodiscard]] std::vector<uint8_t> decompress(const int id_) const
- {
- const auto v = value(id_);
- return { v.begin(), v.end() };
- }
- [[deprecated("With no compression, this function returns a copy; use ::value instead")]]
- [[nodiscard]] std::vector<uint8_t> decompress(const std::string_view &path) const
- {
- const auto v = value(path);
- return { v.begin(), v.end() };
- }
-
-protected:
- const std::array<const char *, N> m_entries;
- const std::array<std::span<const uint8_t>, N> m_values;
-};
-
-template <std::size_t N>
-class CompressedResources final : public Resources<N>
-{
-public:
- explicit CompressedResources(
- const std::array<const char *, N> &entries,
- const std::array<std::span<const uint8_t>, N> &values,
- const Compression algo,
- const std::span<const uint8_t> &dictionary = {})
- : Resources<N>(entries, values)
- , m_compression(make_compression_ctx(algo, dictionary))
- {
- }
- ~CompressedResources() = default;
-
- [[nodiscard]] std::vector<uint8_t> decompress(const int id_) const
- {
- return m_compression->decompress(Resources<N>::value(id_));
- }
- [[nodiscard]] std::vector<uint8_t> decompress(const std::string_view &path) const
- {
- return m_compression->decompress(Resources<N>::value(path));
- }
-
-protected:
- const std::unique_ptr<CompressionCtx> m_compression;
-};
-
-} // namespace embed