diff options
author | Spartan322 <Megacake1234@gmail.com> | 2023-10-04 10:55:42 +0200 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2023-10-12 16:18:37 +0200 |
commit | 5c7af98e3a8a3e7f1462e389c273566d7cdaa5d4 (patch) | |
tree | efeebd80a707a07eda296883772140e9ce32a9ee /src/openvic-simulation/utility/ConstexprIntToStr.hpp | |
parent | 1d113b46161f27551bc3a6a857b8727cfb657b81 (diff) |
Add static `Dataloader::search_for_game_path(fs::path)`
Searches for Victoria 2 according to the supplied path
If supplied path is empty, presumes Steam install according to platform environment variables
If invalid supplied path, falls back to empty path behavior
Supports Steam install on Windows, Mac, Linux, and FreeBSD
Supports Windows registry
Update .clang-format categories to include lexy-vdf
Add Utility/ConstexprIntToStr.hpp
Diffstat (limited to 'src/openvic-simulation/utility/ConstexprIntToStr.hpp')
-rw-r--r-- | src/openvic-simulation/utility/ConstexprIntToStr.hpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/openvic-simulation/utility/ConstexprIntToStr.hpp b/src/openvic-simulation/utility/ConstexprIntToStr.hpp new file mode 100644 index 0000000..e383365 --- /dev/null +++ b/src/openvic-simulation/utility/ConstexprIntToStr.hpp @@ -0,0 +1,56 @@ +#pragma once + +#include <array> +#include <cstddef> +#include <string_view> +#include <utility> + +namespace OpenVic::ConstexprIntToStr { + template<class T, T... values1, T... values2> + constexpr decltype(auto) append_sequence(std::integer_sequence<T, values1...>, std::integer_sequence<T, values2...>) { + return std::integer_sequence<T, values1..., values2...> {}; + } + + template<class sequence_t> + struct string_sequence_to_view; + + template<char... chars> + struct string_sequence_to_view<std::integer_sequence<char, chars...>> { + static constexpr decltype(auto) get() { + return std::string_view { c_str }; + } + + static constexpr const char c_str[] { chars..., char {} }; + }; + + template<std::size_t value> + constexpr decltype(auto) integer_to_string_sequence() { + constexpr auto digits = []() { + return "0123456789abcdefghijklmnopqrstuvwxyz"; + }; + + constexpr std::size_t remainder = value % 10; + constexpr std::size_t next_value = value / 10; + + if constexpr (next_value != 0) { + return append_sequence(integer_to_string_sequence<next_value>(), std::integer_sequence<char, digits()[remainder]> {}); + } else { + return std::integer_sequence<char, digits()[remainder]> {}; + } + } + template<std::size_t i> + constexpr std::string_view make_string() { + return string_sequence_to_view<decltype(integer_to_string_sequence<i>())> {}.c_str; + } + + template<std::size_t... ManyIntegers> + constexpr auto generate_itosv_array(std::integer_sequence<std::size_t, ManyIntegers...>) { + return std::array<std::string_view, sizeof...(ManyIntegers)> { make_string<ManyIntegers>()... }; + } + + // Make array of N string views, countings up from 0 to N - 1 + template<std::size_t N> + constexpr auto make_itosv_array() { + return generate_itosv_array(std::make_integer_sequence<std::size_t, N>()); + } +}
\ No newline at end of file |