GL Studio C++ Runtime API
weak_referenceable_mixin.h
Go to the documentation of this file.
1/*! \file
2 \brief weak reference and related classes
3
4 \par Copyright Information
5
6 Copyright (c) 2016 by The DiSTI Corporation.<br>
7 11301 Corporate Blvd; Suite 100<br>
8 Orlando, Florida 32817<br>
9 USA<br>
10 <br>
11 All rights reserved.<br>
12
13 This Software contains proprietary trade secrets of DiSTI and may not be
14reproduced, in whole or part, in any form, or by any means of electronic,
15mechanical, or otherwise, without the written permission of DiSTI. Said
16permission may be derived through the purchase of applicable DiSTI product
17licenses which detail the distribution rights of this content and any
18Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37State of Florida and the United States of America.
38
39*/
40#ifndef INCLUDED_WEAK_REFERENCEABLE_MIXIN_H
41#define INCLUDED_WEAK_REFERENCEABLE_MIXIN_H
42
43#include "dynamic_array.h"
45#include "weak_reference.h"
46
47namespace disti
48{
49/** utility helper mixin class for simplifying implementing WeakReferenceable.
50 * Classes that want to implement WeakReferenceable can simply inherit this class
51 */
53{
54public:
56 {
57 // reduce storage by only allocating the dynamic array when asked for a weak reference
58 if( !_weakRefs )
59 {
61 }
62
63 // store the weak reference so we can notify it when we are deleted
64 _weakRefs->PushBack( weakRef );
65 }
66
68 {
69 // When a weak reference is deleted, remove it from our list so that we don't call a method on a deleted object
70 // in our destructor
71 if( _weakRefs )
72 {
73 for( unsigned int index = 0u; index < _weakRefs->Count(); ++index )
74 {
75 if( ref == ( *_weakRefs )[ index ] )
76 {
77 _weakRefs->EraseAt( index );
78 return;
79 }
80 }
81 }
82 }
83
84protected:
85 /** constructor */
87 : _weakRefs( NULL )
88 {
89 }
90
91 /** destructor. Notifies all weak references that this object is being deleted */
93 {
94 if( _weakRefs )
95 {
96 for( unsigned int index = 0u; index < _weakRefs->Count(); ++index )
97 {
98 ( *_weakRefs )[ index ]->NotifyReferentDestroyed();
99 }
100
101 delete _weakRefs;
102 _weakRefs = NULL;
103 }
104 }
105
106 /** pointer to array of weak refs. Allocated on the first call to GetWeakReference() */
108};
109
110} // namespace disti
111
112#endif
Definition: dynamic_array.h:79
Definition: weak_reference.h:52
Definition: weak_referenceable_mixin.h:53
virtual ~WeakReferenceableMixin()
Definition: weak_referenceable_mixin.h:92
DynamicArray< WeakReference * > * _weakRefs
Definition: weak_referenceable_mixin.h:107
void AddWeakReference(WeakReference *weakRef) override
Definition: weak_referenceable_mixin.h:55
WeakReferenceableMixin()
Definition: weak_referenceable_mixin.h:86
void NotifyWeakReferenceDestroyed(WeakReference *ref) override
Definition: weak_referenceable_mixin.h:67
Definition: weak_reference.h:65
The disti::DynamicArray class. A templated array of objects capable of dynamically growing.
Macros and helper code to determine what subset of C++11/14/17 is available.
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:214
Force inclusion of the DirectShow library.
Definition: bmpimage.h:47
weak reference and related classes