RavEngine
Loading...
Searching...
No Matches
std_allocator.h
1//----------------------------------------------------------------------------//
2// //
3// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
4// and distributed under the MIT License (MIT). //
5// //
6// Copyright (c) Guillaume Blanc //
7// //
8// Permission is hereby granted, free of charge, to any person obtaining a //
9// copy of this software and associated documentation files (the "Software"), //
10// to deal in the Software without restriction, including without limitation //
11// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
12// and/or sell copies of the Software, and to permit persons to whom the //
13// Software is furnished to do so, subject to the following conditions: //
14// //
15// The above copyright notice and this permission notice shall be included in //
16// all copies or substantial portions of the Software. //
17// //
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
21// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
24// DEALINGS IN THE SOFTWARE. //
25// //
26//----------------------------------------------------------------------------//
27
28#ifndef OZZ_OZZ_BASE_CONTAINERS_STD_ALLOCATOR_H_
29#define OZZ_OZZ_BASE_CONTAINERS_STD_ALLOCATOR_H_
30
31#include <new>
32
33#include "ozz/base/memory/allocator.h"
34
35namespace ozz {
36// Define a STL allocator compliant allocator->
37template <typename _Ty>
39 public:
40 typedef _Ty value_type; // Element type.
41 typedef value_type* pointer; // Pointer to element.
42 typedef value_type& reference; // Reference to element.
43 typedef const value_type* const_pointer; // Constant pointer to element.
44 typedef const value_type& const_reference; // Constant reference to element.
45 typedef size_t size_type; // Quantities of elements.
46 typedef ptrdiff_t difference_type; // Difference between two pointers.
47
48 StdAllocator() noexcept {}
49 StdAllocator(const StdAllocator&) noexcept {}
50
51 template <class _Other>
52 StdAllocator(const StdAllocator<_Other>&) noexcept {}
53
54 template <class _Other>
55 struct rebind {
57 };
58
59 pointer address(reference _ref) const noexcept { return &_ref; }
60 const_pointer address(const_reference _ref) const noexcept { return &_ref; }
61
62 template <class _Other, class... _Args>
63 void construct(_Other* _ptr, _Args&&... _args) {
64 ::new (static_cast<void*>(_ptr)) _Other(std::forward<_Args>(_args)...);
65 }
66
67 template <class _Other>
68 void destroy(_Other* _ptr) {
69 (void)_ptr;
70 _ptr->~_Other();
71 }
72
73 // Allocates array of _Count elements.
74 pointer allocate(size_t _count) noexcept {
75 // Makes sure to a use c like allocator, to avoid duplicated constructor
76 // calls.
77 return reinterpret_cast<pointer>(memory::default_allocator()->Allocate(
78 sizeof(value_type) * _count, alignof(value_type)));
79 }
80
81 // Deallocates object at _Ptr, ignores size.
82 void deallocate(pointer _ptr, size_type) noexcept {
83 memory::default_allocator()->Deallocate(_ptr);
84 }
85
86 size_type max_size() const noexcept {
87 return (~size_type(0)) / sizeof(value_type);
88 }
89};
90
91// Tests for allocator equality (always true).
92template <class _Ty, class _Other>
93inline bool operator==(const StdAllocator<_Ty>&,
94 const StdAllocator<_Other>&) noexcept {
95 return true;
96}
97
98// Tests for allocator inequality (always false).
99template <class _Ty, class _Other>
100inline bool operator!=(const StdAllocator<_Ty>&,
101 const StdAllocator<_Other>&) noexcept {
102 return false;
103}
104} // namespace ozz
105#endif // OZZ_OZZ_BASE_CONTAINERS_STD_ALLOCATOR_H_
Definition std_allocator.h:38
Definition std_allocator.h:55