Initial commit - restart from existing code

This commit is contained in:
Tom Ray
2026-02-13 19:15:05 +01:00
parent 11df621bb2
commit 7c352bc280
1906 changed files with 491226 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
load("@entt//bazel:copts.bzl", "COPTS")
load("@rules_cc//cc:defs.bzl", "cc_library")
package(default_visibility = ["//:__subpackages__"])
cc_library(
name = "common",
copts = COPTS,
hdrs = glob(["*.h", "*.hpp"]),
)

View File

@@ -0,0 +1,25 @@
#ifndef ENTT_COMMON_AGGREGATE_H
#define ENTT_COMMON_AGGREGATE_H
#include <type_traits>
namespace test {
struct aggregate {
int value{};
};
[[nodiscard]] inline bool operator==(const aggregate &lhs, const aggregate &rhs) {
return lhs.value == rhs.value;
}
[[nodiscard]] inline bool operator<(const aggregate &lhs, const aggregate &rhs) {
return lhs.value < rhs.value;
}
// ensure aggregate-ness :)
static_assert(std::is_aggregate_v<test::aggregate>, "Not an aggregate type");
} // namespace test
#endif

View File

@@ -0,0 +1,37 @@
#ifndef ENTT_COMMON_BASIC_TEST_ALLOCATOR_HPP
#define ENTT_COMMON_BASIC_TEST_ALLOCATOR_HPP
#include <memory>
#include <type_traits>
namespace test {
template<typename Type, typename Pocs = std::true_type>
struct basic_test_allocator: std::allocator<Type> {
// basic pocca/pocma/pocs allocator
using base = std::allocator<Type>;
using propagate_on_container_copy_assignment = std::true_type;
using propagate_on_container_swap = Pocs;
using std::allocator<Type>::allocator;
// necessary to avoid a warning by clang-cl :)
basic_test_allocator(const basic_test_allocator &other)
: base{other} {
}
basic_test_allocator &operator=(const basic_test_allocator &other) {
// necessary to avoid call suppression
base::operator=(other);
return *this;
}
bool operator==(const basic_test_allocator &other) const {
return (this == &other);
}
};
} // namespace test
#endif

View File

@@ -0,0 +1,28 @@
#ifndef ENTT_COMMON_BITMASK_H
#define ENTT_COMMON_BITMASK_H
#include <entt/core/enum.hpp>
namespace test {
enum class enum_is_bitmask {
foo = 0x01,
bar = 0x02,
quux = 0x04,
_entt_enum_as_bitmask
};
// small type on purpose
enum class enum_as_bitmask : std::uint8_t {
foo = 0x01,
bar = 0x02,
quux = 0x04
};
} // namespace test
template<>
struct entt::enum_as_bitmask<test::enum_as_bitmask>
: std::true_type {};
#endif

View File

@@ -0,0 +1,25 @@
#ifndef ENTT_COMMON_BOXED_TYPE_H
#define ENTT_COMMON_BOXED_TYPE_H
namespace test {
template<typename Type>
struct boxed_type {
Type value{};
operator Type() const noexcept {
return value;
}
};
template<typename Type>
inline bool operator==(const boxed_type<Type> &lhs, const boxed_type<Type> &rhs) {
return lhs.value == rhs.value;
}
using boxed_int = boxed_type<int>;
using boxed_char = boxed_type<char>;
} // namespace test
#endif

View File

@@ -0,0 +1,20 @@
#ifndef ENTT_COMMON_CONFIG_H
#define ENTT_COMMON_CONFIG_H
namespace test {
#ifdef NDEBUG
# define ENTT_DEBUG_TEST(Case, Test) TEST(Case, DISABLED_##Test)
# define ENTT_DEBUG_TEST_P(Case, Test) TEST_P(Case, DISABLED_##Test)
# define ENTT_DEBUG_TEST_F(Case, Test) TEST_F(Case, DISABLED_##Test)
# define ENTT_DEBUG_TYPED_TEST(Case, Test) TYPED_TEST(Case, DISABLED_##Test)
#else
# define ENTT_DEBUG_TEST(Case, Test) TEST(Case, Test)
# define ENTT_DEBUG_TEST_P(Case, Test) TEST_P(Case, Test)
# define ENTT_DEBUG_TEST_F(Case, Test) TEST_F(Case, Test)
# define ENTT_DEBUG_TYPED_TEST(Case, Test) TYPED_TEST(Case, Test)
#endif
} // namespace test
#endif

View File

@@ -0,0 +1,14 @@
#ifndef ENTT_COMMON_EMITTER_H
#define ENTT_COMMON_EMITTER_H
#include <entt/signal/emitter.hpp>
namespace test {
struct emitter: entt::emitter<emitter> {
using entt::emitter<emitter>::emitter;
};
} // namespace test
#endif

View File

@@ -0,0 +1,11 @@
#ifndef ENTT_COMMON_EMPTY_H
#define ENTT_COMMON_EMPTY_H
namespace test {
struct empty {};
struct other_empty {};
} // namespace test
#endif

View File

@@ -0,0 +1,13 @@
#ifndef ENTT_COMMON_ENTITY_H
#define ENTT_COMMON_ENTITY_H
#include <cstdint>
namespace test {
enum entity : std::uint32_t {};
enum other_entity : std::uint32_t {};
} // namespace test
#endif

View File

@@ -0,0 +1,11 @@
#ifndef ENTT_COMMON_LINTER_HPP
#define ENTT_COMMON_LINTER_HPP
namespace test {
template<typename Type>
void is_initialized(Type &) {}
} // namespace test
#endif

View File

@@ -0,0 +1,17 @@
#ifndef ENTT_COMMON_LISTENER_H
#define ENTT_COMMON_LISTENER_H
namespace test {
template<typename Type>
struct listener {
void on(Type elem) {
value = elem;
}
int value{};
};
} // namespace test
#endif

View File

@@ -0,0 +1,18 @@
#ifndef ENTT_COMMON_META_TRAITS_H
#define ENTT_COMMON_META_TRAITS_H
#include <entt/core/enum.hpp>
namespace test {
enum class meta_traits {
none = 0x0000,
one = 0x0001,
two = 0x0002,
three = 0x0100,
_entt_enum_as_bitmask
};
} // namespace test
#endif

View File

@@ -0,0 +1,36 @@
#ifndef ENTT_COMMON_MIXIN_HPP
#define ENTT_COMMON_MIXIN_HPP
#include <entt/core/any.hpp>
#include <entt/entity/fwd.hpp>
namespace test {
struct assure_loop {};
template<typename Type>
class assure_loop_mixin: public Type {
using underlying_type = Type;
using registry_type = entt::basic_registry<typename underlying_type::entity_type, typename underlying_type::base_type::allocator_type>;
void bind_any(entt::any value) noexcept override {
if(auto *owner = entt::any_cast<registry_type>(&value); owner) {
owner->template storage<int>();
}
}
public:
using allocator_type = typename underlying_type::allocator_type;
using entity_type = typename underlying_type::entity_type;
using Type::Type;
};
} // namespace test
template<typename Entity>
struct entt::storage_type<test::assure_loop, Entity> {
using type = test::assure_loop_mixin<entt::basic_storage<test::assure_loop, Entity>>;
};
#endif

View File

@@ -0,0 +1,22 @@
#ifndef ENTT_COMMON_NEW_DELETE_H
#define ENTT_COMMON_NEW_DELETE_H
#include <cstddef>
namespace test {
struct new_delete {
static void *operator new(std::size_t count) {
return ::operator new(count);
}
static void operator delete(void *ptr) {
::operator delete(ptr);
}
int value{};
};
} // namespace test
#endif

View File

@@ -0,0 +1,12 @@
#ifndef ENTT_COMMON_NON_COMPARABLE_H
#define ENTT_COMMON_NON_COMPARABLE_H
namespace test {
struct non_comparable {
bool operator==(const non_comparable &) const = delete;
};
} // namespace test
#endif

View File

@@ -0,0 +1,17 @@
#ifndef ENTT_COMMON_NON_DEFAULT_CONSTRUCTIBLE_H
#define ENTT_COMMON_NON_DEFAULT_CONSTRUCTIBLE_H
namespace test {
struct non_default_constructible {
non_default_constructible() = delete;
non_default_constructible(int v)
: value{v} {}
int value;
};
} // namespace test
#endif

View File

@@ -0,0 +1,20 @@
#ifndef ENTT_COMMON_NON_MOVABLE_H
#define ENTT_COMMON_NON_MOVABLE_H
namespace test {
struct non_movable {
non_movable() = default;
non_movable(const non_movable &) = default;
non_movable(non_movable &&) = delete;
non_movable &operator=(const non_movable &) = default;
non_movable &operator=(non_movable &&) = delete;
int value{};
};
} // namespace test
#endif

View File

@@ -0,0 +1,21 @@
#ifndef ENTT_COMMON_POINTER_STABLE_H
#define ENTT_COMMON_POINTER_STABLE_H
namespace test {
struct pointer_stable {
static constexpr auto in_place_delete = true;
int value{};
};
[[nodiscard]] inline bool operator==(const pointer_stable &lhs, const pointer_stable &rhs) {
return lhs.value == rhs.value;
}
[[nodiscard]] inline bool operator<(const pointer_stable &lhs, const pointer_stable &rhs) {
return lhs.value < rhs.value;
}
} // namespace test
#endif

View File

@@ -0,0 +1,32 @@
#ifndef ENTT_COMMON_REGISTRY_H
#define ENTT_COMMON_REGISTRY_H
#include <entt/entity/registry.hpp>
namespace test {
template<typename Entity>
struct custom_registry: private entt::basic_registry<Entity> {
using base_type = entt::basic_registry<Entity>;
template<typename, typename>
friend class entt::basic_sigh_mixin;
template<typename, typename>
friend class entt::basic_reactive_mixin;
public:
using allocator_type = typename base_type::allocator_type;
using entity_type = typename base_type::entity_type;
using base_type::base_type;
using base_type::storage;
using base_type::create;
using base_type::emplace;
using base_type::insert;
};
} // namespace test
#endif

View File

@@ -0,0 +1,92 @@
#ifndef ENTT_COMMON_THROWING_ALLOCATOR_HPP
#define ENTT_COMMON_THROWING_ALLOCATOR_HPP
#include <cstddef>
#include <limits>
#include <memory>
#include <type_traits>
#include <entt/container/dense_map.hpp>
#include <entt/core/fwd.hpp>
#include <entt/core/type_info.hpp>
namespace test {
struct throwing_allocator_exception {};
template<typename Type>
class throwing_allocator {
template<typename Other>
friend class throwing_allocator;
template<typename Other, typename = std::enable_if_t<!std::is_void_v<Type> || std::is_constructible_v<std::allocator<Type>, std::allocator<Other>>>>
throwing_allocator(int, const throwing_allocator<Other> &other)
: allocator{other.allocator},
config{other.config} {}
template<typename Other, typename = std::enable_if_t<std::is_void_v<Type> && !std::is_constructible_v<std::allocator<Type>, std::allocator<Other>>>>
throwing_allocator(char, const throwing_allocator<Other> &other)
: allocator{},
config{other.config} {}
public:
using value_type = Type;
using pointer = value_type *;
using const_pointer = const value_type *;
using void_pointer = void *;
using const_void_pointer = const void *;
using propagate_on_container_move_assignment = std::true_type;
using propagate_on_container_swap = std::true_type;
using container_type = entt::dense_map<entt::id_type, std::size_t>;
template<typename Other>
struct rebind {
using other = throwing_allocator<Other>;
};
throwing_allocator()
: allocator{},
config{std::allocate_shared<container_type>(allocator)} {}
template<typename Other>
throwing_allocator(const throwing_allocator<Other> &other)
// std::allocator<void> has no cross constructors (waiting for C++20)
: throwing_allocator{0, other} {}
pointer allocate(std::size_t length) {
if(const auto hash = entt::type_id<Type>().hash(); config->contains(hash)) {
if(auto &elem = (*config)[hash]; elem == 0u) {
config->erase(hash);
throw throwing_allocator_exception{};
} else {
--elem;
}
}
return allocator.allocate(length);
}
void deallocate(pointer mem, std::size_t length) {
allocator.deallocate(mem, length);
}
template<typename Other>
void throw_counter(const std::size_t len) {
(*config)[entt::type_id<Other>().hash()] = len;
}
bool operator==(const throwing_allocator<Type> &) const {
return true;
}
bool operator!=(const throwing_allocator<Type> &other) const {
return !(*this == other);
}
private:
std::allocator<Type> allocator;
std::shared_ptr<container_type> config;
};
} // namespace test
#endif

View File

@@ -0,0 +1,42 @@
#ifndef ENTT_COMMON_THROWING_TYPE_HPP
#define ENTT_COMMON_THROWING_TYPE_HPP
namespace test {
struct throwing_type_exception {};
struct throwing_type {
throwing_type(bool mode)
: trigger{mode} {}
throwing_type(const throwing_type &other)
: trigger{other.trigger} {
if(trigger) {
throw throwing_type_exception{};
}
}
throwing_type &operator=(const throwing_type &other) {
trigger = other.trigger;
return *this;
}
void throw_on_copy(const bool mode) noexcept {
trigger = mode;
}
bool throw_on_copy() const noexcept {
return trigger;
}
private:
bool trigger{};
};
inline bool operator==(const throwing_type &lhs, const throwing_type &rhs) {
return lhs.throw_on_copy() == rhs.throw_on_copy();
}
} // namespace test
#endif

View File

@@ -0,0 +1,64 @@
#ifndef ENTT_COMMON_TRACKED_MEMORY_RESOURCE_HPP
#define ENTT_COMMON_TRACKED_MEMORY_RESOURCE_HPP
#if __has_include(<version>)
# include <version>
#
# if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L
# define ENTT_HAS_TRACKED_MEMORY_RESOURCE
#
# include <cstddef>
# include <memory_resource>
# include <string>
namespace test {
class tracked_memory_resource: public std::pmr::memory_resource {
void *do_allocate(std::size_t bytes, std::size_t alignment) override {
++alloc_counter;
return std::pmr::get_default_resource()->allocate(bytes, alignment);
}
void do_deallocate(void *value, std::size_t bytes, std::size_t alignment) override {
++dealloc_counter;
std::pmr::get_default_resource()->deallocate(value, bytes, alignment);
}
bool do_is_equal(const std::pmr::memory_resource &other) const noexcept override {
return (this == &other);
}
public:
using string_type = std::pmr::string;
using size_type = std::size_t;
static constexpr const char *default_value = "a string long enough to force an allocation (hopefully)";
tracked_memory_resource()
: alloc_counter{},
dealloc_counter{} {}
size_type do_allocate_counter() const noexcept {
return alloc_counter;
}
size_type do_deallocate_counter() const noexcept {
return dealloc_counter;
}
void reset() noexcept {
alloc_counter = 0u;
dealloc_counter = 0u;
}
private:
size_type alloc_counter;
size_type dealloc_counter;
};
} // namespace test
# endif
#endif
#endif

View File

@@ -0,0 +1,20 @@
#ifndef ENTT_COMMON_TRANSPARENT_EQUAL_TO_H
#define ENTT_COMMON_TRANSPARENT_EQUAL_TO_H
#include <type_traits>
namespace test {
struct transparent_equal_to {
using is_transparent = void;
template<typename Type, typename Other>
constexpr std::enable_if_t<std::is_convertible_v<Other, Type>, bool>
operator()(const Type &lhs, const Other &rhs) const {
return lhs == static_cast<Type>(rhs);
}
};
} // namespace test
#endif