DART 6.13.2
Loading...
Searching...
No Matches
StlAllocator.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2022, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef DART_COMMON_STLALLOCATOR_HPP_
34#define DART_COMMON_STLALLOCATOR_HPP_
35
36#include <memory>
37
39
40namespace dart::common {
41
43template <typename T>
44class StlAllocator : public std::allocator<T>
45{
46public:
47 // Type aliases
48 using Base = std::allocator<T>;
49 using value_type = typename std::allocator_traits<Base>::value_type;
50 using size_type = typename std::allocator_traits<Base>::size_type;
51 using pointer = typename std::allocator_traits<Base>::pointer;
52 using const_pointer = typename std::allocator_traits<Base>::const_pointer;
53
54 template <typename U>
55 struct rebind
56 {
58 };
59
61 explicit StlAllocator(
62 MemoryAllocator& baseAllocator = MemoryAllocator::GetDefault()) noexcept;
63
65 StlAllocator(const StlAllocator& other) throw();
66
68 template <class U>
69 StlAllocator(const StlAllocator<U>& other) throw();
70
72 ~StlAllocator() = default;
73
81 [[nodiscard]] pointer allocate(size_type n, const void* hint = 0);
82
89 // TODO(JS): Make this constexpr once migrated to C++20
90
91 // TODO(JS): Add size_type max_size() const noexcept;
92
94 void print(std::ostream& os = std::cout, int indent = 0) const;
95
97 template <typename U>
98 friend std::ostream& operator<<(
99 std::ostream& os, const StlAllocator<U>& allocator);
100
101private:
102 template <typename U>
103 friend class StlAllocator;
105};
106
107} // namespace dart::common
108
109#include "dart/common/detail/StlAllocator-impl.hpp"
110
111#endif // DART_COMMON_STLALLOCATOR_HPP_
Base class for std::allocator compatible allocators.
Definition MemoryAllocator.hpp:46
static MemoryAllocator & GetDefault()
Returns the default memory allocator.
Definition MemoryAllocator.cpp:41
Wrapper class for MemoryAllocator to be compatible with std::allocator.
Definition StlAllocator.hpp:45
void print(std::ostream &os=std::cout, int indent=0) const
Prints state of the memory allocator.
Definition StlAllocator-impl.hpp:91
std::allocator< T > Base
Definition StlAllocator.hpp:48
friend class StlAllocator
Definition StlAllocator.hpp:103
typename std::allocator_traits< Base >::size_type size_type
Definition StlAllocator.hpp:50
typename std::allocator_traits< Base >::pointer pointer
Definition StlAllocator.hpp:51
void deallocate(pointer pointer, size_type n)
Deallocates the storage referenced by the pointer p, which must be a pointer obtained by an earlier c...
Definition StlAllocator-impl.hpp:84
typename std::allocator_traits< Base >::value_type value_type
Definition StlAllocator.hpp:49
MemoryAllocator & mBaseAllocator
Definition StlAllocator.hpp:104
pointer allocate(size_type n, const void *hint=0)
Allocates n * sizeof(T) bytes of uninitialized storage.
Definition StlAllocator-impl.hpp:65
typename std::allocator_traits< Base >::const_pointer const_pointer
Definition StlAllocator.hpp:52
Definition Aspect.cpp:42
Definition StlAllocator.hpp:56