Sese Framework
2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
Memory.h
Go to the documentation of this file.
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
22
#pragma once
23
#include <memory>
24
25
#ifdef _WIN32
26
#pragma warning(disable : 4819)
27
#endif
28
29
namespace
sese
{
30
31
template
<
typename
T>
32
using
SharedType
= std::shared_ptr<T>;
33
34
template
<
typename
T>
35
using
UniqueType
= std::unique_ptr<T>;
36
37
template
<
typename
T>
38
using
WeakType
= std::weak_ptr<T>;
39
47
template
<
typename
RETURN_TYPE,
typename
... ARGS>
48
inline
SharedType<RETURN_TYPE>
makeShared
(ARGS &&...args) {
49
return
std::make_shared<RETURN_TYPE>(args...);
50
}
51
59
template
<
typename
RETURN_TYPE,
typename
... ARGS>
60
inline
SharedType<RETURN_TYPE>
makeUnique
(ARGS &&...args) {
61
return
std::make_unique<RETURN_TYPE>(args...);
62
}
63
64
#define MAKE_SHARED_PRIVATE(RETURN_TYPE, ...) sese::SharedType<RETURN_TYPE>(new RETURN_TYPE(__VA_ARGS__))
65
66
#define MAKE_UNIQUE_PRIVATE(RETURN_TYPE, ...) sese::UniqueType<RETURN_TYPE>(new RETURN_TYPE(__VA_ARGS__))
67
75
template
<
typename
RETURN_TYPE,
typename
INIT_TYPE>
76
SharedType<RETURN_TYPE>
makeSharedFromList
(std::initializer_list<INIT_TYPE> list) {
77
return
std::make_shared<RETURN_TYPE>(std::move(list));
78
}
79
87
template
<
typename
RETURN_TYPE,
typename
INIT_TYPE>
88
UniqueType<RETURN_TYPE>
makeUniqueFromList
(std::initializer_list<INIT_TYPE> list) {
89
return
std::make_unique<RETURN_TYPE>(std::move(list));
90
}
91
99
template
<
typename
RETURN_TYPE,
typename
RAW_TYPE>
100
inline
SharedType<RETURN_TYPE>
dynamicPointerCast
(
SharedType<RAW_TYPE>
raw_type) {
101
return
std::dynamic_pointer_cast<RETURN_TYPE>(raw_type);
102
}
103
111
template
<
typename
RETURN_TYPE,
typename
RAW_TYPE>
112
UniqueType<RETURN_TYPE>
dynamicPointerCast
(
UniqueType<RAW_TYPE>
&raw_type) {
113
RAW_TYPE *pointer = raw_type.release();
114
RETURN_TYPE *newPointer =
dynamic_cast<
RETURN_TYPE *
>
(pointer);
// NOLINT
115
return
std::unique_ptr<RETURN_TYPE>(newPointer);
116
}
117
}
// namespace sese
sese
util
Memory.h
Generated on Tue Jan 7 2025 15:49:06 for Sese Framework by
1.11.0