diff --git a/include/pisa/codec/block_codec_registry.hpp b/include/pisa/codec/block_codec_registry.hpp index a3b454ea..30583017 100644 --- a/include/pisa/codec/block_codec_registry.hpp +++ b/include/pisa/codec/block_codec_registry.hpp @@ -3,13 +3,65 @@ #include #include +#include #include #include "codec/block_codec.hpp" +#include "codec/interpolative.hpp" +#include "codec/maskedvbyte.hpp" +#include "codec/optpfor.hpp" +#include "codec/qmx.hpp" +#include "codec/simdbp.hpp" +#include "codec/simple16.hpp" +#include "codec/simple8b.hpp" +#include "codec/streamvbyte.hpp" +#include "codec/varint_g8iu.hpp" +#include "codec/varintgb.hpp" namespace pisa { -[[nodiscard]] auto get_block_codec(std::string_view name) -> std::unique_ptr; -[[nodiscard]] auto get_block_codec_names() -> gsl::span; +template +struct BlockCodecRegistry { + using BlockCodecConstructor = std::unique_ptr (*)(); + + constexpr static std::array names = + std::array{C::name...}; + + constexpr static std::array constructors = + std::array{[]() -> std::unique_ptr { + return std::make_unique(); + }...}; + + constexpr static auto count() -> std::size_t { return sizeof...(C); } + + static auto get(std::string_view name) -> std::unique_ptr { + auto pos = std::find(names.begin(), names.end(), name); + if (pos == names.end()) { + throw std::domain_error(fmt::format("invalid codec: {}", name)); + } + auto constructor = constructors[std::distance(names.begin(), pos)]; + return constructor(); + } +}; + +using BlockCodecs = BlockCodecRegistry< + InterpolativeBlockCodec, + MaskedVByteBlockCodec, + OptPForBlockCodec, + QmxBlockCodec, + SimdBpBlockCodec, + Simple16BlockCodec, + Simple8bBlockCodec, + StreamVByteBlockCodec, + VarintG8IUBlockCodec, + VarintGbBlockCodec>; + +[[nodiscard]] auto get_block_codec(std::string_view name) -> std::unique_ptr { + return BlockCodecs::get(name); +} + +[[nodiscard]] auto get_block_codec_names() -> gsl::span { + return gsl::make_span(&BlockCodecs::names[0], BlockCodecs::count()); +} } // namespace pisa diff --git a/src/codec/block_codec_registry.cpp b/src/codec/block_codec_registry.cpp index 2f4b8f12..ab7a880a 100644 --- a/src/codec/block_codec_registry.cpp +++ b/src/codec/block_codec_registry.cpp @@ -22,48 +22,4 @@ namespace pisa { -template -struct BlockCodecRegistry { - using BlockCodecConstructor = std::unique_ptr (*)(); - - constexpr static std::array names = - std::array{C::name...}; - - constexpr static std::array constructors = - std::array{[]() -> std::unique_ptr { - return std::make_unique(); - }...}; - - constexpr static auto count() -> std::size_t { return sizeof...(C); } - - static auto get(std::string_view name) -> std::unique_ptr { - auto pos = std::find(names.begin(), names.end(), name); - if (pos == names.end()) { - throw std::domain_error(fmt::format("invalid codec: {}", name)); - } - auto constructor = constructors[std::distance(names.begin(), pos)]; - return constructor(); - } -}; - -using BlockCodecs = BlockCodecRegistry< - InterpolativeBlockCodec, - MaskedVByteBlockCodec, - OptPForBlockCodec, - QmxBlockCodec, - SimdBpBlockCodec, - Simple16BlockCodec, - Simple8bBlockCodec, - StreamVByteBlockCodec, - VarintG8IUBlockCodec, - VarintGbBlockCodec>; - -auto get_block_codec(std::string_view name) -> std::unique_ptr { - return BlockCodecs::get(name); -} - -auto get_block_codec_names() -> gsl::span { - return gsl::make_span(&BlockCodecs::names[0], BlockCodecs::count()); -} - } // namespace pisa