aws-crt-cpp
C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++.
StlAllocator.h
Go to the documentation of this file.
1#pragma once
7#include <memory>
8
9#include <aws/common/common.h>
10#include <aws/crt/Exports.h>
11#include <type_traits>
12
13namespace Aws
14{
15 namespace Crt
16 {
17 using Allocator = aws_allocator;
19
20 template <typename T> class StlAllocator : public std::allocator<T>
21 {
22 public:
23 using Base = std::allocator<T>;
24
26
27 StlAllocator(Allocator *allocator) noexcept : Base() { m_allocator = allocator; }
28
29 StlAllocator(const StlAllocator<T> &a) noexcept : Base(a) { m_allocator = a.m_allocator; }
30
31 template <class U> StlAllocator(const StlAllocator<U> &a) noexcept : Base(a)
32 {
33 m_allocator = a.m_allocator;
34 }
35
37
38 using size_type = std::size_t;
39
40 template <typename U> struct rebind
41 {
43 };
44
45 using RawPointer = typename std::allocator_traits<std::allocator<T>>::pointer;
46
47 RawPointer allocate(size_type n, const void *hint = nullptr)
48 {
49 (void)hint;
50 AWS_ASSERT(m_allocator);
51 return static_cast<RawPointer>(aws_mem_acquire(m_allocator, n * sizeof(T)));
52 }
53
55 {
56 AWS_ASSERT(m_allocator);
57 aws_mem_release(m_allocator, p);
58 }
59
61 };
62 } // namespace Crt
63} // namespace Aws
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Definition: StlAllocator.h:21
void deallocate(RawPointer p, size_type)
Definition: StlAllocator.h:54
typename std::allocator_traits< std::allocator< T > >::pointer RawPointer
Definition: StlAllocator.h:45
RawPointer allocate(size_type n, const void *hint=nullptr)
Definition: StlAllocator.h:47
std::size_t size_type
Definition: StlAllocator.h:38
Allocator * m_allocator
Definition: StlAllocator.h:60
StlAllocator(Allocator *allocator) noexcept
Definition: StlAllocator.h:27
StlAllocator() noexcept
Definition: StlAllocator.h:25
StlAllocator(const StlAllocator< U > &a) noexcept
Definition: StlAllocator.h:31
~StlAllocator()
Definition: StlAllocator.h:36
std::allocator< T > Base
Definition: StlAllocator.h:23
StlAllocator(const StlAllocator< T > &a) noexcept
Definition: StlAllocator.h:29
aws_allocator Allocator
Definition: StlAllocator.h:17
AWS_CRT_CPP_API Allocator * g_allocator
Definition: Api.cpp:21
Definition: Api.h:17
cJSON * n
Definition: cJSON.cpp:2560
cJSON * a
Definition: cJSON.cpp:2562
cJSON * p
Definition: cJSON.cpp:2561
Definition: StlAllocator.h:41
StlAllocator< U > other
Definition: StlAllocator.h:42