Squashed 'external/entt/entt/' content from commit fef92113

git-subtree-dir: external/entt/entt
git-subtree-split: fef921132cae7588213d0f9bcd2fb9c8ffd8b7fc
This commit is contained in:
2023-07-25 11:29:51 +02:00
commit 5c7231b7a3
242 changed files with 146004 additions and 0 deletions

View File

@ -0,0 +1,32 @@
#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;
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) {
return (this == &other);
}
};
} // namespace test
#endif

18
test/entt/common/config.h Normal file
View File

@ -0,0 +1,18 @@
#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_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_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,69 @@
#ifndef ENTT_COMMON_THROWING_ALLOCATOR_HPP
#define ENTT_COMMON_THROWING_ALLOCATOR_HPP
#include <cstddef>
#include <memory>
#include <type_traits>
namespace test {
template<typename Type>
class throwing_allocator: std::allocator<Type> {
template<typename Other>
friend class throwing_allocator;
using base = std::allocator<Type>;
struct test_exception {};
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 exception_type = test_exception;
template<class Other>
struct rebind {
using other = throwing_allocator<Other>;
};
throwing_allocator() = default;
template<class Other>
throwing_allocator(const throwing_allocator<Other> &other)
: base{other} {}
pointer allocate(std::size_t length) {
if(trigger_on_allocate) {
trigger_on_allocate = false;
throw test_exception{};
}
trigger_on_allocate = trigger_after_allocate;
trigger_after_allocate = false;
return base::allocate(length);
}
void deallocate(pointer mem, std::size_t length) {
base::deallocate(mem, length);
}
bool operator==(const throwing_allocator<Type> &) const {
return true;
}
bool operator!=(const throwing_allocator<Type> &other) const {
return !(*this == other);
}
static inline bool trigger_on_allocate{};
static inline bool trigger_after_allocate{};
};
} // namespace test
#endif

View File

@ -0,0 +1,46 @@
#ifndef ENTT_COMMON_THROWING_TYPE_HPP
#define ENTT_COMMON_THROWING_TYPE_HPP
namespace test {
class throwing_type {
struct test_exception {};
public:
using exception_type = test_exception;
static constexpr auto moved_from_value = -1;
throwing_type(int value)
: data{value} {}
throwing_type(const throwing_type &other)
: data{other.data} {
if(data == trigger_on_value) {
data = moved_from_value;
throw exception_type{};
}
}
throwing_type &operator=(const throwing_type &other) {
if(other.data == trigger_on_value) {
data = moved_from_value;
throw exception_type{};
}
data = other.data;
return *this;
}
operator int() const {
return data;
}
static inline int trigger_on_value{};
private:
int data{};
};
} // namespace test
#endif

View File

@ -0,0 +1,64 @@
#ifndef ENTT_COMMON_TRACKED_MEMORY_RESOURCE_HPP
#define ENTT_COMMON_TRACKED_MEMORY_RESOURCE_HPP
#ifdef ENTT_HAS_HEADER_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