File indexing completed on 2025-02-22 10:42:25
0001
0002
0003
0004
0005 #ifndef INCLUDE_CPPGC_CUSTOM_SPACE_H_
0006 #define INCLUDE_CPPGC_CUSTOM_SPACE_H_
0007
0008 #include <stddef.h>
0009
0010 namespace cppgc {
0011
0012
0013
0014
0015 struct CustomSpaceIndex {
0016 constexpr CustomSpaceIndex(size_t value) : value(value) {}
0017 size_t value;
0018 };
0019
0020
0021
0022
0023
0024 class CustomSpaceBase {
0025 public:
0026 virtual ~CustomSpaceBase() = default;
0027 virtual CustomSpaceIndex GetCustomSpaceIndex() const = 0;
0028 virtual bool IsCompactable() const = 0;
0029 };
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 template <typename ConcreteCustomSpace>
0049 class CustomSpace : public CustomSpaceBase {
0050 public:
0051
0052
0053
0054
0055 static constexpr bool kSupportsCompaction = false;
0056
0057 CustomSpaceIndex GetCustomSpaceIndex() const final {
0058 return ConcreteCustomSpace::kSpaceIndex;
0059 }
0060 bool IsCompactable() const final {
0061 return ConcreteCustomSpace::kSupportsCompaction;
0062 }
0063 };
0064
0065
0066
0067
0068 template <typename T, typename = void>
0069 struct SpaceTrait {
0070 using Space = void;
0071 };
0072
0073 namespace internal {
0074
0075 template <typename CustomSpace>
0076 struct IsAllocatedOnCompactableSpaceImpl {
0077 static constexpr bool value = CustomSpace::kSupportsCompaction;
0078 };
0079
0080 template <>
0081 struct IsAllocatedOnCompactableSpaceImpl<void> {
0082
0083 static constexpr bool value = false;
0084 };
0085
0086 template <typename T>
0087 struct IsAllocatedOnCompactableSpace {
0088 public:
0089 static constexpr bool value =
0090 IsAllocatedOnCompactableSpaceImpl<typename SpaceTrait<T>::Space>::value;
0091 };
0092
0093 }
0094
0095 }
0096
0097 #endif