v8  8.6.395 (node 15.0.1)
V8 is Google's open source JavaScript engine
custom-space.h
Go to the documentation of this file.
1 // Copyright 2020 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef INCLUDE_CPPGC_CUSTOM_SPACE_H_
6 #define INCLUDE_CPPGC_CUSTOM_SPACE_H_
7 
8 #include <stddef.h>
9 
10 namespace cppgc {
11 
13  CustomSpaceIndex(size_t value) : value(value) {} // NOLINT
14  size_t value;
15 };
16 
17 /**
18  * Top-level base class for custom spaces. Users must inherit from CustomSpace
19  * below.
20  */
22  public:
23  virtual ~CustomSpaceBase() = default;
25 };
26 
27 /**
28  * Base class custom spaces should directly inherit from. The class inheriting
29  * from CustomSpace must define kSpaceIndex as unique space index. These
30  * indices need for form a sequence starting at 0.
31  *
32  * Example:
33  * \code
34  * class CustomSpace1 : public CustomSpace<CustomSpace1> {
35  * public:
36  * static constexpr CustomSpaceIndex kSpaceIndex = 0;
37  * };
38  * class CustomSpace2 : public CustomSpace<CustomSpace2> {
39  * public:
40  * static constexpr CustomSpaceIndex kSpaceIndex = 1;
41  * };
42  * \endcode
43  */
44 template <typename ConcreteCustomSpace>
45 class CustomSpace : public CustomSpaceBase {
46  public:
48  return ConcreteCustomSpace::kSpaceIndex;
49  }
50 };
51 
52 /**
53  * User-overridable trait that allows pinning types to custom spaces.
54  */
55 template <typename T, typename = void>
56 struct SpaceTrait {
57  using Space = void;
58 };
59 
60 } // namespace cppgc
61 
62 #endif // INCLUDE_CPPGC_CUSTOM_SPACE_H_