TGUI  0.9.5
Loading...
Searching...
No Matches
CopiedSharedPtr.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25
26#ifndef TGUI_COPIED_SHARED_PTR_HPP
27#define TGUI_COPIED_SHARED_PTR_HPP
28
29
30#include <memory>
31
33
34namespace tgui
35{
37
38 template <typename WidgetType>
40 {
41 public:
42
43 template <typename... Args>
44 CopiedSharedPtr(Args&&... args) noexcept
45 : m_WidgetPtr{std::make_shared<WidgetType>(std::forward<Args>(args)...)}
46 {
47 }
48
49 CopiedSharedPtr(const CopiedSharedPtr& other) noexcept
50 : m_WidgetPtr{std::make_shared<WidgetType>(*other.m_WidgetPtr)}
51 {
52 }
53
54 CopiedSharedPtr(CopiedSharedPtr&& other) noexcept
55 : m_WidgetPtr{std::move(other.m_WidgetPtr)}
56 {
57 }
58
59 CopiedSharedPtr& operator=(const CopiedSharedPtr& other) noexcept
60 {
61 if (&other != this)
62 m_WidgetPtr = std::make_shared<WidgetType>(*other.m_WidgetPtr);
63
64 return *this;
65 }
66
67 CopiedSharedPtr& operator=(CopiedSharedPtr&& other) noexcept
68 {
69 if (&other != this)
70 m_WidgetPtr = std::move(other.m_WidgetPtr);
71
72 return *this;
73 }
74
75 operator bool() const noexcept
76 {
77 return (m_WidgetPtr != nullptr);
78 }
79
80 WidgetType& operator*() const noexcept
81 {
82 return *m_WidgetPtr;
83 }
84
85 WidgetType* operator->() const noexcept
86 {
87 return m_WidgetPtr.get();
88 }
89
90 WidgetType* get() const noexcept
91 {
92 return m_WidgetPtr.get();
93 }
94
96 private:
97
98 std::shared_ptr<WidgetType> m_WidgetPtr;
99 };
100
101
103}
104
106
107#endif // TGUI_COPIED_SHARED_PTR_HPP
Definition CopiedSharedPtr.hpp:40
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36