Skip to content

Commit 5196c52

Browse files
Common: added RefCntContainer template struct
1 parent 2a995cb commit 5196c52

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

Common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(INTERFACE
2929
interface/ObjectsRegistry.hpp
3030
interface/ParsingTools.hpp
3131
interface/RefCntAutoPtr.hpp
32+
interface/RefCntContainer.hpp
3233
interface/RefCountedObjectImpl.hpp
3334
interface/Serializer.hpp
3435
interface/SpinLock.hpp
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2024 Diligent Graphics LLC
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+
*
16+
* In no event and under no legal theory, whether in tort (including negligence),
17+
* contract, or otherwise, unless required by applicable law (such as deliberate
18+
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
19+
* liable for any damages, including any direct, indirect, special, incidental,
20+
* or consequential damages of any character arising as a result of this License or
21+
* out of the use or inability to use the software (including but not limited to damages
22+
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23+
* all other commercial damages or losses), even if such Contributor has been advised
24+
* of the possibility of such damages.
25+
*/
26+
27+
#pragma once
28+
29+
/// \file
30+
/// Implementation of the Diligent::RefCntContainer template struct
31+
32+
#include "ObjectBase.hpp"
33+
#include "RefCntAutoPtr.hpp"
34+
35+
namespace Diligent
36+
{
37+
38+
/// Template struct that wraps an object of type Type into a reference-counted container.
39+
template <typename Type>
40+
struct RefCntContainer : public ObjectBase<IObject>
41+
{
42+
using TBase = ObjectBase<IObject>;
43+
44+
template <typename... Args>
45+
RefCntContainer(IReferenceCounters* pRefCounters, Args&&... args) :
46+
TBase{pRefCounters},
47+
Data{std::forward<Args>(args)...}
48+
{}
49+
50+
template <typename... Args>
51+
static RefCntAutoPtr<RefCntContainer> Create(Args&&... args)
52+
{
53+
return RefCntAutoPtr<RefCntContainer>{MakeNewRCObj<RefCntContainer>()(std::forward<Args>(args)...)};
54+
}
55+
56+
Type Data;
57+
};
58+
59+
} // namespace Diligent

0 commit comments

Comments
 (0)