From 2cf10b71f6d0c11bee1f1e1e87c302a47f16a119 Mon Sep 17 00:00:00 2001 From: Baryonics Date: Tue, 30 Jun 2026 23:32:29 +0200 Subject: [PATCH 01/17] Added indicators library to the project --- cmake/load_dependencies.cmake | 3 ++- conanfile.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/load_dependencies.cmake b/cmake/load_dependencies.cmake index bd67d89a..8f0e669a 100644 --- a/cmake/load_dependencies.cmake +++ b/cmake/load_dependencies.cmake @@ -3,7 +3,8 @@ find_package(magic_enum REQUIRED CONFIG) find_package(CLI11 REQUIRED CONFIG) find_package(Eigen3 REQUIRED CONFIG) find_package(GSL REQUIRED) +find_package(indicators REQUIRED) if(ENABLE_TEST) - find_package(GTest CONFIG REQUIRED) + find_package(GTest CONFIG REQUIRED) endif() diff --git a/conanfile.py b/conanfile.py index 662b4bb5..59f9ffee 100644 --- a/conanfile.py +++ b/conanfile.py @@ -15,6 +15,7 @@ def requirements(self): self.requires("magic_enum/0.9.7") # type: ignore self.requires("cli11/2.6.0") # type: ignore self.requires("eigen/5.0.1") # type: ignore + self.requires("indicators/2.3") # type: ignore # Conditions on cmake variables set from cmake/project_options if os.environ["CMAKE_ENABLE_TEST"] == "ON": From ddbdf49b9312b8b12f6848270df91e04edf8097c Mon Sep 17 00:00:00 2001 From: Baryonics Date: Tue, 30 Jun 2026 23:33:07 +0200 Subject: [PATCH 02/17] first implementation of ProgressAdaptor class --- source/centipede/util/progress_indicator.hpp | 106 +++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 source/centipede/util/progress_indicator.hpp diff --git a/source/centipede/util/progress_indicator.hpp b/source/centipede/util/progress_indicator.hpp new file mode 100644 index 00000000..ac1fbdc8 --- /dev/null +++ b/source/centipede/util/progress_indicator.hpp @@ -0,0 +1,106 @@ +#include +#include +#include + +using namespace indicators; +class ProgressAdaptor; + +template +struct ProgressClosure : std::ranges::range_adaptor_closure> +{ + ProgressAdaptor* adaptor; + std::size_t total_size_n; + IncrementFunT increment_fun; + + template + auto operator()(RangeT range) + { + return (*adaptor)(std::forward(range), total_size_n, increment_fun); + } +}; + +class ProgressAdaptor +{ + public: + template + auto operator()(RangeT&& range, std::size_t total_size_n, IncrementFunT increment_fun) + { + return ProgressView{ this, std::forward(range), total_size_n, increment_fun }; + } + + template + auto operator()(std::size_t total_size_n, IncrementFunT increment_fun) + { + return ProgressClosure{ {}, this, total_size_n, increment_fun }; + } + + template + struct ProgressView + { + using IteratorType = std::ranges::iterator_t; + + ProgressView(ProgressAdaptor* progress_adaptor, + RangeT&& base_range, + std::size_t total_size_n, + IncrementFunT increment_fun) + : progress_adaptor_(progress_adaptor) + , base_range_(std::move(base_range)) + , total_size_n_(total_size_n) + , increment_fun_(increment_fun) + { + } + + auto begin() { return Iterator{ progress_adaptor_, this, base_range_.begin() }; } + + auto end() { return base_range_.end(); } + + class Iterator + { + public: + Iterator(ProgressAdaptor* progress_adaptor, ProgressView* progress_view, IteratorType current_it) + : progress_adaptor_(progress_adaptor) + , progress_view_(progress_view) + , current_it_(current_it) + { + } + + auto operator++() + { + ++current_it_; + count_n_ += progress_view_->increment_fun_(); + progress_adaptor_->bar_.set_progress(100 * count_n_ / progress_view_->total_size_n_); + } + + auto operator*() { return *current_it_; } + + auto operator==(auto& other) { return current_it_ == other; } + auto operator!=(auto& other) { return current_it_ != other; } + auto operator==(const auto& other) const { return current_it_ == other; } + auto operator!=(const auto& other) const { return current_it_ != other; } + + private: + ProgressAdaptor* progress_adaptor_; + ProgressView* progress_view_; + IteratorType current_it_; + std::size_t count_n_{}; + }; + + private: + RangeT base_range_; + std::size_t total_size_n_; + IncrementFunT increment_fun_; + ProgressAdaptor* progress_adaptor_; + }; + + private: + ProgressBar bar_{ option::BarWidth{ 50 }, + option::Start{ "[" }, + option::Fill{ "=" }, + option::Lead{ ">" }, + option::Remainder{ " " }, + option::End{ "]" }, + option::PostfixText{ "Extracting Archive" }, + option::ForegroundColor{ Color::green }, + option::ShowPercentage{ true }, + option::FontStyles{ std::vector{ FontStyle::bold } } }; +}; From d05067454186430b4b3d2dfba4efcd3921de7684 Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 00:38:01 +0200 Subject: [PATCH 03/17] Further implementation of progress indicator with cmake integration --- source/centipede/util/CMakeLists.txt | 4 +- source/centipede/util/progress_indicator.hpp | 188 +++++++++++-------- 2 files changed, 114 insertions(+), 78 deletions(-) diff --git a/source/centipede/util/CMakeLists.txt b/source/centipede/util/CMakeLists.txt index 9034c594..8e985f7c 100644 --- a/source/centipede/util/CMakeLists.txt +++ b/source/centipede/util/CMakeLists.txt @@ -3,5 +3,7 @@ target_sources( PUBLIC FILE_SET publicHeaders TYPE HEADERS - FILES common_traits.hpp error_types.hpp return_types.hpp + FILES common_traits.hpp error_types.hpp return_types.hpp progress_indicator.hpp ) + +target_link_libraries(core PUBLIC indicators::indicators) diff --git a/source/centipede/util/progress_indicator.hpp b/source/centipede/util/progress_indicator.hpp index ac1fbdc8..d6710471 100644 --- a/source/centipede/util/progress_indicator.hpp +++ b/source/centipede/util/progress_indicator.hpp @@ -1,106 +1,140 @@ #include +#include +#include #include +#include #include +#include -using namespace indicators; -class ProgressAdaptor; - -template -struct ProgressClosure : std::ranges::range_adaptor_closure> +namespace centipede::progress { - ProgressAdaptor* adaptor; - std::size_t total_size_n; - IncrementFunT increment_fun; - - template - auto operator()(RangeT range) - { - return (*adaptor)(std::forward(range), total_size_n, increment_fun); - } -}; - -class ProgressAdaptor -{ - public: - template - auto operator()(RangeT&& range, std::size_t total_size_n, IncrementFunT increment_fun) - { - return ProgressView{ this, std::forward(range), total_size_n, increment_fun }; - } + class ProgressAdaptor; template - auto operator()(std::size_t total_size_n, IncrementFunT increment_fun) + struct ProgressClosure : std::ranges::range_adaptor_closure> { - return ProgressClosure{ {}, this, total_size_n, increment_fun }; - } + ProgressAdaptor* adaptor; + std::size_t total_size_n; + IncrementFunT increment_fun; - template - struct ProgressView - { - using IteratorType = std::ranges::iterator_t; - - ProgressView(ProgressAdaptor* progress_adaptor, - RangeT&& base_range, - std::size_t total_size_n, - IncrementFunT increment_fun) - : progress_adaptor_(progress_adaptor) - , base_range_(std::move(base_range)) - , total_size_n_(total_size_n) - , increment_fun_(increment_fun) + template + auto operator()(RangeT&& range) { + return (*adaptor)(std::forward(range), total_size_n, increment_fun); } + }; - auto begin() { return Iterator{ progress_adaptor_, this, base_range_.begin() }; } + class ProgressAdaptor + { + public: + template + auto operator()(RangeT&& range, std::size_t total_size_n, IncrementFunT increment_fun) + { + return ProgressView{ + this, std::forward(range), total_size_n, increment_fun + }; + } - auto end() { return base_range_.end(); } + template + auto operator()(std::size_t total_size_n, IncrementFunT increment_fun) + { + return ProgressClosure{ {}, this, total_size_n, increment_fun }; + } - class Iterator + template + struct ProgressView { - public: - Iterator(ProgressAdaptor* progress_adaptor, ProgressView* progress_view, IteratorType current_it) - : progress_adaptor_(progress_adaptor) - , progress_view_(progress_view) - , current_it_(current_it) + using IteratorType = std::ranges::iterator_t; + + ProgressView(ProgressAdaptor* progress_adaptor, + RangeT&& base_range, + std::size_t total_size_n, + IncrementFunT increment_fun) + : base_range_(base_range) + , total_size_n_(total_size_n) + , increment_fun_(increment_fun) + , progress_adaptor_(progress_adaptor) { } - auto operator++() + auto begin() { - ++current_it_; - count_n_ += progress_view_->increment_fun_(); - progress_adaptor_->bar_.set_progress(100 * count_n_ / progress_view_->total_size_n_); + auto it = Iterator{ progress_adaptor_, this, base_range_.begin() }; + + it.add_progress(); + + return it; } - auto operator*() { return *current_it_; } + auto end() { return base_range_.end(); } - auto operator==(auto& other) { return current_it_ == other; } - auto operator!=(auto& other) { return current_it_ != other; } - auto operator==(const auto& other) const { return current_it_ == other; } - auto operator!=(const auto& other) const { return current_it_ != other; } + class Iterator + { + public: + Iterator(ProgressAdaptor* progress_adaptor, ProgressView* progress_view, IteratorType current_it) + : progress_adaptor_(progress_adaptor) + , progress_view_(progress_view) + , current_it_(current_it) + { + } + + auto operator++() + { + ++current_it_; + add_progress(); + return *this; + } + + auto operator*() { return *current_it_; } + + auto operator==(auto& other) { return current_it_ == other; } + + auto operator!=(auto& other) { return current_it_ != other; } + + auto operator==(const auto& other) const { return current_it_ == other; } + + auto operator!=(const auto& other) const { return current_it_ != other; } + + void add_progress() + { + if (finished_) + { + return; + } + count_n_ += progress_view_->increment_fun_(); + const auto percent = 100 * count_n_ / progress_view_->total_size_n_; + progress_adaptor_->bar_.set_progress(percent); + if (percent == 100) + { + finished_ = true; + } + } + + private: + ProgressAdaptor* progress_adaptor_; + ProgressView* progress_view_; + IteratorType current_it_; + std::size_t count_n_{}; + bool finished_{ false }; + }; private: + RangeT base_range_; + std::size_t total_size_n_; + IncrementFunT increment_fun_; ProgressAdaptor* progress_adaptor_; - ProgressView* progress_view_; - IteratorType current_it_; - std::size_t count_n_{}; }; private: - RangeT base_range_; - std::size_t total_size_n_; - IncrementFunT increment_fun_; - ProgressAdaptor* progress_adaptor_; + indicators::ProgressBar bar_{ indicators::option::BarWidth{ 50 }, + indicators::option::Start{ "[" }, + indicators::option::Fill{ "=" }, + indicators::option::Lead{ ">" }, + indicators::option::Remainder{ " " }, + indicators::option::End{ "]" }, + indicators::option::ForegroundColor{ indicators::Color::green }, + indicators::option::ShowPercentage{ true }, + indicators::option::FontStyles{ + std::vector{ indicators::FontStyle::bold } } }; }; - - private: - ProgressBar bar_{ option::BarWidth{ 50 }, - option::Start{ "[" }, - option::Fill{ "=" }, - option::Lead{ ">" }, - option::Remainder{ " " }, - option::End{ "]" }, - option::PostfixText{ "Extracting Archive" }, - option::ForegroundColor{ Color::green }, - option::ShowPercentage{ true }, - option::FontStyles{ std::vector{ FontStyle::bold } } }; -}; +} // namespace centipede::progress From b4f232f97ed306352a9fcecf21707a6c68d9e8e9 Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 00:38:32 +0200 Subject: [PATCH 04/17] Added functions to access file size, as well as the size of last read entry in bytes --- source/centipede/reader/binary.cpp | 1 + source/centipede/reader/binary.hpp | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/source/centipede/reader/binary.cpp b/source/centipede/reader/binary.cpp index 7ac5e3ee..490ab3b9 100644 --- a/source/centipede/reader/binary.cpp +++ b/source/centipede/reader/binary.cpp @@ -224,6 +224,7 @@ namespace centipede::reader { return std::unexpected{ size.error() }; } + last_entry_bytes_ = (read_size + 1U) * sizeof(uint32_t); ++n_entries_; size_ = size.value(); return size.value(); diff --git a/source/centipede/reader/binary.hpp b/source/centipede/reader/binary.hpp index 2873318c..646870ee 100644 --- a/source/centipede/reader/binary.hpp +++ b/source/centipede/reader/binary.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -169,6 +170,15 @@ namespace centipede::reader */ [[nodiscard]] constexpr auto get_n_entries() const -> std::size_t { return n_entries_; } + // TODO: Add documentation + [[nodiscard]] auto get_file_size() const -> std::size_t + { + return static_cast(std::filesystem::file_size(config_.in_filename)); + } + + // TODO: Add documentation + [[nodiscard]] auto get_last_entry_bytes() const -> std::size_t { return last_entry_bytes_; } + /** * @brief Checks if last read operation reached end of file. * @return Returns true if end of file is reached. @@ -298,6 +308,9 @@ namespace centipede::reader */ auto operator!=(const Sentinel&) const -> bool { return reader_->status_ == ErrorCode::invalid; } + // TODO: add documentation + bool operator==(Sentinel) const { return reader_->status_ != ErrorCode::invalid; } + private: Binary* reader_{}; //!< Associated Binary reader instance. EntrySpan current_{}; //!< Current iterator value. @@ -324,7 +337,9 @@ namespace centipede::reader std::ifstream input_file_; //!< Input file handler std::size_t size_{}; //!< Number of Entrypoints in the current entry std::size_t n_entries_{}; //!< Total number of entries read by this instance - bool end_of_file_{ false }; //!< Indicates if end of file is reached. Gets updated on read. + std::size_t last_entry_bytes_{}; // TODO: Add documentation + + bool end_of_file_{ false }; //!< Indicates if end of file is reached. Gets updated on read. ErrorCode status_{ ErrorCode::invalid }; void reset(); From d08b9e548c23981d718f1e98c35cb6b2ee9d894f Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 00:39:17 +0200 Subject: [PATCH 05/17] Testing the progress indicator! --- test/integration_tests/test_reader.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/integration_tests/test_reader.cpp b/test/integration_tests/test_reader.cpp index e3ba3fde..405fd339 100644 --- a/test/integration_tests/test_reader.cpp +++ b/test/integration_tests/test_reader.cpp @@ -1,9 +1,13 @@ #include "centipede/reader/binary.hpp" +#include "centipede/util/progress_indicator.hpp" #include #include +#include auto main() -> int { + static_assert(std::ranges::range); + static_assert(std::ranges::input_range); auto reader = centipede::reader::Binary{ centipede::reader::Binary::Config{ .in_filename = "output.bin" } }; auto init_err = reader.init(); if (not init_err.has_value()) @@ -12,7 +16,9 @@ auto main() -> int return EXIT_FAILURE; } - for ([[maybe_unused]] const auto& entry : reader) + auto progress_adaotor = centipede::progress::ProgressAdaptor{}; + for ([[maybe_unused]] const auto& entry : + reader | progress_adaotor(reader.get_file_size(), [&reader]() { return reader.get_last_entry_bytes(); })) { } From 7313f603870a72f67d35d8830d51baa341582549 Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 01:05:01 +0200 Subject: [PATCH 06/17] Added some important todos I want to implement soon --- source/centipede/util/progress_indicator.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/centipede/util/progress_indicator.hpp b/source/centipede/util/progress_indicator.hpp index d6710471..a1200837 100644 --- a/source/centipede/util/progress_indicator.hpp +++ b/source/centipede/util/progress_indicator.hpp @@ -8,6 +8,12 @@ namespace centipede::progress { + // TODO: + // Overload ProgressAdaptor () to: + // 1) iterate over n elements (instead of increment_fun) + // 2) iterate by 1 (for standard ranges) + // harden templates: use concepts, use std::function + // ProgressAdaptor constructor that takes some config struct (to config the prog bar) class ProgressAdaptor; template From b31cc68d90aef1855ad1b729b354344bcd5deb96 Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 11:29:33 +0200 Subject: [PATCH 07/17] Removed template arguments for IncrementFunT and replaced it with std::function --- source/centipede/util/progress_indicator.hpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/source/centipede/util/progress_indicator.hpp b/source/centipede/util/progress_indicator.hpp index a1200837..897263f1 100644 --- a/source/centipede/util/progress_indicator.hpp +++ b/source/centipede/util/progress_indicator.hpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -16,8 +17,9 @@ namespace centipede::progress // ProgressAdaptor constructor that takes some config struct (to config the prog bar) class ProgressAdaptor; - template - struct ProgressClosure : std::ranges::range_adaptor_closure> + using IncrementFunT = std::function; + + struct ProgressClosure : std::ranges::range_adaptor_closure { ProgressAdaptor* adaptor; std::size_t total_size_n; @@ -33,21 +35,18 @@ namespace centipede::progress class ProgressAdaptor { public: - template + template auto operator()(RangeT&& range, std::size_t total_size_n, IncrementFunT increment_fun) { - return ProgressView{ - this, std::forward(range), total_size_n, increment_fun - }; + return ProgressView{ this, std::forward(range), total_size_n, increment_fun }; } - template auto operator()(std::size_t total_size_n, IncrementFunT increment_fun) { - return ProgressClosure{ {}, this, total_size_n, increment_fun }; + return ProgressClosure{ {}, this, total_size_n, increment_fun }; } - template + template struct ProgressView { using IteratorType = std::ranges::iterator_t; From 7b5a692aca2e37b739085dfb20c395856e86e27c Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 11:32:51 +0200 Subject: [PATCH 08/17] Using concept range --- source/centipede/util/progress_indicator.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/centipede/util/progress_indicator.hpp b/source/centipede/util/progress_indicator.hpp index 897263f1..cc332537 100644 --- a/source/centipede/util/progress_indicator.hpp +++ b/source/centipede/util/progress_indicator.hpp @@ -36,6 +36,7 @@ namespace centipede::progress { public: template + requires std::ranges::range auto operator()(RangeT&& range, std::size_t total_size_n, IncrementFunT increment_fun) { return ProgressView{ this, std::forward(range), total_size_n, increment_fun }; @@ -47,6 +48,7 @@ namespace centipede::progress } template + requires std::ranges::range struct ProgressView { using IteratorType = std::ranges::iterator_t; From 41ed3b0873603e757a256f8b17904befe766103b Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 11:33:18 +0200 Subject: [PATCH 09/17] Removed TODO --- source/centipede/util/progress_indicator.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/source/centipede/util/progress_indicator.hpp b/source/centipede/util/progress_indicator.hpp index cc332537..2e7b92f9 100644 --- a/source/centipede/util/progress_indicator.hpp +++ b/source/centipede/util/progress_indicator.hpp @@ -13,7 +13,6 @@ namespace centipede::progress // Overload ProgressAdaptor () to: // 1) iterate over n elements (instead of increment_fun) // 2) iterate by 1 (for standard ranges) - // harden templates: use concepts, use std::function // ProgressAdaptor constructor that takes some config struct (to config the prog bar) class ProgressAdaptor; From 731f27fbaa2fea050409f5bebd66c35c0ac6a8f1 Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 12:32:53 +0200 Subject: [PATCH 10/17] Added () overload to iterate up to a certain number of elements. Needs fixing --- source/centipede/util/progress_indicator.hpp | 52 +++++++++++++++----- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/source/centipede/util/progress_indicator.hpp b/source/centipede/util/progress_indicator.hpp index 2e7b92f9..11f54ef9 100644 --- a/source/centipede/util/progress_indicator.hpp +++ b/source/centipede/util/progress_indicator.hpp @@ -14,6 +14,7 @@ namespace centipede::progress // 1) iterate over n elements (instead of increment_fun) // 2) iterate by 1 (for standard ranges) // ProgressAdaptor constructor that takes some config struct (to config the prog bar) + // Error Handling! class ProgressAdaptor; using IncrementFunT = std::function; @@ -41,6 +42,20 @@ namespace centipede::progress return ProgressView{ this, std::forward(range), total_size_n, increment_fun }; } + template + requires std::ranges::range + auto operator()(RangeT&& range, std::size_t total_size_n) + { + return ProgressView{ + this, std::forward(range), total_size_n, []() -> std::size_t { return 1; } + }; + } + + auto operator()(std::size_t total_size_n) + { + return ProgressClosure{ {}, this, total_size_n, []() -> std::size_t { return 1; } }; + } + auto operator()(std::size_t total_size_n, IncrementFunT increment_fun) { return ProgressClosure{ {}, this, total_size_n, increment_fun }; @@ -51,6 +66,7 @@ namespace centipede::progress struct ProgressView { using IteratorType = std::ranges::iterator_t; + using SentinelType = std::ranges::sentinel_t; ProgressView(ProgressAdaptor* progress_adaptor, RangeT&& base_range, @@ -65,41 +81,53 @@ namespace centipede::progress auto begin() { - auto it = Iterator{ progress_adaptor_, this, base_range_.begin() }; - - it.add_progress(); - - return it; + return Iterator{ + progress_adaptor_, this, std::ranges::begin(base_range_), std::ranges::end(base_range_) + }; } - auto end() { return base_range_.end(); } + auto end() { return Sentinel{}; } + struct Sentinel + { + }; class Iterator { public: - Iterator(ProgressAdaptor* progress_adaptor, ProgressView* progress_view, IteratorType current_it) + Iterator(ProgressAdaptor* progress_adaptor, + ProgressView* progress_view, + IteratorType current_it, + SentinelType end_it) : progress_adaptor_(progress_adaptor) , progress_view_(progress_view) , current_it_(current_it) + , end_it_(end_it) { } auto operator++() { ++current_it_; + ++element_count_; add_progress(); return *this; } auto operator*() { return *current_it_; } - auto operator==(auto& other) { return current_it_ == other; } + bool operator==(Sentinel) + { + return current_it_ == end_it_ || element_count_ >= progress_view_->total_size_n_; + } - auto operator!=(auto& other) { return current_it_ != other; } + bool operator!=(Sentinel s) { return !(*this == s); } - auto operator==(const auto& other) const { return current_it_ == other; } + bool operator==(Sentinel) const + { + return current_it_ == end_it_ || element_count_ >= progress_view_->total_size_n_; + } - auto operator!=(const auto& other) const { return current_it_ != other; } + bool operator!=(Sentinel s) const { return !(*this == s); } void add_progress() { @@ -120,6 +148,8 @@ namespace centipede::progress ProgressAdaptor* progress_adaptor_; ProgressView* progress_view_; IteratorType current_it_; + SentinelType end_it_; + std::size_t element_count_{}; std::size_t count_n_{}; bool finished_{ false }; }; From 46216b153ad1bb6a5d35ab2712d52eb8d962dd80 Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 17:54:39 +0200 Subject: [PATCH 11/17] Added concept, marked as complete when finished --- source/centipede/util/progress_indicator.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/centipede/util/progress_indicator.hpp b/source/centipede/util/progress_indicator.hpp index 11f54ef9..e8e58982 100644 --- a/source/centipede/util/progress_indicator.hpp +++ b/source/centipede/util/progress_indicator.hpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -26,6 +27,7 @@ namespace centipede::progress IncrementFunT increment_fun; template + requires std::ranges::range auto operator()(RangeT&& range) { return (*adaptor)(std::forward(range), total_size_n, increment_fun); @@ -141,6 +143,7 @@ namespace centipede::progress if (percent == 100) { finished_ = true; + progress_adaptor_->bar_.mark_as_completed(); } } From 9dba304a45ef50cf2c5a86f9bc9541305549add1 Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 18:06:30 +0200 Subject: [PATCH 12/17] ProgressView now has a view to the base range, instead of the range itself.. Not sure about all the move/forward stuff --- source/centipede/util/progress_indicator.hpp | 25 +++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/source/centipede/util/progress_indicator.hpp b/source/centipede/util/progress_indicator.hpp index e8e58982..ce5dddad 100644 --- a/source/centipede/util/progress_indicator.hpp +++ b/source/centipede/util/progress_indicator.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace centipede::progress @@ -19,6 +20,8 @@ namespace centipede::progress class ProgressAdaptor; using IncrementFunT = std::function; + template + using BaseView = std::views::all_t; struct ProgressClosure : std::ranges::range_adaptor_closure { @@ -41,16 +44,19 @@ namespace centipede::progress requires std::ranges::range auto operator()(RangeT&& range, std::size_t total_size_n, IncrementFunT increment_fun) { - return ProgressView{ this, std::forward(range), total_size_n, increment_fun }; + return ProgressView>{ + this, std::views::all(std::forward(range)), total_size_n, std::move(increment_fun) + }; } template requires std::ranges::range auto operator()(RangeT&& range, std::size_t total_size_n) { - return ProgressView{ - this, std::forward(range), total_size_n, []() -> std::size_t { return 1; } - }; + return ProgressView>{ this, + std::views::all(std::forward(range)), + total_size_n, + std::move([]() -> std::size_t { return 1; }) }; } auto operator()(std::size_t total_size_n) @@ -60,21 +66,22 @@ namespace centipede::progress auto operator()(std::size_t total_size_n, IncrementFunT increment_fun) { - return ProgressClosure{ {}, this, total_size_n, increment_fun }; + return ProgressClosure{ {}, this, total_size_n, std::move(increment_fun) }; } template requires std::ranges::range struct ProgressView { + using BaseView = std::views::all_t; using IteratorType = std::ranges::iterator_t; using SentinelType = std::ranges::sentinel_t; ProgressView(ProgressAdaptor* progress_adaptor, - RangeT&& base_range, + BaseView base_view, std::size_t total_size_n, IncrementFunT increment_fun) - : base_range_(base_range) + : base_view_(std::move(base_view)) , total_size_n_(total_size_n) , increment_fun_(increment_fun) , progress_adaptor_(progress_adaptor) @@ -84,7 +91,7 @@ namespace centipede::progress auto begin() { return Iterator{ - progress_adaptor_, this, std::ranges::begin(base_range_), std::ranges::end(base_range_) + progress_adaptor_, this, std::ranges::begin(base_view_), std::ranges::end(base_view_) }; } @@ -158,7 +165,7 @@ namespace centipede::progress }; private: - RangeT base_range_; + BaseView base_view_; std::size_t total_size_n_; IncrementFunT increment_fun_; ProgressAdaptor* progress_adaptor_; From 86a81783053cc9bd830ffaf4c17bb9718116abbb Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 19:07:36 +0200 Subject: [PATCH 13/17] Added new error type "incomplete" to determine between an complete vs incomplete read. --- source/centipede/reader/binary.hpp | 12 ++++++------ source/centipede/util/error_types.hpp | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/centipede/reader/binary.hpp b/source/centipede/reader/binary.hpp index 646870ee..935d1d22 100644 --- a/source/centipede/reader/binary.hpp +++ b/source/centipede/reader/binary.hpp @@ -191,7 +191,7 @@ namespace centipede::reader * The status is updated during iteration and after manual read operations. * * @return - * - ErrorCode::invalid while iteration/reading is in progress. + * - ErrorCode::incomplete while iteration/reading is in progress. * - ErrorCode::success if iteration finished successfully. * - Any other ErrorCode if a read or parsing error occurred. */ @@ -245,7 +245,7 @@ namespace centipede::reader explicit Iterator(Binary* reader_ptr) : reader_{ reader_ptr } { - reader_->status_ = ErrorCode::invalid; + reader_->status_ = ErrorCode::incomplete; ++(*this); } @@ -286,7 +286,7 @@ namespace centipede::reader } current_ = reader_->get_current_entry(); - reader_->status_ = ErrorCode::invalid; + reader_->status_ = ErrorCode::incomplete; return *this; } /** @@ -306,10 +306,10 @@ namespace centipede::reader * * @return Returns true while iteration is not finished. */ - auto operator!=(const Sentinel&) const -> bool { return reader_->status_ == ErrorCode::invalid; } + auto operator!=(const Sentinel&) const -> bool { return reader_->status_ == ErrorCode::incomplete; } // TODO: add documentation - bool operator==(Sentinel) const { return reader_->status_ != ErrorCode::invalid; } + bool operator==(Sentinel) const { return reader_->status_ != ErrorCode::incomplete; } private: Binary* reader_{}; //!< Associated Binary reader instance. @@ -340,7 +340,7 @@ namespace centipede::reader std::size_t last_entry_bytes_{}; // TODO: Add documentation bool end_of_file_{ false }; //!< Indicates if end of file is reached. Gets updated on read. - ErrorCode status_{ ErrorCode::invalid }; + ErrorCode status_{ ErrorCode::incomplete }; void reset(); auto read_entry_to_buffer(uint32_t read_size) -> EnumError<>; diff --git a/source/centipede/util/error_types.hpp b/source/centipede/util/error_types.hpp index 81010444..0d758bb5 100644 --- a/source/centipede/util/error_types.hpp +++ b/source/centipede/util/error_types.hpp @@ -13,6 +13,7 @@ namespace centipede // TODO: duplication of comments invalid, //!< Error due to no evaluation! success, //!< No error. All good! + incomplete, //!< Operation incomplete! handler_incomp_n_locals, //!< Incompatible number of local variables from the current entrypoint. writer_neg_or_zero_sigma, //!< Zero or negative sigma occurs. See @ref writer::Binary. writer_buffer_overflow, //!< Buffer size is too small for a new entry occurs. See @ref writer::Binary. @@ -99,6 +100,8 @@ struct std::formatter return std::format_to(ctx.out(), "Reader: Filename is either empty or invalid!"); case invalid: return std::format_to(ctx.out(), "Error due to no evaluation!"); + case incomplete: + return std::format_to(ctx.out(), "Operation incomplete!"); default: break; } From e39005029cda6c2fdc01887d50903c76e493b383 Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 19:08:05 +0200 Subject: [PATCH 14/17] Added integration test for test coverage. Unit tests? --- source/centipede/util/progress_indicator.hpp | 2 +- test/integration_tests/test_reader.cpp | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/source/centipede/util/progress_indicator.hpp b/source/centipede/util/progress_indicator.hpp index ce5dddad..624f5a0d 100644 --- a/source/centipede/util/progress_indicator.hpp +++ b/source/centipede/util/progress_indicator.hpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -17,6 +16,7 @@ namespace centipede::progress // 2) iterate by 1 (for standard ranges) // ProgressAdaptor constructor that takes some config struct (to config the prog bar) // Error Handling! + // Ehm, testing? class ProgressAdaptor; using IncrementFunT = std::function; diff --git a/test/integration_tests/test_reader.cpp b/test/integration_tests/test_reader.cpp index 405fd339..1f5a0f06 100644 --- a/test/integration_tests/test_reader.cpp +++ b/test/integration_tests/test_reader.cpp @@ -1,5 +1,7 @@ #include "centipede/reader/binary.hpp" +#include "centipede/util/error_types.hpp" #include "centipede/util/progress_indicator.hpp" +#include #include #include #include @@ -16,16 +18,19 @@ auto main() -> int return EXIT_FAILURE; } - auto progress_adaotor = centipede::progress::ProgressAdaptor{}; + auto progress_adaptor = centipede::progress::ProgressAdaptor{}; for ([[maybe_unused]] const auto& entry : - reader | progress_adaotor(reader.get_file_size(), [&reader]() { return reader.get_last_entry_bytes(); })) + reader | progress_adaptor(reader.get_file_size(), [&reader]() { return reader.get_last_entry_bytes(); })) { } if (not reader.is_ok()) { - std::println(stderr, "Error: {}", reader.get_status()); - return EXIT_FAILURE; + if (reader.get_status() != centipede::ErrorCode::incomplete) + { + std::println(stderr, "Error: {}", reader.get_status()); + return EXIT_FAILURE; + } } if (reader.get_n_entries() == 0U) @@ -34,5 +39,11 @@ auto main() -> int return EXIT_FAILURE; } + auto array = std::array{ 1, 2, 3, 4 }; + + for ([[maybe_unused]] auto elem : array | progress_adaptor(array.size())) + { + } + return EXIT_SUCCESS; } From 2621591d5d4fc8bbd36d5a62e103a9b8d326a782 Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 19:13:40 +0200 Subject: [PATCH 15/17] Removed finished_ because it's never reached anyways. --- source/centipede/util/progress_indicator.hpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source/centipede/util/progress_indicator.hpp b/source/centipede/util/progress_indicator.hpp index 624f5a0d..8198365d 100644 --- a/source/centipede/util/progress_indicator.hpp +++ b/source/centipede/util/progress_indicator.hpp @@ -140,16 +140,11 @@ namespace centipede::progress void add_progress() { - if (finished_) - { - return; - } count_n_ += progress_view_->increment_fun_(); const auto percent = 100 * count_n_ / progress_view_->total_size_n_; progress_adaptor_->bar_.set_progress(percent); if (percent == 100) { - finished_ = true; progress_adaptor_->bar_.mark_as_completed(); } } @@ -161,7 +156,6 @@ namespace centipede::progress SentinelType end_it_; std::size_t element_count_{}; std::size_t count_n_{}; - bool finished_{ false }; }; private: From e71eb2efb1dbaef97e25cba038d1647b58cd2570 Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 19:18:58 +0200 Subject: [PATCH 16/17] Forgot to add the range concept to closure --- source/centipede/util/progress_indicator.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/centipede/util/progress_indicator.hpp b/source/centipede/util/progress_indicator.hpp index 8198365d..32d3e3c0 100644 --- a/source/centipede/util/progress_indicator.hpp +++ b/source/centipede/util/progress_indicator.hpp @@ -20,7 +20,9 @@ namespace centipede::progress class ProgressAdaptor; using IncrementFunT = std::function; + template + requires std::ranges::range using BaseView = std::views::all_t; struct ProgressClosure : std::ranges::range_adaptor_closure From b3991d420d69e6ed74436446eb86a49518a7f38f Mon Sep 17 00:00:00 2001 From: Baryonics Date: Wed, 1 Jul 2026 19:21:55 +0200 Subject: [PATCH 17/17] renamed s to sentinel, since it doesn't fit the style --- source/centipede/util/progress_indicator.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/centipede/util/progress_indicator.hpp b/source/centipede/util/progress_indicator.hpp index 32d3e3c0..0d23f1d3 100644 --- a/source/centipede/util/progress_indicator.hpp +++ b/source/centipede/util/progress_indicator.hpp @@ -131,14 +131,14 @@ namespace centipede::progress return current_it_ == end_it_ || element_count_ >= progress_view_->total_size_n_; } - bool operator!=(Sentinel s) { return !(*this == s); } + bool operator!=(Sentinel sentinel) { return !(*this == sentinel); } bool operator==(Sentinel) const { return current_it_ == end_it_ || element_count_ >= progress_view_->total_size_n_; } - bool operator!=(Sentinel s) const { return !(*this == s); } + bool operator!=(Sentinel sentinel) const { return !(*this == sentinel); } void add_progress() {