Program Listing for File FeedbackCommons.hpp

↰ Return to documentation for file (src/feedback/FeedbackCommons.hpp)

#ifndef FEEDBACKCOMMONS_HPP
#define FEEDBACKCOMMONS_HPP

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <stdexcept>
#include <string>
#include <string_view>

namespace feedback
{
    enum class WRwindModel : std::uint8_t
    {
        // NOLINTBEGIN(readability-identifier-naming) -- trailing underscore on each enumerator matches yields::Channel's own identical convention (see its own comment)
        none_,
        lOverc_,
        nugisLamers00_
        // NOLINTEND(readability-identifier-naming)
    };

    constexpr std::array<std::string_view, 3> wrWindModelStr{
        "none",
        "l_over_c",
        "nugis_lamers_00"
    };

    inline auto wrWindModelFromString(const std::string_view name) -> WRwindModel
    {
        const auto* const it = std::ranges::find(wrWindModelStr, name);
        if (it == wrWindModelStr.end())
        {
            throw std::invalid_argument("'" + std::string(name) +
                "' is not a recognized WR wind model (expected none, "
                "l_over_c, or nugis_lamers_00)");
        }
        return static_cast<WRwindModel>(std::distance(wrWindModelStr.begin(), it));
    }

    inline auto wrWindModelToString(const WRwindModel model) -> std::string_view
    {
        return wrWindModelStr.at(static_cast<std::size_t>(model));
    }

    enum class OBwindModel : std::uint8_t
    {
        // NOLINTBEGIN(readability-identifier-naming) -- trailing underscore on each enumerator matches yields::Channel's own identical convention (see its own comment)
        none_,
        vink01_,
        vinkSander21_
        // NOLINTEND(readability-identifier-naming)
    };

    constexpr std::array<std::string_view, 3> obWindModelStr{
        "none",
        "vink_01",
        "vink_sander_21"
    };

    inline auto obWindModelFromString(const std::string_view name) -> OBwindModel
    {
        const auto* const it = std::ranges::find(obWindModelStr, name);
        if (it == obWindModelStr.end())
        {
            throw std::invalid_argument("'" + std::string(name) +
                "' is not a recognized OB wind model (expected none, "
                "vink_01, or vink_sander_21)");
        }
        return static_cast<OBwindModel>(std::distance(obWindModelStr.begin(), it));
    }

    inline auto obWindModelToString(const OBwindModel model) -> std::string_view
    {
        return obWindModelStr.at(static_cast<std::size_t>(model));
    }

    enum class AGBwindModel : std::uint8_t
    {
        // NOLINTBEGIN(readability-identifier-naming) -- trailing underscore on each enumerator matches yields::Channel's own identical convention (see its own comment)
        none_,
        slug2_
        // NOLINTEND(readability-identifier-naming)
    };

    constexpr std::array<std::string_view, 2> agbWindModelStr{
        "none",
        "slug2"
    };

    inline auto agbWindModelFromString(const std::string_view name) -> AGBwindModel
    {
        const auto* const it = std::ranges::find(agbWindModelStr, name);
        if (it == agbWindModelStr.end())
        {
            throw std::invalid_argument("'" + std::string(name) +
                "' is not a recognized AGB wind model (expected none or slug2)");
        }
        return static_cast<AGBwindModel>(std::distance(agbWindModelStr.begin(), it));
    }

    inline auto agbWindModelToString(const AGBwindModel model) -> std::string_view
    {
        return agbWindModelStr.at(static_cast<std::size_t>(model));
    }

    enum class OtherwindModel : std::uint8_t
    {
        // NOLINTBEGIN(readability-identifier-naming) -- trailing underscore on each enumerator matches yields::Channel's own identical convention (see its own comment)
        none_,
        vesc_
        // NOLINTEND(readability-identifier-naming)
    };

    constexpr std::array<std::string_view, 2> otherWindModelStr{
        "none",
        "vesc"
    };

    inline auto otherWindModelFromString(const std::string_view name) -> OtherwindModel
    {
        const auto* const it = std::ranges::find(otherWindModelStr, name);
        if (it == otherWindModelStr.end())
        {
            throw std::invalid_argument("'" + std::string(name) +
                "' is not a recognized other-star wind model (expected none or vesc)");
        }
        return static_cast<OtherwindModel>(std::distance(otherWindModelStr.begin(), it));
    }

    inline auto otherWindModelToString(const OtherwindModel model) -> std::string_view
    {
        return otherWindModelStr.at(static_cast<std::size_t>(model));
    }

} // namespace feedback

#endif // FEEDBACKCOMMONS_HPP