Welcome to mirror list, hosted at ThFree Co, Russian Federation.

custom-space.h « cppgc « include « v8 « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2597a5bdef7a415ecfb2e599be87f05415ab4533 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef INCLUDE_CPPGC_CUSTOM_SPACE_H_
#define INCLUDE_CPPGC_CUSTOM_SPACE_H_

#include <stddef.h>

namespace cppgc {

struct CustomSpaceIndex {
  CustomSpaceIndex(size_t value) : value(value) {}  // NOLINT
  size_t value;
};

/**
 * Top-level base class for custom spaces. Users must inherit from CustomSpace
 * below.
 */
class CustomSpaceBase {
 public:
  virtual ~CustomSpaceBase() = default;
  virtual CustomSpaceIndex GetCustomSpaceIndex() const = 0;
};

/**
 * Base class custom spaces should directly inherit from. The class inheriting
 * from CustomSpace must define kSpaceIndex as unique space index. These
 * indices need for form a sequence starting at 0.
 *
 * Example:
 * \code
 * class CustomSpace1 : public CustomSpace<CustomSpace1> {
 *  public:
 *   static constexpr CustomSpaceIndex kSpaceIndex = 0;
 * };
 * class CustomSpace2 : public CustomSpace<CustomSpace2> {
 *  public:
 *   static constexpr CustomSpaceIndex kSpaceIndex = 1;
 * };
 * \endcode
 */
template <typename ConcreteCustomSpace>
class CustomSpace : public CustomSpaceBase {
 public:
  CustomSpaceIndex GetCustomSpaceIndex() const final {
    return ConcreteCustomSpace::kSpaceIndex;
  }
};

/**
 * User-overridable trait that allows pinning types to custom spaces.
 */
template <typename T, typename = void>
struct SpaceTrait {
  using Space = void;
};

}  // namespace cppgc

#endif  // INCLUDE_CPPGC_CUSTOM_SPACE_H_