17 #ifndef OSMANIP_PROGRESSBAR_MULTIPROGRESSBAR_HPP
18 #define OSMANIP_PROGRESSBAR_MULTIPROGRESSBAR_HPP
34 #include <type_traits>
49 template <
size_t... Is>
59 template <
size_t N,
size_t... Is>
69 template <
size_t... Is>
80 template <
class... Indicators>
91 template <
class... Inds>
100 static size_t size() {
return sizeof...(Indicators); }
113 template <
class Func,
class... Args>
114 void for_one(
size_t idx, Func &&func, Args &&...args) {
115 call_one(idx,
gen_indices<
sizeof...(Indicators)>(), std::forward<Func>(func),
116 std::forward<Args>(args)...);
130 template <
class Func,
class... Args>
132 call_all(
gen_indices<
sizeof...(Indicators)>(), std::forward<Func>(func), std::forward<Args>(args)...);
150 template <
size_t... Ids,
class Func,
class... Args>
151 void call_one(
size_t idx,
indices<Ids...>, Func func, Args &&...args) {
152 std::lock_guard<std::mutex> lock{mutex_};
153 int32_t idx_delta = idx - last_updated_index;
154 std::string direction;
158 idx_delta = -idx_delta;
162 for (int32_t i = 0; i < idx_delta; i++) {
165 last_updated_index = idx;
169 ((void)std::forward<Func>(func)(std::get<Ids>(bars_), std::forward<Args>(args)...),
false))...);
184 template <
size_t... Ids,
class Func,
class... Args>
185 void call_all(indices<Ids...>, Func func, Args &&...args) {
186 std::lock_guard<std::mutex> lock{mutex_};
187 auto dummy = {(func(std::get<Ids>(bars_), args...), 0)...};
192 std::tuple<Indicators &...> bars_;
194 uint32_t last_updated_index;
208 template <
class... Indicators>
210 return {std::forward<Indicators>(inds)...};
234 template <
template <
class>
class PB,
class bar_type>
236 -> decltype(pb.update(bar_type{})) {
Template class used to create multi progress bars.
Definition: multi_progress_bar.hpp:81
make_MultiProgressBar(Inds &&...bars)
Construct a new make MultiProgressBar object.
Definition: multi_progress_bar.hpp:92
void for_each(Func &&func, Args &&...args)
Method used to update progress bars simultaneously.
Definition: multi_progress_bar.hpp:131
static size_t size()
Return the number of the indicators.
Definition: multi_progress_bar.hpp:100
void for_one(size_t idx, Func &&func, Args &&...args)
Method used to update the progress bar for one progress bar only.
Definition: multi_progress_bar.hpp:114
Definition: canvas.cpp:30
make_MultiProgressBar< typename std::remove_reference< Indicators >::type... > MultiProgressBar(Indicators &&...inds)
Helper function used for deduction guides.
Definition: multi_progress_bar.hpp:209
const string_pair_map crs
It is used to store the cursor commands.
Definition: cursor.cpp:42
const std::string & feat(const std::unordered_map< std::string, std::string > &generic_map, const std::string &feat_string)
It takes an std::map object as the first argument and an std::string object (map key) as the second a...
Definition: common.cpp:41
Type to generate indices for parameter packs.
Definition: multi_progress_bar.hpp:60
Type to generate indices for parameter packs.
Definition: multi_progress_bar.hpp:50
Struct used to to typedef the functor.
Definition: multi_progress_bar.hpp:222
T type
Definition: multi_progress_bar.hpp:223
Functor used to call the ProgressBar class update method.
Definition: multi_progress_bar.hpp:233
auto operator()(PB< bar_type > &pb, typename type_identity< bar_type >::type v) const -> decltype(pb.update(bar_type{}))
Definition: multi_progress_bar.hpp:235