Skip to content
Closed
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
10 changes: 7 additions & 3 deletions src/openvic-simulation/population/PopIdInProvince.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
#include <fmt/base.h>
#include <fmt/format.h>

#include <type_safe/narrow_cast.hpp>
#include <type_safe/strong_typedef.hpp>

namespace OpenVic {
struct pop_id_in_province_t : type_safe::strong_typedef<pop_id_in_province_t, std::size_t>,
struct pop_id_in_province_t : type_safe::strong_typedef<pop_id_in_province_t, std::uint16_t>,
type_safe::strong_typedef_op::equality_comparison<pop_id_in_province_t>,
type_safe::strong_typedef_op::relational_comparison<pop_id_in_province_t>,
type_safe::strong_typedef_op::integer_arithmetic<pop_id_in_province_t> {
using strong_typedef::strong_typedef;

constexpr pop_id_in_province_t(const std::size_t i)
: pop_id_in_province_t(type_safe::narrow_cast<std::uint16_t>(i)) {} \

constexpr bool is_null() const { return type_safe::get(*this) == 0; }
constexpr bool operator!() const { return is_null(); }
};
Expand All @@ -23,8 +27,8 @@ namespace std {
struct hash<OpenVic::pop_id_in_province_t> : type_safe::hashable<OpenVic::pop_id_in_province_t> {};
}
template<>
struct fmt::formatter<OpenVic::pop_id_in_province_t> : fmt::formatter<std::size_t> {
struct fmt::formatter<OpenVic::pop_id_in_province_t> : fmt::formatter<std::uint16_t> {
fmt::format_context::iterator format(OpenVic::pop_id_in_province_t const& value, fmt::format_context& ctx) const {
return fmt::formatter<std::size_t>::format(type_safe::get(value), ctx);
return fmt::formatter<std::uint16_t>::format(type_safe::get(value), ctx);
}
};
4 changes: 3 additions & 1 deletion src/openvic-simulation/types/TypedIndices.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <fmt/base.h>
#include <fmt/format.h>

#include <type_safe/narrow_cast.hpp>
#include <type_safe/strong_typedef.hpp>

#define TYPED_INDEX_CUSTOM(name, base_type) \
Expand All @@ -15,6 +16,7 @@
type_safe::strong_typedef_op::relational_comparison<name>, \
type_safe::strong_typedef_op::integer_arithmetic<name> { \
using strong_typedef::strong_typedef; \
constexpr name(const std::size_t i) : name(type_safe::narrow_cast<base_type>(i)) {} \
}; \
} \
namespace std { \
Expand All @@ -27,7 +29,7 @@
return fmt::formatter<base_type>::format(type_safe::get(value), ctx); \
} \
};
#define TYPED_INDEX(name) TYPED_INDEX_CUSTOM(name, std::size_t)
#define TYPED_INDEX(name) TYPED_INDEX_CUSTOM(name, std::uint16_t)

TYPED_INDEX(bookmark_index_t)
TYPED_INDEX(building_type_index_t)
Expand Down
Loading