CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
weak_reference.h
1
2#pragma once
3
4#include "system/object.h"
5#include "system/smart_ptr.h"
6#include "system/weak_ptr.h"
7
8namespace System
9{
12 template <typename... Args>
13 class ASPOSECPP_SHARED_CLASS WeakReference;
14
17 template <typename T>
18 class ASPOSECPP_SHARED_CLASS WeakReference<T> : public System::Object
19 {
20
21 RTTI_INFO(System::WeakReference<T>, ::System::BaseTypesInfo<System::Object>)
22 public:
25 {
26 }
27
29 WeakReference(std::nullptr_t)
30 {
31 }
32
36 {
37 wptr = data;
38 }
39
43 WeakReference(const SmartPtr<T>& data, bool trackResurrection)
44 {
45 ASPOSE_UNUSED(trackResurrection);
46 wptr = data;
47 }
48
52 bool TryGetTarget(const SmartPtr<T>& data) const
53 {
54 data = wptr;
55 return true;
56 }
57
60 void SetTarget(const SmartPtr<T>& data)
61 {
62 wptr = data;
63 }
64
65 void reset()
66 {
67 wptr.reset();
68 }
69
72 bool operator==(std::nullptr_t) const
73 {
74 return wptr == nullptr;
75 }
76
79 bool operator!=(std::nullptr_t) const
80 {
81 return !(*this == nullptr);
82 }
83
87 bool operator==(const WeakReference<T>& other) const
88 {
89 return wptr == other.wptr;
90 }
91
95 bool operator!=(const WeakReference<T>& other) const
96 {
97 return wptr != other.wptr;
98 }
99
100 protected:
102 };
103
105 template <>
106 class ASPOSECPP_SHARED_CLASS WeakReference<> : public WeakReference<System::Object>
107 {
108
109 RTTI_INFO(System::WeakReference<>, ::System::BaseTypesInfo<System::Object>);
110 public:
113 {
114 }
115
117 WeakReference(std::nullptr_t) : WeakReference<Object>(nullptr)
118 {
119 }
120
124 {
125 }
126
130 WeakReference(const SmartPtr<Object>& data, bool trackResurrection) : WeakReference<Object>(data, trackResurrection)
131 {
132 }
133
137 {
138 return wptr;
139 }
140
143 void set_Target(const SmartPtr<Object>& data)
144 {
145 wptr = data;
146 }
147
150 bool get_IsAlive() const
151 {
152 return !wptr.expired();
153 }
154 };
155}
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Subclass of System::SmartPtr which sets itself to weak mode at construction. Please note that this cl...
Definition: weak_ptr.h:18
Represents a weak reference, which references an object while still allowing that object to be delete...
Definition: weak_reference.h:19
WeakReference(const SmartPtr< T > &data)
Initializes a new instance of the WeakReference class, referencing the specified object.
Definition: weak_reference.h:35
void SetTarget(const SmartPtr< T > &data)
Sets the object (the target) referenced by the current WeakReference object.
Definition: weak_reference.h:60
WeakPtr< T > wptr
Definition: weak_reference.h:101
bool operator==(std::nullptr_t) const
Checks if referenced object is null.
Definition: weak_reference.h:72
bool operator!=(const WeakReference< T > &other) const
Compares referenced object to another instance WeakReference class.
Definition: weak_reference.h:95
bool TryGetTarget(const SmartPtr< T > &data) const
Gets the object (the target) referenced by the current WeakReference object.
Definition: weak_reference.h:52
bool operator==(const WeakReference< T > &other) const
Compares referenced object to another instance WeakReference class.
Definition: weak_reference.h:87
WeakReference()
Default constructor.
Definition: weak_reference.h:24
WeakReference(std::nullptr_t)
Constructor from nullptr.
Definition: weak_reference.h:29
void reset()
Definition: weak_reference.h:65
bool operator!=(std::nullptr_t) const
Checks if referenced object is not null.
Definition: weak_reference.h:79
WeakReference(const SmartPtr< T > &data, bool trackResurrection)
Initializes a new instance of the WeakReference class, referencing the specified object.
Definition: weak_reference.h:43
Represents a weak reference, which references an object while still allowing that object to be delete...
Definition: weak_reference.h:107
bool get_IsAlive() const
Gets an indication whether the object referenced by the current WeakReference object has been deleted...
Definition: weak_reference.h:150
WeakReference()
Default constructor.
Definition: weak_reference.h:112
const WeakPtr< Object > & get_Target() const
Gets the object (the target) referenced by the current WeakReference object.
Definition: weak_reference.h:136
WeakReference(std::nullptr_t)
Constructor from nullptr.
Definition: weak_reference.h:117
void set_Target(const SmartPtr< Object > &data)
Sets the object (the target) referenced by the current WeakReference object.
Definition: weak_reference.h:143
WeakReference(const SmartPtr< Object > &data)
Initializes a new instance of the WeakReference class, referencing the specified object.
Definition: weak_reference.h:123
WeakReference(const SmartPtr< Object > &data, bool trackResurrection)
Initializes a new instance of the WeakReference class, referencing the specified object.
Definition: weak_reference.h:130
Definition: db_command.h:9
class ASPOSECPP_SHARED_CLASS WeakReference
Represents a weak reference, which references an object while still allowing that object to be delete...
Definition: weak_reference.h:13