| 2914 | namespace indicators { |
| 2915 | |
| 2916 | template <typename Indicator> class DynamicProgress { |
| 2917 | using Settings = std::tuple<option::HideBarWhenComplete>; |
| 2918 | |
| 2919 | public: |
| 2920 | template <typename... Indicators> explicit DynamicProgress(Indicators &... bars) { |
| 2921 | bars_ = {bars...}; |
| 2922 | for (auto &bar : bars_) { |
| 2923 | bar.get().multi_progress_mode_ = true; |
| 2924 | ++total_count_; |
| 2925 | ++incomplete_count_; |
| 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | Indicator &operator[](size_t index) { |
| 2930 | print_progress(); |
| 2931 | std::lock_guard<std::mutex> lock{mutex_}; |
| 2932 | return bars_[index].get(); |
| 2933 | } |
| 2934 | |
| 2935 | size_t push_back(Indicator &bar) { |
| 2936 | std::lock_guard<std::mutex> lock{mutex_}; |
| 2937 | bar.multi_progress_mode_ = true; |
| 2938 | bars_.push_back(bar); |
| 2939 | return bars_.size() - 1; |
| 2940 | } |
| 2941 | |
| 2942 | template <typename T, details::ProgressBarOption id> |
| 2943 | void set_option(details::Setting<T, id> &&setting) { |
| 2944 | static_assert(!std::is_same<T, typename std::decay<decltype(details::get_value<id>( |
| 2945 | std::declval<Settings>()))>::type>::value, |
| 2946 | "Setting has wrong type!"); |
| 2947 | std::lock_guard<std::mutex> lock(mutex_); |
| 2948 | get_value<id>() = std::move(setting).value; |
| 2949 | } |
| 2950 | |
| 2951 | template <typename T, details::ProgressBarOption id> |
| 2952 | void set_option(const details::Setting<T, id> &setting) { |
| 2953 | static_assert(!std::is_same<T, typename std::decay<decltype(details::get_value<id>( |
| 2954 | std::declval<Settings>()))>::type>::value, |
| 2955 | "Setting has wrong type!"); |
| 2956 | std::lock_guard<std::mutex> lock(mutex_); |
| 2957 | get_value<id>() = setting.value; |
| 2958 | } |
| 2959 | |
| 2960 | private: |
| 2961 | Settings settings_; |
| 2962 | std::atomic<bool> started_{false}; |
| 2963 | std::mutex mutex_; |
| 2964 | std::vector<std::reference_wrapper<Indicator>> bars_; |
| 2965 | std::atomic<size_t> total_count_{0}; |
| 2966 | std::atomic<size_t> incomplete_count_{0}; |
| 2967 | |
| 2968 | template <details::ProgressBarOption id> |
| 2969 | auto get_value() -> decltype((details::get_value<id>(std::declval<Settings &>()).value)) { |
| 2970 | return details::get_value<id>(settings_).value; |
| 2971 | } |
| 2972 | |
| 2973 | template <details::ProgressBarOption id> |
nothing calls this directly
no outgoing calls
no test coverage detected