LMMS
Loading...
Searching...
No Matches
fobject.cpp
Go to the documentation of this file.
1//------------------------------------------------------------------------
2// Project : SDK Base
3// Version : 1.0
4//
5// Category : Helpers
6// Filename : base/source/fobject.cpp
7// Created by : Steinberg, 2008
8// Description : Basic Object implementing FUnknown
9//
10//-----------------------------------------------------------------------------
11// LICENSE
12// (c) 2021, Steinberg Media Technologies GmbH, All Rights Reserved
13//-----------------------------------------------------------------------------
14// Redistribution and use in source and binary forms, with or without modification,
15// are permitted provided that the following conditions are met:
16//
17// * Redistributions of source code must retain the above copyright notice,
18// this list of conditions and the following disclaimer.
19// * Redistributions in binary form must reproduce the above copyright notice,
20// this list of conditions and the following disclaimer in the documentation
21// and/or other materials provided with the distribution.
22// * Neither the name of the Steinberg Media Technologies nor the names of its
23// contributors may be used to endorse or promote products derived from this
24// software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
34// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
35// OF THE POSSIBILITY OF SUCH DAMAGE.
36//-----------------------------------------------------------------------------
37
38#include "base/source/fobject.h"
40
41#include <vector>
42
43namespace Steinberg {
44
46
47//------------------------------------------------------------------------
48const FUID FObject::iid;
49
50//------------------------------------------------------------------------
52{
53 // the object iid is always generated so that different components
54 // only can cast to their own objects
55 // this initializer must be after the definition of FObject::iid, otherwise
56 // the default constructor of FUID will clear the generated iid
58 {
59 const_cast<FUID&> (FObject::iid).generate ();
60 }
62
63//------------------------------------------------------------------------
64uint32 PLUGIN_API FObject::addRef ()
65{
67}
68
69//------------------------------------------------------------------------
71{
73 {
74 refCount = -1000;
75 delete this;
76 return 0;
77 }
78 return refCount;
79}
80
81//------------------------------------------------------------------------
82tresult PLUGIN_API FObject::queryInterface (const TUID _iid, void** obj)
83{
87 *obj = nullptr;
88 return kNoInterface;
89}
90
91//------------------------------------------------------------------------
93{
95 gUpdateHandler->addDependent (unknownCast (), dep);
96}
97
98//------------------------------------------------------------------------
100{
101 if (gUpdateHandler)
102 gUpdateHandler->removeDependent (unknownCast (), dep);
103}
104
105//------------------------------------------------------------------------
107{
109 gUpdateHandler->triggerUpdates (unknownCast (), msg);
110 else
112}
113
114//------------------------------------------------------------------------
116{
117 if (gUpdateHandler)
118 gUpdateHandler->deferUpdates (unknownCast (), msg);
119 else
120 updateDone (msg);
121}
122
123//------------------------------------------------------------------------
125//------------------------------------------------------------------------
126namespace Singleton
127{
128 using ObjectVector = std::vector<FObject**>;
132
134
136 {
137 if (!singletonsLock) // assume first call not from multiple threads
139 singletonsLock->lock ();
140 }
142 {
143 singletonsLock->unlock ();
144 }
145
147 {
149 if (singletonsTerminated == false)
150 {
151 if (singletonInstances == nullptr)
152 singletonInstances = NEW std::vector<FObject**>;
153 singletonInstances->push_back (o);
154 }
155 }
156
157 struct Deleter
158 {
160 {
163 {
164 for (ObjectVector::iterator it = singletonInstances->begin (),
165 end = singletonInstances->end ();
166 it != end; ++it)
167 {
168 FObject** obj = (*it);
169 (*obj)->release ();
170 *obj = nullptr;
171 obj = nullptr;
172 }
173
174 delete singletonInstances;
175 singletonInstances = nullptr;
176 }
177 delete singletonsLock;
178 singletonsLock = nullptr;
179 }
181}
182
183//------------------------------------------------------------------------
184} // namespace Steinberg
Definition flock.h:92
Definition fobject.h:82
virtual void addDependent(IDependent *dep)
adds dependency to the object
Definition fobject.cpp:92
virtual void removeDependent(IDependent *dep)
removes dependency from the object
Definition fobject.cpp:99
virtual void changed(int32 msg=kChanged)
Inform all dependents, that the object has changed.
Definition fobject.cpp:106
FObject()
default constructor...
Definition fobject.h:85
static const FUID iid
Definition fobject.h:123
uint32 PLUGIN_API addRef() SMTG_OVERRIDE
please refer to FUnknown::addref ()
Definition fobject.cpp:64
virtual void deferUpdate(int32 msg=kChanged)
Similar to triggerUpdates, except only delivered in idle (usefull in collecting updates).
Definition fobject.cpp:115
tresult PLUGIN_API queryInterface(const TUID _iid, void **obj) SMTG_OVERRIDE
please refer to FUnknown::queryInterface ()
Definition fobject.cpp:82
virtual void updateDone(int32)
empty virtual method that should be overridden by derived classes
Definition fobject.h:112
int32 refCount
COM-model local reference count.
Definition fobject.h:127
uint32 PLUGIN_API release() SMTG_OVERRIDE
please refer to FUnknown::release ()
Definition fobject.cpp:70
static IUpdateHandler * gUpdateHandler
Definition fobject.h:129
FUnknown * unknownCast()
get FUnknown interface from object
Definition fobject.h:97
Definition funknown.h:233
Definition funknown.h:361
static const FUID iid
Definition funknown.h:382
Definition iupdatehandler.h:76
static const FUID iid
Definition iupdatehandler.h:92
Definition iupdatehandler.h:41
#define NEW
Definition fdebug.h:212
#define SMTG_ASSERT(f)
Definition fdebug.h:196
#define QUERY_INTERFACE(iid, obj, InterfaceIID, InterfaceName)
Definition funknown.h:131
static int generate(SordWorld *world, SordModel *sord, size_t n_quads, SordNode *graph)
Definition sord_test.c:72
const char * msg
Definition missing_descriptor.c:20
int32 PLUGIN_API atomicAdd(int32 &var, int32 d)
Definition funknown.cpp:88
Definition fobject.cpp:127
void unlockRegister()
Definition fobject.cpp:141
bool isTerminated()
Definition fobject.cpp:133
struct Steinberg::Singleton::Deleter deleter
Steinberg::Base::Thread::FLock * singletonsLock
Definition fobject.cpp:131
void lockRegister()
Definition fobject.cpp:135
void registerInstance(FObject **o)
Definition fobject.cpp:146
ObjectVector * singletonInstances
Definition fobject.cpp:129
std::vector< FObject ** > ObjectVector
Definition fobject.cpp:128
bool singletonsTerminated
Definition fobject.cpp:130
Definition baseiids.cpp:43
int int32
Definition ftypes.h:50
int8 TUID[16]
plain UID type
Definition funknown.h:210
@ kNoInterface
Definition funknown.h:192
struct Steinberg::FObjectIIDInitializer gFObjectIidInitializer
int32 tresult
Definition ftypes.h:76
unsigned int uint32
Definition ftypes.h:51
FObjectIIDInitializer()
Definition fobject.cpp:57
Definition fobject.cpp:158
~Deleter()
Definition fobject.cpp:159