|
template<typename T1 , typename T2 > |
static System::SmartPtr< typename T1::Pointee_ > | BindLifetime (const T1 &target, const T2 &owner) |
| Creates a smart pointer using the aliasing constructor. Creates a pointer to the target object which controls lifetime of the owner object. This pointer's expiration is bound to expiration of the owner object, just like this of any other pointer that owns owner object. If converted to weak type, it is still consistent with other pointers to owner and does not expire while there is at least one shared pointer to owner object. Also, the returned pointer does not ensure that target object is alive, so some other means (e. g. shared pointer stored in the owner object) should do so. Should be used in the situations where owner owns the target , which effectively means that the target will be kept alive by owner even if the returned aliasing pointer no longer exists. Otherwise, doesn't guarantee that the resulting pointer will remain valid, because if owner doesn't actually hold shared reference to target , target can be deleted any time as the resulting pointer only owns owner but not the target . More...
|
|
template<typename T1 , typename T2 > |
static std::enable_if<!std::is_reference< T1 >::value, System::SmartPtr< typenameT1::Pointee_ > >::type | BindLifetime (T1 &&target, const T2 &owner) |
| Creates a smart pointer using the aliasing constructor. Creates a pointer to the target object which controls lifetime of the owner object. This pointer's expiration is bound to expiration of the owner object, just like this of any other pointer that owns owner object. If converted to weak type, it is still consistent with other pointers to owner and does not expire while there is at least one shared pointer to owner object. Also, the returned pointer does not ensure that target object is alive, so some other means (e. g. shared pointer stored in the owner object) should do so. Should be used in the situations where owner owns the target , which effectively means that the target will be kept alive by owner even if the returned aliasing pointer no longer exists. Otherwise, doesn't guarantee that the returned pointer will remain valid, because if owner doesn't actually hold shared reference to target , target can be deleted any time as the returned pointer only owns owner but not the target . More...
|
|
template<typename T , typename... Objects> |
static System::SmartPtr< typename T::Pointee_ > | ExtendLifetime (const T &target, const Objects &... objects) |
| Creates a smart pointer using the aliasing constructor and copies target and objects pointers to the "proxy" objects holder. Creates a pointer to the target and extends the lifetime of all objects to the lifetime of this pointer. The resulting pointer guarantees all parameters to remain alive, even if it is the only pointer that keeps track of them. The resulting pointer effectively owns all objects passed to this method, however, it has its own expiration track. This means, that converting its own copy to weak type will expire it, even if all objects it tracks are still alive. Should be used in the situations when there are several unrelated (not holding shared references to each other) objects that should be guaranteed to remain alive together. The returned pointer will own a temporary objects that keeps all of them alive, and this lifetime extension stops working once the returned pointer no longer exists (or all of its copies become weak). More...
|
|
template<typename T , typename TObject > |
static System::SmartPtr< typename T::Pointee_ > | ExtendLifetimeAsWeakPostponed (const System::SharedPtr< System::Object > &key, const T &target, const TObject &object) |
| Creates a smart pointer using the aliasing constructor and copies target and objects pointers to the "proxy" objects holder. Creates a pointer to the target and extends the lifetime of all objects to the lifetime of this pointer. The resulting pointer guarantees all parameters to remain alive, even if it is the only pointer that keeps track of them. key - PostponedHolders key. In the case of PostponedHolders declared above the stack with the same key, all ObjectHolders will be switched to weak mode. This will be useful when need to control the destruction of objects in the holder. For example to avoid destructor calling if an exception happens in the constructor body but "this" pointer needs to keep in the ObjectHolders. The resulting pointer effectively owns all objects passed to this method, however, it has its own expiration track. This means, that converting its own copy to weak type will expire it, even if all objects it tracks are still alive. Should be used in the situations when there are several unrelated (not holding shared references to each other) objects that should be guaranteed to remain alive together. The returned pointer will own a temporary objects that keeps all of them alive, and this lifetime extension stops working once the returned pointer no longer exists (or all of its copies become weak). More...
|
|
Defines a methods that changes the lifetime of objects.
template<typename T1 , typename T2 >
static System::SmartPtr< typename T1::Pointee_ > CodePorting::Translator::Cs2Cpp::MemoryManagement::BindLifetime |
( |
const T1 & |
target, |
|
|
const T2 & |
owner |
|
) |
| |
|
inlinestatic |
Creates a smart pointer using the aliasing constructor. Creates a pointer to the target
object which controls lifetime of the owner
object. This pointer's expiration is bound to expiration of the owner
object, just like this of any other pointer that owns owner
object. If converted to weak type, it is still consistent with other pointers to owner
and does not expire while there is at least one shared pointer to owner
object. Also, the returned pointer does not ensure that target
object is alive, so some other means (e. g. shared pointer stored in the owner
object) should do so. Should be used in the situations where owner
owns the target
, which effectively means that the target
will be kept alive by owner
even if the returned aliasing pointer no longer exists. Otherwise, doesn't guarantee that the resulting pointer will remain valid, because if owner
doesn't actually hold shared reference to target
, target
can be deleted any time as the resulting pointer only owns owner
but not the target
.
- Template Parameters
-
T1 | Type of smart pointer to the object that the new smart pointer will refer to. |
T2 | Type of smart pointer to an object whose ownership is shared with a new smart pointer. |
- Parameters
-
target | Smart pointer to the object that the new smart pointer will refer to. |
owner | Smart pointer to an object whose ownership is shared with a new smart pointer. |
- Returns
- New smart pointer.
#include "system/memory_management.h"
#include "system/object.h"
#include <iostream>
class ChildNode;
{
public:
};
{
public:
};
{
auto parent = System::MakeObject<ParentNode>();
auto child = System::MakeObject<ChildNode>();
parent->child = child;
child->parent = parent;
}
{
std::cout <<
"The pointer to an instance of the ParentNode class has expired: " << (parent.
expired() ?
"True" :
"False") << std::endl;
}
int main()
{
auto child = GetChildNode(false);
PrintInfo(child->parent);
child = GetChildNode(true);
PrintInfo(child->parent);
return 0;
}
static System::SmartPtr< typename T1::Pointee_ > BindLifetime(const T1 &target, const T2 &owner)
Creates a smart pointer using the aliasing constructor. Creates a pointer to the target object which ...
Definition: memory_management.h:165
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:65
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
bool expired() const
Checks if referenced object was already deleted.
Definition: weak_ptr.h:86
template<typename T1 , typename T2 >
static std::enable_if<!std::is_reference< T1 >::value, System::SmartPtr< typenameT1::Pointee_ > >::type CodePorting::Translator::Cs2Cpp::MemoryManagement::BindLifetime |
( |
T1 && |
target, |
|
|
const T2 & |
owner |
|
) |
| |
|
inlinestatic |
Creates a smart pointer using the aliasing constructor. Creates a pointer to the target
object which controls lifetime of the owner
object. This pointer's expiration is bound to expiration of the owner
object, just like this of any other pointer that owns owner
object. If converted to weak type, it is still consistent with other pointers to owner
and does not expire while there is at least one shared pointer to owner
object. Also, the returned pointer does not ensure that target
object is alive, so some other means (e. g. shared pointer stored in the owner
object) should do so. Should be used in the situations where owner
owns the target
, which effectively means that the target
will be kept alive by owner
even if the returned aliasing pointer no longer exists. Otherwise, doesn't guarantee that the returned pointer will remain valid, because if owner
doesn't actually hold shared reference to target
, target
can be deleted any time as the returned pointer only owns owner
but not the target
.
- Template Parameters
-
T1 | Type of smart pointer to the object that the new smart pointer will refer to. |
T2 | Type of smart pointer to an object whose ownership is shared with a new smart pointer. |
- Parameters
-
target | Smart pointer to the object that the new smart pointer will refer to. |
owner | Smart pointer to an object whose ownership is shared with a new smart pointer. |
- Returns
- New smart pointer.
template<typename T , typename... Objects>
static System::SmartPtr< typename T::Pointee_ > CodePorting::Translator::Cs2Cpp::MemoryManagement::ExtendLifetime |
( |
const T & |
target, |
|
|
const Objects &... |
objects |
|
) |
| |
|
inlinestatic |
Creates a smart pointer using the aliasing constructor and copies target
and objects
pointers to the "proxy" objects holder. Creates a pointer to the target
and extends the lifetime of all objects to the lifetime of this pointer. The resulting pointer guarantees all parameters to remain alive, even if it is the only pointer that keeps track of them. The resulting pointer effectively owns all objects passed to this method, however, it has its own expiration track. This means, that converting its own copy to weak type will expire it, even if all objects it tracks are still alive. Should be used in the situations when there are several unrelated (not holding shared references to each other) objects that should be guaranteed to remain alive together. The returned pointer will own a temporary objects that keeps all of them alive, and this lifetime extension stops working once the returned pointer no longer exists (or all of its copies become weak).
- Template Parameters
-
T | Type of the object that the new smart pointer will refer to. |
Objects | Types of the objects whose ownership is shared with a new smart pointer. |
- Parameters
-
target | Smart pointer to the object that the new smart pointer will refer to. |
objects | Smart pointers to the objects whose ownership is shared with a new smart pointer. |
- Returns
- New smart pointer.
#include "system/memory_management.h"
#include "system/object.h"
#include <iostream>
{
int32_t m_value;
public:
NodePtr previous;
NodePtr next;
explicit Node(int32_t value): m_value(value) {}
int32_t GetValue() const
{
return m_value;
}
};
{
std::cout << (node == nullptr ? "nullptr" : std::to_string(node->GetValue())) << ' ';
}
int main()
{
{
auto first = System::MakeObject<Node>(1);
node = System::MakeObject<Node>(2);
auto last = System::MakeObject<Node>(3);
first->next = node;
node->previous = first;
node->next = last;
last->previous = node;
}
PrintValue(node->previous);
PrintValue(node);
PrintValue(node->next);
std::cout << std::endl;
{
auto first = System::MakeObject<Node>(4);
auto middle = System::MakeObject<Node>(5);
auto last = System::MakeObject<Node>(6);
first->next = middle;
middle->previous = first;
middle->next = last;
last->previous = middle;
}
PrintValue(node->previous);
PrintValue(node);
PrintValue(node->next);
std::cout << std::endl;
return 0;
}
static System::SmartPtr< typename T::Pointee_ > ExtendLifetime(const T &target, const Objects &... objects)
Creates a smart pointer using the aliasing constructor and copies target and objects pointers to the ...
Definition: memory_management.h:294
template<typename T , typename TObject >
Creates a smart pointer using the aliasing constructor and copies target
and objects
pointers to the "proxy" objects holder. Creates a pointer to the target
and extends the lifetime of all objects to the lifetime of this pointer. The resulting pointer guarantees all parameters to remain alive, even if it is the only pointer that keeps track of them. key - PostponedHolders key. In the case of PostponedHolders declared above the stack with the same key, all ObjectHolders will be switched to weak mode. This will be useful when need to control the destruction of objects in the holder. For example to avoid destructor calling if an exception happens in the constructor body but "this" pointer needs to keep in the ObjectHolders. The resulting pointer effectively owns all objects passed to this method, however, it has its own expiration track. This means, that converting its own copy to weak type will expire it, even if all objects it tracks are still alive. Should be used in the situations when there are several unrelated (not holding shared references to each other) objects that should be guaranteed to remain alive together. The returned pointer will own a temporary objects that keeps all of them alive, and this lifetime extension stops working once the returned pointer no longer exists (or all of its copies become weak).