| |
| |
| |
|
|
| #ifndef INCLUDE_CPPGC_CUSTOM_SPACE_H_ |
| #define INCLUDE_CPPGC_CUSTOM_SPACE_H_ |
|
|
| #include <stddef.h> |
|
|
| namespace cppgc { |
|
|
| |
| |
| |
| struct CustomSpaceIndex { |
| constexpr CustomSpaceIndex(size_t value) : value(value) {} |
| size_t value; |
| }; |
|
|
| |
| |
| |
| |
| class CustomSpaceBase { |
| public: |
| virtual ~CustomSpaceBase() = default; |
| virtual CustomSpaceIndex GetCustomSpaceIndex() const = 0; |
| virtual bool IsCompactable() const = 0; |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| template <typename ConcreteCustomSpace> |
| class CustomSpace : public CustomSpaceBase { |
| public: |
| |
| |
| |
| |
| static constexpr bool kSupportsCompaction = false; |
|
|
| CustomSpaceIndex GetCustomSpaceIndex() const final { |
| return ConcreteCustomSpace::kSpaceIndex; |
| } |
| bool IsCompactable() const final { |
| return ConcreteCustomSpace::kSupportsCompaction; |
| } |
| }; |
|
|
| |
| |
| |
| template <typename T, typename = void> |
| struct SpaceTrait { |
| using Space = void; |
| }; |
|
|
| namespace internal { |
|
|
| template <typename CustomSpace> |
| struct IsAllocatedOnCompactableSpaceImpl { |
| static constexpr bool value = CustomSpace::kSupportsCompaction; |
| }; |
|
|
| template <> |
| struct IsAllocatedOnCompactableSpaceImpl<void> { |
| |
| static constexpr bool value = false; |
| }; |
|
|
| template <typename T> |
| struct IsAllocatedOnCompactableSpace { |
| public: |
| static constexpr bool value = |
| IsAllocatedOnCompactableSpaceImpl<typename SpaceTrait<T>::Space>::value; |
| }; |
|
|
| } |
|
|
| } |
|
|
| #endif |
|
|