Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/openvic-simulation/core/Typedefs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ namespace OpenVic {
#endif
}

template<class Lambda, int = (Lambda {}(), 0)>
constexpr bool is_constexpr(Lambda) {
return true;
}
constexpr bool is_constexpr(...) {
return false;
}

namespace cow {
template<typename T>
T const& read(T const& v) {
Expand Down
12 changes: 3 additions & 9 deletions src/openvic-simulation/core/memory/Formatting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@

namespace OpenVic::memory {
namespace fmt {
template<typename T, class RawAllocator = foonathan::memory::default_allocator>
using basic_memory_buffer = ::fmt::basic_memory_buffer<
T,
::fmt::inline_buffer_size,
foonathan::memory::std_allocator<
T,
OpenVic::memory::tracker<RawAllocator>
>
>;
template<typename T, size_t SIZE = ::fmt::inline_buffer_size, class RawAllocator = foonathan::memory::default_allocator>
using basic_memory_buffer =
::fmt::basic_memory_buffer<T, SIZE, foonathan::memory::std_allocator<T, OpenVic::memory::tracker<RawAllocator>>>;

inline static memory::string vformat(::fmt::string_view fmt, ::fmt::format_args args) {
memory::fmt::basic_memory_buffer<char> buf {};
Expand Down
54 changes: 27 additions & 27 deletions src/openvic-simulation/core/object/Date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct date_writer {
} else if (upper >= 0 && upper < 100) {
write2(static_cast<int>(upper));
} else {
_out = detail::write<Char>(_out, upper);
_out = fmt::detail::write<Char>(_out, upper);
}
}

Expand All @@ -118,11 +118,11 @@ struct date_writer {
}

void on_abbr_weekday() {
_out = detail::write<Char>(_out, _date.get_weekday_name().substr(0, 3));
_out = fmt::detail::write<Char>(_out, _date.get_weekday_name().substr(0, 3));
}

void on_full_weekday() {
_out = detail::write<Char>(_out, _date.get_weekday_name());
_out = fmt::detail::write<Char>(_out, _date.get_weekday_name());
}

void on_dec0_weekday(numeric_system ns) {
Expand All @@ -135,10 +135,10 @@ struct date_writer {
}

void on_abbr_month() {
_out = detail::write<Char>(_out, _date.get_month_name().substr(0, 3));
_out = fmt::detail::write<Char>(_out, _date.get_month_name().substr(0, 3));
}
void on_full_month() {
_out = detail::write<Char>(_out, _date.get_month_name());
_out = fmt::detail::write<Char>(_out, _date.get_month_name());
}

void on_dec_month(numeric_system ns, pad_type pad) {
Expand Down Expand Up @@ -177,32 +177,32 @@ struct date_writer {
char buf[8];
write_digit2_separated(
buf, //
detail::to_unsigned(_date.get_day()), //
detail::to_unsigned(_date.get_month()), //
detail::to_unsigned(split_year_lower(_date.get_year())), //
fmt::detail::to_unsigned(_date.get_day()), //
fmt::detail::to_unsigned(_date.get_month()), //
fmt::detail::to_unsigned(split_year_lower(_date.get_year())), //
'/'
);
_out = detail::copy<Char>(std::begin(buf), std::end(buf), _out);
_out = fmt::detail::copy<Char>(std::begin(buf), std::end(buf), _out);
}

void on_us_date() {
char buf[8];
write_digit2_separated(
buf, //
detail::to_unsigned(_date.get_month()), //
detail::to_unsigned(_date.get_day()), //
detail::to_unsigned(split_year_lower(_date.get_year())), //
fmt::detail::to_unsigned(_date.get_month()), //
fmt::detail::to_unsigned(_date.get_day()), //
fmt::detail::to_unsigned(split_year_lower(_date.get_year())), //
'/'
);
_out = detail::copy<Char>(std::begin(buf), std::end(buf), _out);
_out = fmt::detail::copy<Char>(std::begin(buf), std::end(buf), _out);
}

void on_iso_date() {
auto year = _date.get_year();
char buf[10];
size_t offset = 0;
if (year >= 0 && year < 10000) {
detail::write2digits(buf, static_cast<size_t>(year / 100));
fmt::detail::write2digits(buf, static_cast<size_t>(year / 100));
} else {
offset = 4;
write_year_extended(year, pad_type::zero);
Expand All @@ -211,19 +211,19 @@ struct date_writer {
write_digit2_separated(
buf + 2, //
static_cast<unsigned>(year % 100), //
detail::to_unsigned(_date.get_month()), //
detail::to_unsigned(_date.get_day()), //
fmt::detail::to_unsigned(_date.get_month()), //
fmt::detail::to_unsigned(_date.get_day()), //
'-'
);
_out = detail::copy<Char>(std::begin(buf) + offset, std::end(buf), _out);
_out = fmt::detail::copy<Char>(std::begin(buf) + offset, std::end(buf), _out);
}

private:
static OutputIt write_padding(OutputIt out, pad_type pad, int width) {
if (pad == pad_type::none) {
return out;
}
return detail::fill_n(out, width, pad == pad_type::space ? ' ' : '0');
return fmt::detail::fill_n(out, width, pad == pad_type::space ? ' ' : '0');
}

static OutputIt write_padding(OutputIt out, pad_type pad) {
Expand All @@ -234,17 +234,17 @@ struct date_writer {
}

void write1(int value) {
*_out++ = static_cast<char>('0' + detail::to_unsigned(value) % 10);
*_out++ = static_cast<char>('0' + fmt::detail::to_unsigned(value) % 10);
}
void write2(int value) {
const char* d = detail::digits2(detail::to_unsigned(value) % 100);
const char* d = fmt::detail::digits2(fmt::detail::to_unsigned(value) % 100);
*_out++ = *d++;
*_out++ = *d;
}
void write2(int value, pad_type pad) {
unsigned int v = detail::to_unsigned(value) % 100;
unsigned int v = fmt::detail::to_unsigned(value) % 100;
if (v >= 10) {
const char* d = detail::digits2(v);
const char* d = fmt::detail::digits2(v);
*_out++ = *d++;
*_out++ = *d;
} else {
Expand All @@ -261,8 +261,8 @@ struct date_writer {
year = 0 - year;
--width;
}
detail::uint32_or_64_or_128_t<long long> n = detail::to_unsigned(year);
const int num_digits = detail::count_digits(n);
fmt::detail::uint32_or_64_or_128_t<long long> n = fmt::detail::to_unsigned(year);
const int num_digits = fmt::detail::count_digits(n);
if (negative && pad == pad_type::zero) {
*_out++ = '-';
}
Expand All @@ -272,7 +272,7 @@ struct date_writer {
if (negative && pad != pad_type::zero) {
*_out++ = '-';
}
_out = detail::format_decimal<Char>(_out, n, num_digits);
_out = fmt::detail::format_decimal<Char>(_out, n, num_digits);
}
void write_year(long long year, pad_type pad) {
write_year_extended(year, pad);
Expand Down Expand Up @@ -308,7 +308,7 @@ struct date_writer {
digits |= 0x3030003030003030 | (usep << 16) | (usep << 40);

constexpr const size_t len = 8;
if (detail::const_check(detail::is_big_endian())) {
if (fmt::detail::const_check(fmt::detail::is_big_endian())) {
char tmp[len];
std::memcpy(tmp, &digits, len);
std::reverse_copy(tmp, tmp + len, buf);
Expand Down Expand Up @@ -364,5 +364,5 @@ fmt::format_context::iterator fmt::formatter<Date>::format(Date d, format_contex
basic_appender out = basic_appender<char>(buf);

parse_date_format(_fmt.begin(), _fmt.end(), date_writer { out, d });
return detail::write(ctx.out(), string_view { buf.data(), buf.size() }, specs);
return fmt::detail::write(ctx.out(), string_view { buf.data(), buf.size() }, specs);
}
18 changes: 18 additions & 0 deletions src/openvic-simulation/core/string/StringLiteral.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,22 @@ namespace OpenVic {
// Size of 1 to include null terminator
template<typename CharT = char, class Traits = std::char_traits<CharT>>
string_literal() -> string_literal<1, CharT, Traits>;

template<typename T>
struct is_string_literal : std::false_type {};

template<std::size_t N, typename CharT, typename CharTraits>
struct is_string_literal<string_literal<N, CharT, CharTraits>> : std::true_type {};

template<std::size_t N, typename CharT, typename CharTraits>
struct is_string_literal<const string_literal<N, CharT, CharTraits>> : std::true_type {};

template<std::size_t N, typename CharT, typename CharTraits>
struct is_string_literal<string_literal<N, CharT, CharTraits> const&> : std::true_type {};

template<typename T>
inline constexpr bool is_string_literal_v = is_string_literal<T>::value;

template<typename T>
concept string_literal_concept = is_string_literal_v<T>;
}
24 changes: 23 additions & 1 deletion src/openvic-simulation/core/template/Concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstddef>
#include <memory>
#include <string_view>
#include <type_traits>

#include <type_safe/strong_typedef.hpp>

Expand Down Expand Up @@ -231,4 +232,25 @@ namespace OpenVic {
concept strict_regular_invocable_r = std::regular_invocable<F, Args...> && requires(F f, Args&&... args) {
{ f(static_cast<Args>(args)...) } -> std::same_as<Return>;
};
}

namespace detail {
template<typename T, int = (T(), 0)>
constexpr bool enable_if_constexpr_constructible(int) {
return true;
}

template<typename>
constexpr bool enable_if_constexpr_constructible(long) {
return false;
}
}

template<typename T>
struct is_constexpr_constructible : std::bool_constant<detail::enable_if_constexpr_constructible<T>(0)> {};

template<typename T>
inline static constexpr bool is_constexpr_constructible_v = is_constexpr_constructible<T>::value;

template<typename T>
concept constexpr_constructible = is_constexpr_constructible_v<T>;
}
2 changes: 1 addition & 1 deletion src/openvic-simulation/dataloader/Vic2PathSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ static fs::path _search_for_game_path(fs::path hint_path) {
lexy_vdf::Parser parser;

memory::string buffer;
auto error_log_stream = detail::make_callback_stream<char>(
auto error_log_stream = ovdl::detail::make_callback_stream<char>(
[](void const* s, std::streamsize n, void* user_data) -> std::streamsize {
if (s != nullptr && n > 0 && user_data != nullptr) {
static_cast<memory::string*>(user_data)->append(static_cast<char const*>(s), n);
Expand Down
Loading
Loading