-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathmemory_pool_adaptor.h
More file actions
63 lines (56 loc) · 2.06 KB
/
memory_pool_adaptor.h
File metadata and controls
63 lines (56 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright 2026-present Alibaba Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <memory>
#include <string>
#include "paimon/memory/memory_pool.h"
namespace paimon {
/// CRTP base class for memory pool adaptors.
///
/// This class provides the common interface required by MemoryPool::AsSpecifiedMemoryPool().
/// Subclasses should inherit from MemoryPoolAdaptor<Subclass> and implement:
/// - A static Identifier() method returning a unique string identifier
/// - A constructor accepting MemoryPool& as parameter
///
/// @tparam Adaptor The derived adaptor class (CRTP pattern).
///
/// @example
/// class MyPoolAdaptor : public SomePoolInterface,
/// public MemoryPoolAdaptor<MyPoolAdaptor> {
/// public:
/// explicit MyPoolAdaptor(MemoryPool& pool) : pool_(pool) {}
/// static std::string Identifier() { return "MyPoolAdaptor"; }
/// // ... implement SomePoolInterface methods ...
/// private:
/// MemoryPool& pool_;
/// };
///
/// SomePoolInterface* AsSomePool(MemoryPool& pool) {
/// return pool.AsSpecifiedMemoryPool<MyPoolAdaptor>();
/// }
template <typename Adaptor>
class MemoryPoolAdaptor {
public:
static std::string Identifier() {
return Adaptor::Identifier();
}
static MemoryPool::AdaptorPtr Create(MemoryPool& pool) {
auto adaptor = std::make_unique<Adaptor>(pool);
return MemoryPool::AdaptorPtr(adaptor.release(),
[](void* ptr) { delete static_cast<Adaptor*>(ptr); });
}
};
} // namespace paimon