CommonLibSSE (Parapets fork)
RegistrationTraits.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "RE/N/NiSmartPointer.h"
4 #include "RE/T/TESForm.h"
5 #include "RE/T/TESObjectREFR.h"
6 
7 namespace SKSE
8 {
9  namespace Impl
10  {
11  template <class T>
12  using is_object_pointer = std::is_convertible<std::decay_t<T>, RE::TESObjectREFR*>;
13 
14  template <class T>
16 
17  template <class T>
18  using is_not_object_pointer = std::negation<is_object_pointer<T>>;
19 
20  template <class T>
22 
23  template <class T>
24  using is_form_pointer = std::is_convertible<std::decay_t<T>, RE::TESForm*>;
25 
26  template <class T>
28 
29  template <class T>
30  using is_not_form_pointer = std::negation<is_form_pointer<T>>;
31 
32  template <class T>
34 
35  template <class T>
37  std::make_index_sequence<
38  std::tuple_size_v<
39  std::decay_t<T>>>
40  {};
41 
42  // default
43  template <class T, class = void>
44  class VMArg
45  {
46  public:
47  using value_type = std::decay_t<T>;
48 
49  VMArg() :
50  _arg{}
51  {}
52 
53  template <class U, std::enable_if_t<std::is_same_v<std::decay_t<U>, value_type>, int> = 0>
54  VMArg(U&& a_arg) :
55  _arg{ std::forward<U>(a_arg) }
56  {}
57 
58  ~VMArg() = default;
59 
60  template <class U, std::enable_if_t<std::is_same_v<std::decay_t<U>, value_type>, int> = 0>
61  void Pack(U&& a_arg)
62  {
63  _arg = std::forward<U>(a_arg);
64  }
65 
67  {
68  return value_type{ std::move(_arg) };
69  }
70 
71  private:
72  T _arg;
73  };
74 
75  // forms
76  template <class T>
77  class VMArg<
78  T,
79  std::enable_if_t<
80  std::conjunction_v<
81  is_form_pointer<T>,
82  is_not_object_pointer<T>>>>
83  {
84  public:
85  using value_type = std::decay_t<T>;
86 
87  VMArg() :
88  _formID(static_cast<RE::FormID>(0))
89  {}
90 
91  template <class U, std::enable_if_t<std::is_same_v<std::decay_t<U>, value_type>, int> = 0>
92  VMArg(U&& a_arg) :
93  VMArg()
94  {
95  Pack(std::forward<U>(a_arg));
96  }
97 
98  ~VMArg() = default;
99 
100  template <class U, std::enable_if_t<std::is_same_v<std::decay_t<U>, value_type>, int> = 0>
101  void Pack(U&& a_arg)
102  {
103  if (a_arg) {
104  _formID = a_arg->GetFormID();
105  }
106  }
107 
109  {
110  return static_cast<value_type>(RE::TESForm::LookupByID(_formID));
111  }
112 
113  private:
114  RE::FormID _formID;
115  };
116 
117  // objects
118  template <class T>
119  class VMArg<
120  T,
121  std::enable_if_t<
122  is_object_pointer_v<T>>>
123  {
124  public:
125  using value_type = std::decay_t<T>;
126 
127  VMArg() :
128  _object(nullptr)
129  {}
130 
131  template <class U, std::enable_if_t<std::is_same_v<std::decay_t<U>, value_type>, int> = 0>
132  VMArg(U&& a_arg) :
133  VMArg()
134  {
135  Pack(std::forward<U>(a_arg));
136  }
137 
138  ~VMArg() = default;
139 
140  template <class U, std::enable_if_t<std::is_same_v<std::decay_t<U>, value_type>, int> = 0>
141  void Pack(U&& a_arg)
142  {
143  _object.reset(a_arg);
144  }
145 
147  {
148  return _object.get();
149  }
150 
151  private:
153  };
154 
155  template <class T>
156  VMArg(T&&) -> VMArg<T>;
157  }
158 }
Definition: NiSmartPointer.h:9
Definition: TESForm.h:34
static TESForm * LookupByID(FormID a_formID)
Definition: TESObjectREFR.h:105
value_type Unpack()
Definition: RegistrationTraits.h:146
VMArg(U &&a_arg)
Definition: RegistrationTraits.h:132
std::decay_t< T > value_type
Definition: RegistrationTraits.h:125
void Pack(U &&a_arg)
Definition: RegistrationTraits.h:141
Definition: RegistrationTraits.h:45
VMArg()
Definition: RegistrationTraits.h:49
std::decay_t< T > value_type
Definition: RegistrationTraits.h:47
void Pack(U &&a_arg)
Definition: RegistrationTraits.h:61
VMArg(U &&a_arg)
Definition: RegistrationTraits.h:54
value_type Unpack()
Definition: RegistrationTraits.h:66
Definition: AbsorbEffect.h:6
std::uint32_t FormID
Definition: BSCoreTypes.h:5
std::is_convertible< std::decay_t< T >, RE::TESObjectREFR * > is_object_pointer
Definition: RegistrationTraits.h:12
std::negation< is_object_pointer< T > > is_not_object_pointer
Definition: RegistrationTraits.h:18
constexpr bool is_not_form_pointer_v
Definition: RegistrationTraits.h:33
std::is_convertible< std::decay_t< T >, RE::TESForm * > is_form_pointer
Definition: RegistrationTraits.h:24
VMArg(T &&) -> VMArg< T >
constexpr bool is_form_pointer_v
Definition: RegistrationTraits.h:27
std::negation< is_form_pointer< T > > is_not_form_pointer
Definition: RegistrationTraits.h:30
constexpr bool is_not_object_pointer_v
Definition: RegistrationTraits.h:21
constexpr bool is_object_pointer_v
Definition: RegistrationTraits.h:15
Definition: API.h:14
Definition: NiBinaryStream.h:94
Definition: RegistrationTraits.h:40