cpp-msgpack-light
0.3.0
A light library to serialize MessagePack.
Toggle main menu visibility
Loading...
Searching...
No Matches
allocator_wrapper.h
Go to the documentation of this file.
1
/*
2
* Copyright 2024 MusicScience37 (Kenta Kabashima)
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
20
#pragma once
21
22
#include <cstddef>
23
#include <utility>
// IWYU pragma: keep
24
25
#include "
msgpack_light/details/object_data.h
"
26
27
namespace
msgpack_light::details
{
28
34
template
<
typename
Allocator>
35
class
allocator_wrapper
{
36
public
:
42
explicit
allocator_wrapper
(Allocator allocator)
43
:
allocator_
(
std
::move(allocator)) {}
44
51
[[nodiscard]]
object_data
*
allocate_object_data
(std::size_t size) {
52
return
static_cast<
object_data
*
>
(
allocator_
.allocate(
53
size *
sizeof
(
object_data
),
alignof
(
object_data
)));
54
}
55
61
void
deallocate_object_data
(
object_data
* ptr)
noexcept
{
62
allocator_
.deallocate(ptr);
63
}
64
71
[[nodiscard]]
key_value_pair_data
*
allocate_key_value_pair_data
(
72
std::size_t size) {
73
return
static_cast<
key_value_pair_data
*
>
(
allocator_
.allocate(
74
size *
sizeof
(
key_value_pair_data
),
alignof
(
key_value_pair_data
)));
75
}
76
82
void
deallocate_key_value_pair_data
(
key_value_pair_data
* ptr)
noexcept
{
83
allocator_
.deallocate(ptr);
84
}
85
92
[[nodiscard]]
unsigned
char
*
allocate_unsigned_char
(std::size_t size) {
93
return
static_cast<
unsigned
char
*
>
(
allocator_
.allocate(size, 1U));
94
}
95
101
void
deallocate_unsigned_char
(
unsigned
char
* ptr)
noexcept
{
102
allocator_
.deallocate(ptr);
103
}
104
111
[[nodiscard]]
char
*
allocate_char
(std::size_t size) {
112
return
static_cast<
char
*
>
(
allocator_
.allocate(size, 1U));
113
}
114
120
void
deallocate_char
(
char
* ptr)
noexcept
{
allocator_
.deallocate(ptr); }
121
122
private
:
124
Allocator
allocator_
;
125
};
126
127
}
// namespace msgpack_light::details
msgpack_light::details::allocator_wrapper::deallocate_unsigned_char
void deallocate_unsigned_char(unsigned char *ptr) noexcept
Deallocate unsigned char instances.
Definition
allocator_wrapper.h:101
msgpack_light::details::allocator_wrapper::allocate_char
char * allocate_char(std::size_t size)
Allocate char instances.
Definition
allocator_wrapper.h:111
msgpack_light::details::allocator_wrapper::deallocate_char
void deallocate_char(char *ptr) noexcept
Deallocate char instances.
Definition
allocator_wrapper.h:120
msgpack_light::details::allocator_wrapper::allocator_wrapper
allocator_wrapper(Allocator allocator)
Constructor.
Definition
allocator_wrapper.h:42
msgpack_light::details::allocator_wrapper::deallocate_object_data
void deallocate_object_data(object_data *ptr) noexcept
Deallocate object data.
Definition
allocator_wrapper.h:61
msgpack_light::details::allocator_wrapper::allocate_object_data
object_data * allocate_object_data(std::size_t size)
Allocate object data.
Definition
allocator_wrapper.h:51
msgpack_light::details::allocator_wrapper::allocate_key_value_pair_data
key_value_pair_data * allocate_key_value_pair_data(std::size_t size)
Allocate key-value pair data.
Definition
allocator_wrapper.h:71
msgpack_light::details::allocator_wrapper::allocator_
Allocator allocator_
Allocator.
Definition
allocator_wrapper.h:124
msgpack_light::details::allocator_wrapper::allocate_unsigned_char
unsigned char * allocate_unsigned_char(std::size_t size)
Allocate unsigned char instances.
Definition
allocator_wrapper.h:92
msgpack_light::details::allocator_wrapper::deallocate_key_value_pair_data
void deallocate_key_value_pair_data(key_value_pair_data *ptr) noexcept
Deallocate key-value pair data.
Definition
allocator_wrapper.h:82
msgpack_light::details
Namespace of internal implementations.
Definition
binary.h:35
std
STL namespace.
object_data.h
Definition of object_data struct.
msgpack_light::details::key_value_pair_data
Struct of data of key-value pairs in maps.
Definition
object_data.h:135
msgpack_light::details::object_data
Struct of data of objects in MessagePack.
Definition
object_data.h:94
include
msgpack_light
details
allocator_wrapper.h
Generated on
for cpp-msgpack-light by
1.18.0