Sese Framework
x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
Memory.h
浏览该文件的文档.
1
// Copyright 2024 libsese
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
21
#pragma once
22
#include <memory>
23
24
#ifdef _WIN32
25
#pragma warning(disable : 4819)
26
#endif
27
28
namespace
sese
{
29
30
template
<
typename
T>
31
using
SharedType
= std::shared_ptr<T>;
32
33
template
<
typename
T>
34
using
UniqueType
= std::unique_ptr<T>;
35
36
template
<
typename
T>
37
using
WeakType
= std::weak_ptr<T>;
38
46
template
<
typename
RETURN_TYPE,
typename
... ARGS>
47
inline
SharedType<RETURN_TYPE>
makeShared
(ARGS &&...args) {
48
return
std::make_shared<RETURN_TYPE>(args...);
49
}
50
58
template
<
typename
RETURN_TYPE,
typename
... ARGS>
59
inline
SharedType<RETURN_TYPE>
makeUnique
(ARGS &&...args) {
60
return
std::make_unique<RETURN_TYPE>(args...);
61
}
62
63
#define MAKE_SHARED_PRIVATE(RETURN_TYPE, ...) sese::SharedType<RETURN_TYPE>(new RETURN_TYPE(__VA_ARGS__))
64
65
#define MAKE_UNIQUE_PRIVATE(RETURN_TYPE, ...) sese::UniqueType<RETURN_TYPE>(new RETURN_TYPE(__VA_ARGS__))
66
74
template
<
typename
RETURN_TYPE,
typename
INIT_TYPE>
75
SharedType<RETURN_TYPE>
makeSharedFromList
(std::initializer_list<INIT_TYPE> list) {
76
return
std::make_shared<RETURN_TYPE>(std::move(list));
77
}
78
86
template
<
typename
RETURN_TYPE,
typename
INIT_TYPE>
87
UniqueType<RETURN_TYPE>
makeUniqueFromList
(std::initializer_list<INIT_TYPE> list) {
88
return
std::make_unique<RETURN_TYPE>(std::move(list));
89
}
90
98
template
<
typename
RETURN_TYPE,
typename
RAW_TYPE>
99
inline
SharedType<RETURN_TYPE>
dynamicPointerCast
(
SharedType<RAW_TYPE>
raw_type) {
100
return
std::dynamic_pointer_cast<RETURN_TYPE>(raw_type);
101
}
102
110
template
<
typename
RETURN_TYPE,
typename
RAW_TYPE>
111
UniqueType<RETURN_TYPE>
dynamicPointerCast
(
UniqueType<RAW_TYPE>
&raw_type) {
112
RAW_TYPE *pointer = raw_type.release();
113
RETURN_TYPE *newPointer =
dynamic_cast<
RETURN_TYPE *
>
(pointer);
// NOLINT
114
return
std::unique_ptr<RETURN_TYPE>(newPointer);
115
}
116
}
// namespace sese
sese
util
Memory.h
生成于 2024年 十一月 4日 星期一 09:58:03 , 为 Sese Framework使用
1.11.0