Debian Codegraph @

thirdparty/jolt_physics/Jolt/Core/STLAlignedAllocator.h

raw symbols SCIP
1 // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2 // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3 // SPDX-License-Identifier: MIT
4
5 #pragma once
6
7 JPH_NAMESPACE_BEGIN
8
9 /// STL allocator that takes care that memory is aligned to N bytes
10 template <typename T, size_t N>
11 class STLAlignedAllocator
12 {
13 public:
14 using value_type = T;
15
16 /// Pointer to type
17 using pointer = T *;
18 using const_pointer = const T *;
19
20 /// Reference to type.
21 /// Can be removed in C++20.
22 using reference = T &;
23 using const_reference = const T &;
24
25 using size_type = size_t;
26 using difference_type = ptrdiff_t;
27
28 /// The allocator is stateless
29 using is_always_equal = std::true_type;
30
31 /// Allocator supports moving
32 using propagate_on_container_move_assignment = std::true_type;
33
34 /// Constructor
35 inline STLAlignedAllocator() = default;
36
37 /// Constructor from other allocator
38 template <typename T2>
39 inline explicit STLAlignedAllocator(const STLAlignedAllocator<T2, N> &) { }
40
41 /// Allocate memory
42 inline pointer allocate(size_type inN)
43 {
44 return (pointer)AlignedAllocate(inN * sizeof(value_type), N);
45 }
46
47 /// Free memory
48 inline void deallocate(pointer inPointer, size_type)
49 {
50 AlignedFree(inPointer);
51 }
52
53 /// Allocators are stateless so assumed to be equal
54 inline bool operator == (const STLAlignedAllocator<T, N> &) const
55 {
56 return true;
57 }
58
59 inline bool operator != (const STLAlignedAllocator<T, N> &) const
60 {
61 return false;
62 }
63
64 /// Converting to allocator for other type
65 template <typename T2>
66 struct rebind
67 {
68 using other = STLAlignedAllocator<T2, N>;
69 };
70 };
71
72 JPH_NAMESPACE_END