4#include <system/object.h>
5#include <system/smart_ptr.h>
6#include <system/exceptions.h>
7#include <system/iobjects_holder.h>
8#include <system/details/objects_bag.h>
14namespace CodePorting {
namespace Translator {
namespace Cs2Cpp {
23template <
size_t ObjectCount>
27 template <
typename ...Args,
typename = std::enable_if_t<
sizeof...(Args) == ObjectCount>>
29 : m_objects{ args... }
38 for (
int n = 1; n < ObjectCount; ++n)
44#if defined(__DBG_TOOLS)
45 std::vector<int> getHoldObjectIds() const final
48 for (
int n = 1; n < ObjectCount; ++n)
50 res.push_back(System::Details::DbgTools::DBG_InstanceNo(m_objects[n].GetObjectOrNull()));
60#ifdef ASPOSE_GET_SHARED_MEMBERS
61 void GetSharedMembers(System::Object::shared_members_type& result)
const override
63 System::Object::GetSharedMembers(result);
64 for (
auto&
object : m_objects)
65 result.Add(
"m_objects[]",
object);
69#ifdef __DBG_FOR_EACH_MEMBER
71 void DBG_for_each_member(System::DBG::for_each_member_visitor &visitor)
const override
73 visitor.add_self(
this);
74 System::DBG::for_each_of_Object(
this, m_objects, visitor);
77 const char* DBG_class_name()
const override {
return "ObjectsHolder<T>"; }
164 template<
typename T1,
typename T2>
189 template<
typename T1,
typename T2>
194 if (target !=
nullptr && target->SharedCount() == 1)
195 throw System::InvalidOperationException(u
"Can not bind lifetime for a temporary target object");
293 template <
typename T,
typename... Objects>
303 class PostponedHolders;
305 class PostponedHoldersRegistrar;
324 template <
typename T,
typename TObject>
333 auto* postpone_holder = PostponedHoldersRegistrar::inst().get(key);
336 postpone_holder->addHolder(holder);
344 class PostponedHoldersRegistrar
346 friend class PostponedHolders;
348 template <
typename T,
typename TObject>
352 static PostponedHoldersRegistrar & inst()
354 static PostponedHoldersRegistrar instance;
359 void reg(
void *key, PostponedHolders *holder)
361 if (m_map_holders.end() != m_map_holders.find(key))
366 m_map_holders.insert({key, holder});
370 void unreg(
void *key)
372 m_map_holders.erase(key);
380 auto it = m_map_holders.find(key.
get());
381 if (m_map_holders.end() == it)
390 using map_holders = std::map<void*, PostponedHolders*>;
391 map_holders m_map_holders;
398 template <
typename T,
typename TObject>
405 PostponedHoldersRegistrar::inst().reg(m_key,
this);
410 PostponedHoldersRegistrar::inst().unreg(m_key);
417 for (
auto& holder : posponed_weak_holders)
421 posponed_weak_holders.clear();
429 posponed_weak_holders.push_back(holder);
433 std::list<System::SharedPtr<Details::IObjectsHolder>> posponed_weak_holders;
Base class for ObjectsHolder. Need for control ObjectHolder pointer's mode. See PostponedHolders clas...
Definition: iobjects_holder.h:17
Used to hold multiple objects. Objects of this class should only be allocated using System::MakeObjec...
Definition: memory_management.h:25
ObjectsHolder(const ObjectsHolder &)=delete
ObjectsHolder & operator=(const ObjectsHolder &)=delete
ObjectsHolder(const System::SmartPtr< Args > &...args)
Definition: memory_management.h:28
void setObjectsMode(System::SmartPtrMode mode) final
Change object holders smart pointers modes. mode - Smart pointer mode.
Definition: memory_management.h:36
Keeps ObjectHolder's in Weak state and after the switch, it to Shared remove it from a local collecti...
Definition: memory_management.h:397
void switchToShared()
Switch ObjectsHolder pointer's collection to Shared mode and clean postponed holders list.
Definition: memory_management.h:415
PostponedHolders(const System::SharedPtr< System::Object > &key)
Definition: memory_management.h:402
~PostponedHolders()
Definition: memory_management.h:408
Defines a methods that changes the lifetime of objects.
Definition: memory_management.h:87
System::Details::ObjectsBag ObjectsBag
Highly optimized container designed to extend objects lifetime.
Definition: memory_management.h:90
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 ...
Definition: memory_management.h:190
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
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 ...
Definition: memory_management.h:326
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
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
void set_Mode(SmartPtrMode mode)
Sets pointer mode. May alter referenced object's reference counts.
Definition: smart_ptr.h:664
Pointee_ * get() const
Gets pointed object.
Definition: smart_ptr.h:518
Definition: iobjects_holder.h:10
SmartPtrMode
SmartPtr pointer type: weak or shared. Defines whether pointer is being counted when it is being deci...
Definition: smart_ptr.h:68
@ Weak
Weak mode: pointer does not participate in reference counting.
@ Shared
Shared mode: pointer participates in reference counting.
Trait class to check if a type is a specialization of SmartPtr class.
Definition: smart_ptr.h:1499