CommonLibVR
GConstructorMov.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace RE
4 {
5  template <class T>
7  {
8  public:
9  static void Construct(void* a_ptr)
10  {
11  ::new (a_ptr) T{};
12  }
13 
14  static void Construct(void* a_ptr, const T& a_source)
15  {
16  ::new (a_ptr) T{ a_source };
17  }
18 
19  template <class S>
20  static void ConstructAlt(void* a_ptr, const S& a_source)
21  {
22  ::new (a_ptr) T{ a_source };
23  }
24 
25  static void ConstructArray(void* a_ptr, UPInt a_count)
26  {
27  T* ptr = static_cast<T*>(a_ptr);
28  for (UPInt i = 0; i < a_count; ++i) {
29  Construct(ptr++);
30  }
31  }
32 
33  static void ConstructArray(void* a_ptr, UPInt count, const T& source)
34  {
35  T* ptr = (T*)a_ptr;
36  for (UPInt i = 0; i < count; ++i) {
37  Construct(ptr++, source);
38  }
39  }
40 
41  static void ConstructArray(void* a_ptr, UPInt a_count, const T* a_source)
42  {
43  T* ptr = (T*)a_ptr;
44  for (UPInt i = 0; i < a_count; ++i) {
45  Construct(ptr++, *(a_source++));
46  }
47  }
48 
49  static void Destruct(T* a_ptr)
50  {
51  a_ptr->~T();
52  }
53 
54  static void DestructArray(T* a_ptr, UPInt a_count)
55  {
56  a_ptr += a_count - 1;
57  for (UPInt i = 0; i < a_count; ++i) {
58  (a_ptr--)->~T();
59  }
60  }
61 
62  static void CopyArrayForward(T* a_dst, const T* a_src, UPInt a_count)
63  {
64  std::memmove(a_dst, a_src, a_count * sizeof(T));
65  }
66 
67  static void CopyArrayBackward(T* a_dst, const T* a_src, UPInt a_count)
68  {
69  std::memmove(a_dst, a_src, a_count * sizeof(T));
70  }
71 
72  static bool IsMovable()
73  {
74  return true;
75  }
76 
77  private:
78  KEEP_FOR_RE()
79  };
80  static_assert(sizeof(GConstructorMov<void*>) == 0x1);
81 }
#define KEEP_FOR_RE()
Definition: PCH.h:713
Definition: GConstructorMov.h:7
static void ConstructArray(void *a_ptr, UPInt a_count)
Definition: GConstructorMov.h:25
static void ConstructAlt(void *a_ptr, const S &a_source)
Definition: GConstructorMov.h:20
static void Destruct(T *a_ptr)
Definition: GConstructorMov.h:49
static bool IsMovable()
Definition: GConstructorMov.h:72
static void Construct(void *a_ptr)
Definition: GConstructorMov.h:9
static void DestructArray(T *a_ptr, UPInt a_count)
Definition: GConstructorMov.h:54
static void CopyArrayForward(T *a_dst, const T *a_src, UPInt a_count)
Definition: GConstructorMov.h:62
static void Construct(void *a_ptr, const T &a_source)
Definition: GConstructorMov.h:14
static void CopyArrayBackward(T *a_dst, const T *a_src, UPInt a_count)
Definition: GConstructorMov.h:67
static void ConstructArray(void *a_ptr, UPInt count, const T &source)
Definition: GConstructorMov.h:33
static void ConstructArray(void *a_ptr, UPInt a_count, const T *a_source)
Definition: GConstructorMov.h:41
Definition: AbsorbEffect.h:6
std::size_t UPInt
Definition: SFTypes.h:5