mirror of
https://github.com/mhx/dwarfs.git
synced 2025-08-04 02:06:22 -04:00
refactor: hide private members in compression_registry
This commit is contained in:
parent
0cfeea7dd3
commit
95d3679751
@ -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_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user