]>
git.proxmox.com Git - ceph.git/blob - ceph/src/fmt/test/mock-allocator.h
1 // Formatting library for C++ - mock allocator
3 // Copyright (c) 2012 - present, Victor Zverovich
4 // All rights reserved.
6 // For the license information refer to format.h.
8 #ifndef FMT_MOCK_ALLOCATOR_H_
9 #define FMT_MOCK_ALLOCATOR_H_
11 #include "fmt/format.h"
14 template <typename T
> class mock_allocator
{
17 mock_allocator(const mock_allocator
&) {}
19 MOCK_METHOD1_T(allocate
, T
*(std::size_t n
));
20 MOCK_METHOD2_T(deallocate
, void(T
* p
, std::size_t n
));
23 template <typename Allocator
> class allocator_ref
{
27 void move(allocator_ref
& other
) {
28 alloc_
= other
.alloc_
;
29 other
.alloc_
= FMT_NULL
;
33 typedef typename
Allocator::value_type value_type
;
35 explicit allocator_ref(Allocator
* alloc
= FMT_NULL
) : alloc_(alloc
) {}
37 allocator_ref(const allocator_ref
& other
) : alloc_(other
.alloc_
) {}
38 allocator_ref(allocator_ref
&& other
) { move(other
); }
40 allocator_ref
& operator=(allocator_ref
&& other
) {
41 assert(this != &other
);
46 allocator_ref
& operator=(const allocator_ref
& other
) {
47 alloc_
= other
.alloc_
;
52 Allocator
* get() const { return alloc_
; }
54 value_type
* allocate(std::size_t n
) {
55 return fmt::internal::allocate(*alloc_
, n
);
57 void deallocate(value_type
* p
, std::size_t n
) { alloc_
->deallocate(p
, n
); }
60 #endif // FMT_MOCK_ALLOCATOR_H_