LMMS
Loading...
Searching...
No Matches
juce_OptionalScopedPointer.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
36template <class ObjectType>
38{
39public:
40 //==============================================================================
43
51 OptionalScopedPointer (ObjectType* objectToHold, bool takeOwnership)
52 : object (objectToHold),
53 shouldDelete (takeOwnership)
54 {
55 }
56
66 : object (std::move (other.object)),
67 shouldDelete (std::move (other.shouldDelete))
68 {
69 }
70
72 explicit OptionalScopedPointer (std::unique_ptr<ObjectType>&& ptr) noexcept
73 : OptionalScopedPointer (ptr.release(), true)
74 {
75 }
76
78 explicit OptionalScopedPointer (ObjectType& ref) noexcept
79 : OptionalScopedPointer (std::addressof (ref), false)
80 {
81 }
82
91 OptionalScopedPointer& operator= (OptionalScopedPointer&& other) noexcept
92 {
93 swapWith (other);
94 other.reset();
95 return *this;
96 }
97
106
107 //==============================================================================
109 operator ObjectType*() const noexcept { return object.get(); }
110
112 ObjectType* get() const noexcept { return object.get(); }
113
115 ObjectType& operator*() const noexcept { return *object; }
116
118 ObjectType* operator->() const noexcept { return object.get(); }
119
120 //==============================================================================
124 ObjectType* release() noexcept { return object.release(); }
125
130 {
131 if (! shouldDelete)
132 object.release();
133 else
134 object.reset();
135 }
136
138 void clear() { reset(); }
139
147 void set (ObjectType* newObject, bool takeOwnership)
148 {
149 if (object.get() != newObject)
150 {
151 reset();
152 object.reset (newObject);
153 }
154
155 shouldDelete = takeOwnership;
156 }
157
159 void setOwned (ObjectType* newObject)
160 {
161 set (newObject, true);
162 }
163
165 void setNonOwned (ObjectType* newObject)
166 {
167 set (newObject, false);
168 }
169
174
175 //==============================================================================
180 {
181 std::swap (other.object, object);
182 std::swap (other.shouldDelete, shouldDelete);
183 }
184
185private:
186 //==============================================================================
187 std::unique_ptr<ObjectType> object;
188 bool shouldDelete = false;
189};
190
191} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
OptionalScopedPointer(ObjectType *objectToHold, bool takeOwnership)
Definition juce_OptionalScopedPointer.h:51
void setNonOwned(ObjectType *newObject)
Definition juce_OptionalScopedPointer.h:165
void set(ObjectType *newObject, bool takeOwnership)
Definition juce_OptionalScopedPointer.h:147
void clear()
Definition juce_OptionalScopedPointer.h:138
void reset() noexcept
Definition juce_OptionalScopedPointer.h:129
OptionalScopedPointer(std::unique_ptr< ObjectType > &&ptr) noexcept
Definition juce_OptionalScopedPointer.h:72
ObjectType * get() const noexcept
Definition juce_OptionalScopedPointer.h:112
OptionalScopedPointer(ObjectType &ref) noexcept
Definition juce_OptionalScopedPointer.h:78
ObjectType & operator*() const noexcept
Definition juce_OptionalScopedPointer.h:115
ObjectType * release() noexcept
Definition juce_OptionalScopedPointer.h:124
void setOwned(ObjectType *newObject)
Definition juce_OptionalScopedPointer.h:159
void swapWith(OptionalScopedPointer< ConvolutionMessageQueue > &other) noexcept
Definition juce_OptionalScopedPointer.h:179
bool willDeleteObject() const noexcept
Definition juce_OptionalScopedPointer.h:173
ObjectType * operator->() const noexcept
Definition juce_OptionalScopedPointer.h:118
OptionalScopedPointer(OptionalScopedPointer &&other) noexcept
Definition juce_OptionalScopedPointer.h:65
bool shouldDelete
Definition juce_OptionalScopedPointer.h:188
~OptionalScopedPointer() noexcept
Definition juce_OptionalScopedPointer.h:102
std::unique_ptr< ConvolutionMessageQueue > object
Definition juce_OptionalScopedPointer.h:187
void * object
Definition jmemsys.h:50
Definition carla_juce.cpp:31
jack_client_t client jack_client_t client jack_client_t client jack_client_t JackInfoShutdownCallback void arg jack_client_t jack_port_t port void func jack_client_t const char const char unsigned long flags const jack_port_t port jack_client_t jack_port_id_t port_id const jack_port_t const char port_name const jack_port_t port void * ptr
Definition juce_linux_JackAudio.cpp:79
#define const
Definition zconf.h:137