refactor: hide private members in compression_registry

This commit is contained in:
Marcus Holland-Moritz 2025-04-07 07:25:36 +02:00
parent 0cfeea7dd3
commit 95d3679751
3 changed files with 15 additions and 7 deletions

View File

@ -47,7 +47,9 @@ struct compression_registrar;
class compression_registry_base { class compression_registry_base {
protected: protected:
void register_name(compression_type type, std::string_view name); void register_name(compression_type type, std::string_view name);
compression_type get_type(std::string const& name) const;
private:
std::unordered_map<std::string, compression_type> names_; std::unordered_map<std::string, compression_type> names_;
}; };

View File

@ -31,6 +31,7 @@
#include <string> #include <string>
#include <dwarfs/detail/compression_registry.h> #include <dwarfs/detail/compression_registry.h>
#include <dwarfs/error.h>
namespace dwarfs::detail { namespace dwarfs::detail {
@ -43,4 +44,15 @@ void compression_registry_base::register_name(compression_type type,
} }
} }
compression_type
compression_registry_base::get_type(std::string const& name) const {
auto nit = names_.find(name);
if (nit == names_.end()) {
DWARFS_THROW(runtime_error, "unknown compression: " + name);
}
return nit->second;
}
} // namespace dwarfs::detail } // namespace dwarfs::detail

View File

@ -27,7 +27,6 @@
*/ */
#include <dwarfs/compressor_registry.h> #include <dwarfs/compressor_registry.h>
#include <dwarfs/error.h>
#include <dwarfs/option_map.h> #include <dwarfs/option_map.h>
#include "compression_registry.h" #include "compression_registry.h"
@ -51,13 +50,8 @@ compressor_registry& compressor_registry::instance() {
std::unique_ptr<block_compressor::impl> std::unique_ptr<block_compressor::impl>
compressor_registry::create(std::string_view spec) const { compressor_registry::create(std::string_view spec) const {
option_map om(spec); option_map om(spec);
auto nit = names_.find(om.choice());
if (nit == names_.end()) { auto obj = get_factory(get_type(om.choice())).create(om);
DWARFS_THROW(runtime_error, "unknown compression: " + om.choice());
}
auto obj = get_factory(nit->second).create(om);
om.report(); om.report();