From aacb9a0d949960db28984f9047f59daedac5a83e Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sun, 13 Aug 2023 22:29:13 +0200 Subject: [PATCH] add segmenter_factory --- CMakeLists.txt | 1 + include/dwarfs/categorized_option.h | 48 +++++++++++++ include/dwarfs/options.h | 22 +----- include/dwarfs/scanner.h | 5 +- include/dwarfs/segmenter.h | 5 +- include/dwarfs/segmenter_factory.h | 66 +++++++++++++++++ src/dwarfs/scanner.cpp | 45 ++++++------ src/dwarfs/segmenter.cpp | 2 +- src/dwarfs/segmenter_factory.cpp | 62 ++++++++++++++++ src/mkdwarfs_main.cpp | 105 +++++++++++++++------------- test/dwarfs.cpp | 18 ++++- test/dwarfs_benchmark.cpp | 15 ++-- 12 files changed, 286 insertions(+), 108 deletions(-) create mode 100644 include/dwarfs/categorized_option.h create mode 100644 include/dwarfs/segmenter_factory.h create mode 100644 src/dwarfs/segmenter_factory.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 49c4381d..c938b328 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -399,6 +399,7 @@ list( src/dwarfs/safe_main.cpp src/dwarfs/scanner.cpp src/dwarfs/segmenter.cpp + src/dwarfs/segmenter_factory.cpp src/dwarfs/similarity.cpp src/dwarfs/similarity_ordering.cpp src/dwarfs/string_table.cpp diff --git a/include/dwarfs/categorized_option.h b/include/dwarfs/categorized_option.h new file mode 100644 index 00000000..dc6418b3 --- /dev/null +++ b/include/dwarfs/categorized_option.h @@ -0,0 +1,48 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/** + * \author Marcus Holland-Moritz (github@mhxnet.de) + * \copyright Copyright (c) Marcus Holland-Moritz + * + * This file is part of dwarfs. + * + * dwarfs is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * dwarfs is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with dwarfs. If not, see . + */ + +#pragma once + +#include "dwarfs/contextual_option.h" +#include "dwarfs/fragment_category.h" + +namespace dwarfs { + +namespace detail { + +template +struct categorized_option_policy { + using ContextArgumentType = fragment_category; + using ContextType = fragment_category::value_type; + using ValueType = T; + + static ContextType context_from_arg(ContextArgumentType const& arg) { + return arg.value(); + } +}; + +} // namespace detail + +template +using categorized_option = + contextual_option>; + +} // namespace dwarfs diff --git a/include/dwarfs/options.h b/include/dwarfs/options.h index 4e5132c4..a6654c08 100644 --- a/include/dwarfs/options.h +++ b/include/dwarfs/options.h @@ -28,9 +28,8 @@ #include #include -#include "dwarfs/contextual_option.h" +#include "dwarfs/categorized_option.h" #include "dwarfs/file_stat.h" -#include "dwarfs/fragment_category.h" #include "dwarfs/types.h" namespace dwarfs { @@ -38,25 +37,6 @@ namespace dwarfs { class categorizer_manager; class entry; -namespace detail { - -template -struct categorized_option_policy { - using ContextArgumentType = fragment_category; - using ContextType = fragment_category::value_type; - using ValueType = T; - - static ContextType context_from_arg(ContextArgumentType const& arg) { - return arg.value(); - } -}; - -} // namespace detail - -template -using categorized_option = - contextual_option>; - enum class mlock_mode { NONE, TRY, MUST }; enum class cache_tidy_strategy { NONE, EXPIRY_TIME, BLOCK_SWAPPED_OUT }; diff --git a/include/dwarfs/scanner.h b/include/dwarfs/scanner.h index 5ee21405..44a34ef9 100644 --- a/include/dwarfs/scanner.h +++ b/include/dwarfs/scanner.h @@ -27,8 +27,6 @@ #include #include -#include "dwarfs/segmenter.h" - namespace dwarfs { struct scanner_options; @@ -39,11 +37,12 @@ class logger; class os_access; class progress; class script; +class segmenter_factory; class worker_group; class scanner { public: - scanner(logger& lgr, worker_group& wg, const segmenter::config& cfg, + scanner(logger& lgr, worker_group& wg, std::shared_ptr sf, std::shared_ptr ef, std::shared_ptr os, std::shared_ptr