/* Activity Indicators for Modern C++ https://github.com/p-ranav/indicators Licensed under the MIT License . SPDX-License-Identifier: MIT Copyright (c) 2019 Dawid Pilarski . Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef INDICATORS_SETTING #define INDICATORS_SETTING #include #include #include #include #include #include #include #include #include #include namespace indicators { namespace details { template struct if_else; template <> struct if_else { using type = std::true_type; }; template <> struct if_else { using type = std::false_type; }; template struct if_else_type; template struct if_else_type { using type = True; }; template struct if_else_type { using type = False; }; template struct conjuction; template <> struct conjuction<> : std::true_type {}; template struct conjuction : if_else_type>::type {}; template struct disjunction; template <> struct disjunction<> : std::false_type {}; template struct disjunction : if_else_type>::type {}; enum class ProgressBarOption { bar_width = 0, prefix_text, postfix_text, start, end, fill, lead, remainder, max_postfix_text_len, completed, show_percentage, show_elapsed_time, show_remaining_time, saved_start_time, foreground_color, spinner_show, spinner_states, font_styles, hide_bar_when_complete, min_progress, max_progress, progress_type, stream }; template struct Setting { template ::value>::type> explicit Setting(Args &&... args) : value(std::forward(args)...) {} Setting(const Setting &) = default; Setting(Setting &&) = default; static constexpr auto id = Id; using type = T; T value{}; }; template struct is_setting : std::false_type {}; template struct is_setting> : std::true_type {}; template struct are_settings : if_else...>::value>::type {}; template <> struct are_settings<> : std::true_type {}; template struct is_setting_from_tuple; template struct is_setting_from_tuple> : std::true_type {}; template struct is_setting_from_tuple> : if_else...>::value>::type {}; template struct are_settings_from_tuple : if_else...>::value>::type {}; template struct always_true { static constexpr auto value = true; }; template Default &&get_impl(Default &&def) { return std::forward(def); } template auto get_impl(Default && /*def*/, T &&first, Args &&... /*tail*/) -> typename std::enable_if<(std::decay::type::id == Id), decltype(std::forward(first))>::type { return std::forward(first); } template auto get_impl(Default &&def, T && /*first*/, Args &&... tail) -> typename std::enable_if<(std::decay::type::id != Id), decltype(get_impl(std::forward(def), std::forward(tail)...))>::type { return get_impl(std::forward(def), std::forward(tail)...); } template ::value, void>::type> auto get(Default &&def, Args &&... args) -> decltype(details::get_impl(std::forward(def), std::forward(args)...)) { return details::get_impl(std::forward(def), std::forward(args)...); } template using StringSetting = Setting; template using IntegerSetting = Setting; template using BooleanSetting = Setting; template struct option_idx; template struct option_idx, counter> : if_else_type<(Id == T::id), std::integral_constant, option_idx, counter + 1>>::type {}; template struct option_idx, counter> { static_assert(always_true<(ProgressBarOption)Id>::value, "No such option was found"); }; template auto get_value(Settings &&settings) -> decltype((std::get::type>::value>( std::declval()))) { return std::get::type>::value>( std::forward(settings)); } } // namespace details namespace option { using BarWidth = details::IntegerSetting; using PrefixText = details::StringSetting; using PostfixText = details::StringSetting; using Start = details::StringSetting; using End = details::StringSetting; using Fill = details::StringSetting; using Lead = details::StringSetting; using Remainder = details::StringSetting; using MaxPostfixTextLen = details::IntegerSetting; using Completed = details::BooleanSetting; using ShowPercentage = details::BooleanSetting; using ShowElapsedTime = details::BooleanSetting; using ShowRemainingTime = details::BooleanSetting; using SavedStartTime = details::BooleanSetting; using ForegroundColor = details::Setting; using ShowSpinner = details::BooleanSetting; using SpinnerStates = details::Setting, details::ProgressBarOption::spinner_states>; using HideBarWhenComplete = details::BooleanSetting; using FontStyles = details::Setting, details::ProgressBarOption::font_styles>; using MinProgress = details::IntegerSetting; using MaxProgress = details::IntegerSetting; using ProgressType = details::Setting; using Stream = details::Setting; } // namespace option } // namespace indicators #endif