2#ifndef _aspose_system_smart_ptr_h_
3#define _aspose_system_smart_ptr_h_
6#include "smart_ptr_counter.h"
8#include "select_type.h"
10#include <system/details/makeobject_leakage_detector.h>
13#include <system/diagnostics/debug.h>
22template <
typename T>
class ASPOSECPP_SHARED_CLASS
Array;
25#if defined(__DBG_TOOLS)
27 struct for_each_member_visitor;
36 template <
typename T>
struct ArrayTypeResolver
41 using value_type = void;
45 template <
typename T>
struct ArrayTypeResolver<
Array<T>>
48 using type = Array<T>;
59 template <
typename X,
typename IdxType>
typename Array<X>::UnderlyingType& GetByIndex(
const SmartPtr<Array<X>> *ptr, IdxType idx);
63 template <
typename T> Array<T>* CreateArray(Array<T>*);
76struct EmptyArrayInitializer {};
187 typedef typename System::Details::ArrayTypeResolver<T>::type
ArrayType;
189 using ValueType =
typename System::Details::SelectType<typename System::Details::ArrayTypeResolver<T>::value_type>::type;
224 template<class Q, typename = typename std::enable_if<System::detail::is_pointer_convertible<Q, Pointee_>::type::value>::type>
236 if (m_data.GetMode() == x.m_data.GetMode())
239 m_data.swapPointers(x.m_data);
244 MoveSharedFromWeak(std::move(x));
246 MoveWeakFromShared(std::move(x));
253 template <
typename Y>
257 InitArray(
this, src);
261 template <typename Y, typename = typename std::enable_if<std::is_same<Y, EmptyArrayInitializer>::value,
void>::type>
264 Lock(Details::CreateArray((
Pointee_*)
nullptr));
326 template <
typename P>
330 if (ptr ==
nullptr || p ==
nullptr)
335 m_data.WeakSetPointer(
341 m_data.WeakSetPointer(
344#ifdef ENABLE_EXTERNAL_REFCOUNT
345 , ptr.
m_data.SharedGetCounter()->WeakRefAdded()
354 m_data.SharedSetPointer(
358#ifdef ENABLE_EXTERNAL_REFCOUNT
363 m_data.SharedSetPointer(
367#ifdef ENABLE_EXTERNAL_REFCOUNT
368 , ptr.
m_data.SharedGetCounter()
376 delete ReleaseAndGetObjectToDelete();
383 Pointee_ *
const this_pointee = m_data.GetPointee();
386 if (this_pointee ==
nullptr)
388 if (other_pointee ==
nullptr)
394 m_data.swapPointers(x.m_data);
396 MoveWeakFromShared(std::move(x));
400 if (x.m_data.WeakGetCounter()->GetObject() ==
nullptr)
403 m_data.swapPointers(x.m_data);
405 MoveSharedFromWeak(std::move(x));
410 if (other_pointee ==
nullptr)
413 delete ReleaseSharedAndGetObjectToDelete();
422 if (this_pointee != other_pointee || m_data.SharedGetOwned() != x.m_data.SharedGetOwned())
423 m_data.swapPointers(x.m_data);
427 System::Detail::SmartPtrCounter *
const releaser = m_data.WeakGetCounter();
428 if (this_pointee != other_pointee || releaser->GetObject() != x.m_data.SharedGetOwned())
430 MoveWeakFromShared(std::move(x));
431 ReleaseWeak(releaser);
437 System::Detail::SmartPtrCounter *
const other_counter = x.m_data.WeakGetCounter();
438 if (other_counter->GetObject() ==
nullptr)
441 delete ReleaseSharedAndGetObjectToDelete();
448 if (this_pointee != other_pointee || m_data.WeakGetCounter() != other_counter)
449 m_data.swapPointers(x.m_data);
453 if (this_pointee != other_pointee || m_data.SharedGetOwned() != other_counter->GetObject())
456 MoveSharedFromWeak(std::move(x));
457 delete ReleaseSharedAndGetObjectToDelete(releaser);
477 template <
typename Q>
488 if (GetPointer() != p)
491 m_data.swapPointers(temp.
m_data);
499 delete ReleaseAndGetObjectToDelete();
508 return GetObjectNotNull();
514 return m_data.IsNull();
520 return m_data.GetPointee();
526 return m_data.SharedGetPointee();
532 delete ReleaseAndGetObjectToDelete();
538 delete ReleaseAndGetObjectToDelete();
545 return m_data.GetMode();
563 Object* pointee =
nullptr;
567 pointee = m_data.SharedGetObject();
568 owner = m_data.SharedGetOwned();
572 pointee = m_data.WeakGetObject();
573 System::Detail::SmartPtrCounter* counter = m_data.WeakGetCounterOrNull();
574 owner = counter ==
nullptr ? nullptr : counter->GetObject();
576 return pointee != owner;
585 owner = m_data.SharedGetOwned();
589 System::Detail::SmartPtrCounter* counter = m_data.WeakGetCounterOrNull();
591 owner = counter->GetObject();
666 if (m_data.GetMode() == mode)
675 return *GetObjectNotNull();
679 explicit operator bool() const noexcept
681 return *
this !=
nullptr;
685 bool operator !() const noexcept
687 return *
this ==
nullptr;
696 return GetObjectOrNull() < p;
711 return Pointee_::Type();
741 template<
class Y,
typename Check = std::false_type>
750 template <
class Y,
typename Check = std::false_type>
751 std::enable_if_t<!std::is_same<Y, T>::value && std::is_base_of<Y, T>::value,
SmartPtr<Y>>
Cast()
const
759 template <
class Y,
typename Check = std::false_type>
760 std::enable_if_t<Check::value && !std::is_same<Y, T>::value && !std::is_base_of<Y, T>::value,
SmartPtr<Y>>
Cast()
const
762 auto result = m_data.IsNull() ?
SmartPtr<Y>() :
SmartPtr<Y>(*
this,
dynamic_cast<Y*
>(m_data.GetPointee()));
763 if ((*
this) && !result)
764 System::Detail::SmartPtrCounter::ThrowInvalidCastException();
772 template <
class Y,
typename Check = std::false_type>
773 std::enable_if_t<!Check::value && !std::is_same<Y, T>::value && !std::is_base_of<Y, T>::value,
SmartPtr<Y>>
Cast()
const
788 return m_data.SharedGetObject();
790 return m_data.WeakGetObject();
799 return m_data.GetPointee();
805 if (m_data.SharedGetPointee() ==
nullptr)
808#ifdef ENABLE_EXTERNAL_REFCOUNT
809 return m_data.SharedGetCounter()->SharedCount();
811 return m_data.SharedGetOwned()->SharedCount();
816 void SetContainedTemplateWeakPtr(uint32_t argument)
const;
821 template <
typename IdxType>
822 decltype(System::Details::GetByIndex(std::declval<const SmartPtr_*>(), std::declval<IdxType>()))
operator[] (IdxType idx)
const
824 return System::Details::GetByIndex(
this, idx);
830 template <
typename Q = T>
auto begin() ->
decltype(std::declval<Q>().begin())
832 return GetObjectNotNull()->begin();
838 template <
typename Q = T>
auto end() ->
decltype(std::declval<Q>().end())
840 return GetObjectNotNull()->end();
846 template <
typename Q = T>
auto begin() const -> decltype(std::declval<const Q>().begin())
848 return GetObjectNotNull()->begin();
854 template <
typename Q = T>
auto end() const -> decltype(std::declval<const Q>().end())
856 return GetObjectNotNull()->end();
862 template <
typename Q = T>
auto cbegin() const -> decltype(std::declval<const Q>().cbegin())
864 return GetObjectNotNull()->cbegin();
870 template <
typename Q = T>
auto cend() const -> decltype(std::declval<const Q>().cend())
872 return GetObjectNotNull()->cend();
879 return GetHashCodeImpl(
static_cast<Pointee_*
>(
nullptr));
888 System::Detail::SmartPtrCounter::ThrowNullReferenceException();
889 return m_data.GetPointee();
895 friend class System::Details::ObjectsBag;
896#if defined(__DBG_TOOLS)
897 friend struct DBG::for_each_member_visitor;
903 if (
object ==
nullptr)
908#ifdef ENABLE_EXTERNAL_REFCOUNT
909 m_data.SharedSetPointer(
object,
object->Object::SharedRefAdded(),
object->Object::GetCounter());
911 m_data.SharedSetPointer(
object,
object->Object::SharedRefAdded());
928 LockWeakFromWeak(ptr);
930 LockWeakFromShared(ptr);
935 LockSharedFromWeak(ptr);
937 LockSharedFromShared(ptr);
943 template <
typename Q>
946 m_data.SharedSetPointer(
950#ifdef ENABLE_EXTERNAL_REFCOUNT
951 , ptr.
m_data.SharedGetCounter()
958 template <
typename Q>
961 m_data.SharedSetPointer(
965#ifdef ENABLE_EXTERNAL_REFCOUNT
973 template <
typename Q>
976 m_data.WeakSetPointer(
979#ifdef ENABLE_EXTERNAL_REFCOUNT
989 template <
typename Q>
992 m_data.WeakSetPointer(
1001 if (m_data.HoldsReference())
1004 return ReleaseSharedAndGetObjectToDelete();
1010#ifdef ENABLE_EXTERNAL_REFCOUNT
1012 typedef System::Detail::SmartPtrCounter SharedRefReleaser;
1015 SharedRefReleaser* GetSharedReleaser()
const
1017 return m_data.SharedGetCounter();
1026 return m_data.SharedGetOwned();
1031 static Object* ReleaseSharedAndGetObjectToDelete(SharedRefReleaser *releaser);
1035 return ReleaseSharedAndGetObjectToDelete(GetSharedReleaser());
1041 counter->WeakRefRemoved();
1046 m_data.WeakGetCounter()->WeakRefRemoved();
1052 if (x.m_data.IsNull())
1056 m_data.SharedSetPointer(
1057 x.m_data.WeakGetPointee()
1058 , x.m_data.WeakGetCounter()->Lock()
1059#ifdef ENABLE_EXTERNAL_REFCOUNT
1060 , x.m_data.WeakGetCounter()
1071 if (x.m_data.IsNull())
1075 m_data.WeakSetPointer(
1076 x.m_data.SharedGetPointee()
1077 , x.m_data.SharedGetObject()
1078#ifdef ENABLE_EXTERNAL_REFCOUNT
1079 , x.m_data.SharedGetCounter()->WeakRefAdded()
1081 , x.m_data.SharedGetOwned()->WeakRefAdded()
1084 delete x.ReleaseSharedAndGetObjectToDelete();
1093 template <
typename X,
typename Y>
1096 T *
const destination =
new T(src->get_Length());
1097 ptr->Lock(destination);
1098 std::copy(src->data().begin(), src->data().end(), destination->data().begin());
1103 template <typename Q, typename R = decltype(std::declval<Q*>()->GetHashCode())>
1106 if (m_data.IsNull())
1109 return GetPointer()->GetHashCode();
1114 if (m_data.IsNull())
1117 return m_data.SharedGetObject()->GetHashCode();
1119 return m_data.WeakGetCounter()->GetObject()->GetHashCode();
1124 template <
typename Q>
1127 Pointee_ *
const this_pointee = m_data.GetPointee();
1130 if (this_pointee ==
nullptr)
1132 if (other_pointee ==
nullptr)
1137 LockSharedFromShared(x);
1139 LockWeakFromShared(x);
1146 LockSharedFromWeak(x);
1148 LockWeakFromWeak(x);
1153 if (other_pointee ==
nullptr)
1156 delete ReleaseSharedAndGetObjectToDelete();
1166 LockSharedFromShared(x);
1167 delete ReleaseSharedAndGetObjectToDelete(releaser);
1172 if (this_pointee != other_pointee || m_data.WeakGetCounter()->GetObject() != x.
m_data.
SharedGetOwned())
1175 LockWeakFromShared(x);
1181 if (other_pointee ==
nullptr)
1184 delete ReleaseSharedAndGetObjectToDelete();
1192 if (other_owned ==
nullptr)
1195 delete ReleaseSharedAndGetObjectToDelete();
1202 if (this_pointee != other_pointee || m_data.SharedGetOwned() != other_owned)
1204 delete ReleaseSharedAndGetObjectToDelete();
1205 LockSharedFromWeak(x);
1212 System::Detail::SmartPtrCounter *
const releaser = m_data.WeakGetCounter();
1213 LockWeakFromWeak(x);
1214 ReleaseWeak(releaser);
1227#ifdef ENABLE_EXTERNAL_REFCOUNT
1231 System::Detail::SmartPtrCounter *m_counter;
1273 else if (m_pointee ==
nullptr)
1275 else if (m_counter->GetObject() ==
nullptr)
1284 return m_pointee ==
nullptr || (m_mode ==
SmartPtrMode::Weak && m_counter->GetObject() ==
nullptr);
1289 m_pointee =
nullptr;
1295 return m_pointee !=
nullptr;
1316 return IsNull() ? nullptr : m_counter;
1325 m_pointee = pointee;
1327 m_counter = counter;
1362 return IsNull() ? nullptr : m_object;
1369 return IsNull() ? nullptr : m_owned;
1371#ifdef ENABLE_EXTERNAL_REFCOUNT
1374 System::Detail::SmartPtrCounter* SharedGetCounter()
const
1381 System::Detail::SmartPtrCounter** SharedGetCounterPointer()
1388 System::Detail::SmartPtrCounter* SharedGetCounterOrNull()
const
1391 return IsNull() ? nullptr : m_counter;
1398 void SharedSetPointer(Pointee_ *pointee, Object *
object, Object *owned, System::Detail::SmartPtrCounter *counter)
1401 m_pointee = pointee;
1404 m_counter = counter;
1410 void SharedSetPointer(Pointee_ *pointee, Object *
object, System::Detail::SmartPtrCounter *counter)
1413 m_pointee = pointee;
1416 m_counter = counter;
1426 m_pointee = pointee;
1436 m_pointee = pointee;
1445 std::swap(m_mode, data.m_mode);
1452 std::swap(m_pointee, data.m_pointee);
1453 std::swap(m_object, data.m_object);
1454 std::swap(m_owned, data.m_owned);
1455#ifdef ENABLE_EXTERNAL_REFCOUNT
1456 std::swap(m_counter, data.m_counter);
1466#ifdef ENABLE_EXTERNAL_REFCOUNT
1474 SmartPtrCounter::NextOwnership() = SmartPtrCounter::BeingConstructed;
1479 template <
typename T>
1480 void CreatedSuccessfully(T *
object) {
1481 object->Object::GetCounter()->CreatedSuccessfully();
1491 template <
typename T>
1492 void CreatedSuccessfully(T *) {}
1505template<
class T,
class ...Args>
1508 System::Details::MakeObjectLeakageDetector::SignatureBacktraceSentry signature_sentry;
1509 System::Details::MakeObjectLeakageDetector::SetSignature<T>(std::forward<Args>(args)...);
1511 System::Detail::OwnNextObject ownershipSentry;
1513 T *
const object = ::new T(std::forward<Args>(args)...);
1515 ownershipSentry.CreatedSuccessfully(
object);
1516 signature_sentry.CreatedSuccessfully(
object);
1525template<
class T,
class ...Args>
1526typename std::enable_if<IsSmartPtr<T>::value, T>::type
MakeObject(Args&&... args)
1528 return MakeObject<typename T::Pointee_>(std::forward<Args>(args)...);
1536template<
class X,
class Y>
1547template<
class X,
class Y>
1559 return x ==
nullptr;
1568 return !(x ==
nullptr);
1577 return !(x ==
nullptr);
1585template<
class X,
class Y>
1586typename std::enable_if<std::is_base_of<Object, Y>::value && detail::has_no_operator_equal<X,Y>::value,
bool>::type
1597template<
class X,
class Y>
1598typename std::enable_if<std::is_base_of<Object, Y>::value && detail::has_no_operator_equal<X,Y>::value,
bool>::type
1609template<
class X,
class Y>
1610typename std::enable_if<std::is_base_of<Object, X>::value && detail::has_no_operator_equal<X,Y>::value,
bool>::type
1621template<
class X,
class Y>
1622typename std::enable_if<std::is_base_of<Object, X>::value && detail::has_no_operator_equal<X,Y>::value,
bool>::type
1668template<
class Y,
class X>
1671 return x.template static_pointer_cast<Y>();
1678template<
class Y,
class X>
1681 return x.template dynamic_pointer_cast<Y>();
1689template<
class Y,
class X>
1692 return x.template const_pointer_cast<Y>();
1703 , m_internal_pointer(nullptr)
1708 template <
typename T>
1710 : m_object(ptr.IsShared() ? ptr.m_data.SharedGetObject() : nullptr)
1711 , m_owned(ptr.IsShared() ? ptr.m_data.SharedGetOwned() : nullptr)
1712 , m_internal_pointer(ptr.IsShared() ? ptr.m_data.GetPointee() : nullptr)
1716 inline operator bool()
const
1718 return m_internal_pointer !=
nullptr;
1724 return m_object ==
nullptr;
1737 return m_internal_pointer < other.m_internal_pointer;
1755 return m_internal_pointer;
1763 void *m_internal_pointer;
1784template <
typename T>
1793template <
typename T>
1794struct BasePointerType
1802template <
typename T>
1803std::enable_if_t<detail::has_print_to_function<T>::value,
void>
PrintTo(
const SmartPtr<T>& object_ptr, std::ostream* stream)
1805 if (object_ptr ==
nullptr)
1806 *stream <<
"nullptr";
1812template <
typename T>
1813std::enable_if_t<!detail::has_print_to_function<T>::value,
void>
PrintTo(
const SmartPtr<T>& object_ptr, std::ostream* stream)
1815 if (object_ptr ==
nullptr)
1816 *stream <<
"nullptr";
1825template <
typename T>
1828 if (object_ptr !=
nullptr)
1829 stream << object_ptr->ToString();
1837template <
typename T>
1840 if (object_ptr !=
nullptr)
1841 stream << object_ptr->ToString();
1847#define CODEPORTING_ARGS(...) __VA_ARGS__
1849#define MEMBER_FUNCTION_MAKE_OBJECT(name, args_with_types, args) \
1851static System::SmartPtr<name> MakeObject(args_with_types) \
1853 System::Details::MakeObjectLeakageDetector::SignatureBacktraceSentry signature_sentry; \
1854 System::Details::MakeObjectLeakageDetector::SetSignature<name>(args); \
1856 System::Detail::OwnNextObject ownershipSentry; \
1858 name *const object = ::new name(args); \
1860 ownershipSentry.CreatedSuccessfully(object); \
1861 signature_sentry.CreatedSuccessfully(object); \
1863 return System::SmartPtr<name>(object); \
1866#define MEMBER_FUNCTION_MAKE_OBJECT_DECLARATION(name, args_with_types) \
1867static System::SmartPtr<name> MakeObject(args_with_types);
1869#define MEMBER_FUNCTION_MAKE_OBJECT_DEFINITION(name, args_with_types, args) \
1870System::SmartPtr<name> name::MakeObject(args_with_types) \
1872 System::Details::MakeObjectLeakageDetector::SignatureBacktraceSentry signature_sentry; \
1873 System::Details::MakeObjectLeakageDetector::SetSignature<name>(args); \
1875 System::Detail::OwnNextObject ownershipSentry; \
1877 name *const object = ::new name(args); \
1879 ownershipSentry.CreatedSuccessfully(object); \
1880 signature_sentry.CreatedSuccessfully(object); \
1882 return System::SmartPtr<name>(object); \
1895 using result_type = std::size_t;
Class that represents an array data structure. Objects of this class should only be allocated using S...
Definition: array.h:259
typename System::Details::SelectType< T >::type UnderlyingType
Alias for the type used to represent each element of the array.
Definition: array.h:270
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
Object * SharedRefAdded()
Increments shared reference count. Shouldn't be called directly; instead, use smart pointers or ThisP...
Definition: object.h:297
Detail::SmartPtrCounter * WeakRefAdded()
Increments weak reference count. Shouldn't be called directly; instead, use smart pointers or ThisPro...
Definition: object.h:328
Internal data storage class which hides data members and enforces neccessary asserts around them.
Definition: smart_ptr.h:1220
void SetNull()
Sets pointer to null.
Definition: smart_ptr.h:1287
Object * WeakGetObject() const
Gets referenced object which is cast to System::Object. Asserts that pointer is weak....
Definition: smart_ptr.h:1345
T * GetComparable() const
Gets pointed object (if set and not yet deleted) or nullptr.
Definition: smart_ptr.h:1269
void SharedSetPointer(Pointee_ *pointee, Object *object, Object *owned)
Sets pointer value. Asserts that pointer is shared.
Definition: smart_ptr.h:1423
Object * SharedGetObjectOrNull() const
Gets referenced object (if any) which is cast to System::Object or null. Asserts that pointer is shar...
Definition: smart_ptr.h:1359
void swapPointers(Data &data) noexcept
Swaps pointer data of two Data instances, excluding modes.
Definition: smart_ptr.h:1450
Data(const Data &)=delete
void SharedSetPointer(Pointee_ *pointee, Object *object)
Sets pointer value. Asserts that pointer is shared.
Definition: smart_ptr.h:1433
System::Detail::SmartPtrCounter * WeakGetCounterOrNull() const
Gets referenced object (if any) reference counter or null. Asserts that pointer is weak.
Definition: smart_ptr.h:1313
T * GetPointee() const
Gets pointed object (if any) or nullptr.
Definition: smart_ptr.h:1263
Data(SmartPtrMode mode)
Initializes Data structure. Doesn't set any members except for m_mode.
Definition: smart_ptr.h:1242
Object * SharedGetOwnedOrNull() const
Gets owned object. Asserts that pointer is shared.
Definition: smart_ptr.h:1366
Object * SharedGetOwned() const
Gets owned object which. Asserts that pointer is shared. Doesn't null-check.
Definition: smart_ptr.h:1352
Pointee_ * WeakGetPointee() const
Gets referenced object. Asserts that pointer is weak.
Definition: smart_ptr.h:1299
System::Detail::SmartPtrCounter * WeakGetCounter() const
Gets referenced object reference counter. Asserts that pointer is weak. Doesn't null-check.
Definition: smart_ptr.h:1306
System::Detail::SmartPtrCounter * m_counter
Reference counter structure linked to m_pointee.
Definition: smart_ptr.h:1237
Object * m_owned
Owned pointer.
Definition: smart_ptr.h:1235
bool IsNull() const
Checks if referenced object is set and not yet deleted.
Definition: smart_ptr.h:1282
void WeakSetPointer(Pointee_ *pointee, Object *object, System::Detail::SmartPtrCounter *counter)
Sets pointer value. Asserts that pointer is weak.
Definition: smart_ptr.h:1322
void SetMode(SmartPtrMode mode)
Sets pointer mode. Doesn't do any reference count or pointer changes.
Definition: smart_ptr.h:1257
bool HoldsReference() const
Checks if pointer actually holds a shared or weak reference to an object.
Definition: smart_ptr.h:1293
void swap(Data &data) noexcept
Swaps data of two Data instances, including modes and pointers.
Definition: smart_ptr.h:1443
SmartPtrMode GetMode() const
Gets current pointer mode.
Definition: smart_ptr.h:1251
Pointee_ * SharedGetPointee() const
Gets referenced object. Asserts that pointer is shared.
Definition: smart_ptr.h:1331
Object * SharedGetObject() const
Gets referenced object which is cast to System::Object. Asserts that pointer is shared....
Definition: smart_ptr.h:1338
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
int GetHashCode() const
Calls GetHashCode() on pointed object.
Definition: smart_ptr.h:877
void LockSharedFromShared(const SmartPtr< Q > &ptr)
Sets pointee object. Asserts that both current object and ptr are in shared mode.
Definition: smart_ptr.h:944
SmartPtr(const SmartPtr< P > &ptr, Pointee_ *p, SmartPtrMode mode=SmartPtrMode::Shared)
Constructs a SmartPtr which shares ownership information with the initial value of ptr,...
Definition: smart_ptr.h:327
auto end() -> decltype(std::declval< Q >().end())
Accessor for end() method of an underling collection. Only compiles if SmartPtr_ is specialization ty...
Definition: smart_ptr.h:838
SmartPtr< T > SmartPtr_
Specialized smart pointer type.
Definition: smart_ptr.h:185
SmartPtr(std::nullptr_t=nullptr, SmartPtrMode mode=SmartPtrMode::Shared)
Creates null-pointer SmartPtr object of required mode.
Definition: smart_ptr.h:199
SmartPtr(const SmartPtr< Array< Y > > &src, SmartPtrMode mode=SmartPtrMode::Shared)
Converts type of referenced array by creating a new array of different type. Useful if in C# there is...
Definition: smart_ptr.h:254
Pointee_ * GetPointer() const
Gets pointed object (if any) or nullptr. Same as get().
Definition: smart_ptr.h:797
void ReleaseWeak()
Decrements currently referenced object's weak pointer counter.
Definition: smart_ptr.h:1044
SmartPtr(SmartPtrMode mode)
Creates SmartPtr object of required mode.
Definition: smart_ptr.h:192
Object * ReleaseAndGetObjectToDelete()
Decrements currently referenced object's shared or weak pointer counter, depending on current pointer...
Definition: smart_ptr.h:999
void set_Mode(SmartPtrMode mode)
Sets pointer mode. May alter referenced object's reference counts.
Definition: smart_ptr.h:664
typename System::Details::SelectType< typename System::Details::ArrayTypeResolver< T >::value_type >::type ValueType
Storage type of pointed array. Only meaningful if T is a specialization of System::Array.
Definition: smart_ptr.h:189
Pointee_ * get() const
Gets pointed object.
Definition: smart_ptr.h:518
auto cend() const -> decltype(std::declval< const Q >().cend())
Accessor for cend() method of an underling collection. Only compiles if SmartPtr_ is specialization t...
Definition: smart_ptr.h:870
SmartPtr(const Y &)
Initializes empty array. Used to translate some C# code constructs.
Definition: smart_ptr.h:262
SmartPtr(const SmartPtr< Q > &x, SmartPtrMode mode=SmartPtrMode::Shared)
Copy constructs SmartPtr object. Both pointers point to the same object afterwards....
Definition: smart_ptr.h:225
SmartPtr< Y > dynamic_pointer_cast() const
Casts pointer to different type using dynamic_cast on pointed object.
Definition: smart_ptr.h:725
std::enable_if_t< std::is_same< Y, T >::value, SmartPtr< Y > > Cast() const
Casts pointer to its type itself.
Definition: smart_ptr.h:742
void Lock(Pointee_ *object)
Sets pointee object. Increments shared or weak reference count, depending on pointer mode.
Definition: smart_ptr.h:901
void LockSharedFromWeak(const SmartPtr< Q > &ptr)
Sets pointee object. Asserts that current object is in shared mode and ptr is in weak mode.
Definition: smart_ptr.h:959
bool IsShared() const
Checks if pointer is in shared mode.
Definition: smart_ptr.h:549
Object SharedRefReleaser
Type to use to release shared pointers. Depends on whether external refcount is on or off.
Definition: smart_ptr.h:1021
static void InitArray(SmartPtr< Array< X > > *ptr, const SmartPtr< Array< Y > > &src)
Performs actual array copying on cast constructor calls.
Definition: smart_ptr.h:1094
SmartPtr< Y > static_pointer_cast() const
Casts pointer to different type using static_cast on pointed object.
Definition: smart_ptr.h:717
auto begin() -> decltype(std::declval< Q >().begin())
Accessor for begin() method of an underling collection. Only compiles if SmartPtr_ is specialization ...
Definition: smart_ptr.h:830
~SmartPtr()
Destroys SmartPtr object. If required, decreases pointed object's reference counter and deletes objec...
Definition: smart_ptr.h:374
bool IsWeak() const
Checks if pointer is in weak mode.
Definition: smart_ptr.h:555
SmartPtr_ RemoveAliasing() const
Removes aliasing (created by an aliasing constructor) from pointer, makes sure it manages (if shared)...
Definition: smart_ptr.h:601
SmartPtr(Pointee_ *object, SmartPtrMode mode=SmartPtrMode::Shared)
Creates SmartPtr pointing to specified object, or converts raw pointer to SmartPtr.
Definition: smart_ptr.h:207
Object * GetObjectOrNull() const
Gets pointed object (if any) or nullptr. Same as get().
Definition: smart_ptr.h:783
void MoveWeakFromShared(SmartPtr &&x)
Implements move semantics. Asserts that current object is in weak mode and x is in shared mode.
Definition: smart_ptr.h:1069
void Lock(const SmartPtr< Q > &ptr)
Sets pointee object. Increments shared or weak reference count, depending on pointer mode.
Definition: smart_ptr.h:921
SharedRefReleaser * GetSharedReleaser() const
Gets object to use to release shared pointer to.
Definition: smart_ptr.h:1024
void reset()
Makes pointer pointing to nullptr.
Definition: smart_ptr.h:536
System::Details::ArrayTypeResolver< T >::type ArrayType
Same as Pointee_, if it is a specialization of System::Array, and void otherwise.
Definition: smart_ptr.h:187
std::enable_if_t<!std::is_same< Y, T >::value &&std::is_base_of< Y, T >::value, SmartPtr< Y > > Cast() const
Casts pointer to base type using static_cast.
Definition: smart_ptr.h:751
void reset(Pointee_ *ptr)
Sets pointed object.
Definition: smart_ptr.h:530
int get_shared_count() const
Gets number of shared pointers existing to referenced object, including current one....
Definition: smart_ptr.h:803
std::enable_if_t<!Check::value &&!std::is_same< Y, T >::value &&!std::is_base_of< Y, T >::value, SmartPtr< Y > > Cast() const
Casts pointer to derived type dynamic_cast.
Definition: smart_ptr.h:773
SmartPtr(SmartPtr_ &&x, SmartPtrMode mode=SmartPtrMode::Shared) noexcept
Move constructs SmartPtr object. Effectively, swaps two pointers, if they are both of same mode....
Definition: smart_ptr.h:233
SmartPtr< Y > const_pointer_cast() const
Casts pointer to different type using const_cast on pointed object.
Definition: smart_ptr.h:733
int GetHashCodeImpl(void *) const
Calls GetHashCode() method from Object if it is not available on Pointee_ type (e....
Definition: smart_ptr.h:1112
SmartPtr(const SmartPtr_ &ptr, SmartPtrMode mode=SmartPtrMode::Shared)
Copy constructs SmartPtr object. Both pointers point to the same object afterwards.
Definition: smart_ptr.h:215
SmartPtrMode get_Mode() const
Gets pointer mode.
Definition: smart_ptr.h:543
T * GetObjectNotNull() const
Gets currently referenced object (if any) or throws.
Definition: smart_ptr.h:885
void MoveSharedFromWeak(SmartPtr &&x)
Implements move semantics. Asserts that current object is in shared mode and x is in weak mode.
Definition: smart_ptr.h:1050
void Assign(const SmartPtr< Q > &x)
Copy-assigns SmartPtr object. Does type conversions, if required.
Definition: smart_ptr.h:1125
static const System::TypeInfo & Type()
Shortcut to get System::TypeInfo object for the Pointee_ type.
Definition: smart_ptr.h:709
Pointee_ * get_shared() const
Gets pointed object, but asserts that pointer is in shared mode.
Definition: smart_ptr.h:524
void LockWeakFromShared(const SmartPtr< Q > &ptr)
Sets pointee object. Asserts that current object is in weak mode and ptr is in shared mode.
Definition: smart_ptr.h:974
class System::SmartPtr::Data m_data
An instance of Data class.
auto end() const -> decltype(std::declval< const Q >().end())
Accessor for end() method of an underling collection. Only compiles if SmartPtr_ is specialization ty...
Definition: smart_ptr.h:854
Object * GetObjectOwner() const
Gets referenced object.
Definition: smart_ptr.h:580
bool IsAliasingPtr() const
Checks if pointer is pointed to another object than owned (created by an aliasing constructor).
Definition: smart_ptr.h:561
static void ReleaseWeak(System::Detail::SmartPtrCounter *counter)
Decrements weak pointer counter.
Definition: smart_ptr.h:1039
auto begin() const -> decltype(std::declval< const Q >().begin())
Accessor for begin() method of an underling collection. Only compiles if SmartPtr_ is specialization ...
Definition: smart_ptr.h:846
T Pointee_
Pointed type.
Definition: smart_ptr.h:183
auto cbegin() const -> decltype(std::declval< const Q >().cbegin())
Accessor for cbegin() method of an underling collection. Only compiles if SmartPtr_ is specialization...
Definition: smart_ptr.h:862
std::enable_if_t< Check::value &&!std::is_same< Y, T >::value &&!std::is_base_of< Y, T >::value, SmartPtr< Y > > Cast() const
Casts pointer to derived type dynamic_cast.
Definition: smart_ptr.h:760
void LockWeakFromWeak(const SmartPtr< Q > &ptr)
Sets pointee object. Asserts that both current object and ptr are in weak mode.
Definition: smart_ptr.h:990
R GetHashCodeImpl(Q *) const
Calls into GetHashCode() method if it is available on Pointee_ type (which is true if it is a complet...
Definition: smart_ptr.h:1104
Object * ReleaseSharedAndGetObjectToDelete()
Decrements currently referenced object's shared pointer counter.
Definition: smart_ptr.h:1033
Service class to test and alter SmartPtr's contents without knowing final type. Used for garbage coll...
Definition: smart_ptr.h:1697
Object * getObject() const
Gets object referenced pointer points to.
Definition: smart_ptr.h:1741
bool operator!() const
Checks if info object does not point to non-null pointer.
Definition: smart_ptr.h:1722
bool operator<(const SmartPtrInfo &other) const
Less-compares values of pointers referenced by two info objects.
Definition: smart_ptr.h:1735
SmartPtrInfo(const SmartPtr< T > &ptr)
Creates SmartPtrInfo object with information on specific smart pointer.
Definition: smart_ptr.h:1709
Object * operator->() const
Allows to call methods of Object pointed by the referenced pointer.
Definition: smart_ptr.h:1728
SmartPtrInfo()
Creates empty SmartPtrInfo object.
Definition: smart_ptr.h:1700
const void * getInternalPtr() const
Gets raw object referenced pointer points to.
Definition: smart_ptr.h:1753
Object * getOwned() const
Gets object owned pointer.
Definition: smart_ptr.h:1747
Represents a particular type and provides information about it.
Definition: type_info.h:109
@ TypeInfo
Specifies that the member is a type.
Definition: db_command.h:9
void PrintTo(DateTime value, std::ostream *stream)
Prints value to ostream. Mostly used for debug.
bool operator!=(ArraySegment< T > a, ArraySegment< T > b)
Definition: array_segment.h:157
SmartPtr< Y > static_pointer_cast(SmartPtr< X > const &x)
Casts smart pointers using static_cast.
Definition: smart_ptr.h:1669
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.
SmartPtr< X > MakeSharedPtr(X *p)
Converts raw pointer to smart pointer.
Definition: smart_ptr.h:1650
SmartPtr< Y > const_pointer_cast(SmartPtr< X > const &x)
Casts smart pointers using const_cast.
Definition: smart_ptr.h:1690
std::enable_if<!IsSmartPtr< T >::value, SmartPtr< T > >::type MakeObject(Args &&... args)
Creates object on heap and returns shared pointer to it.
Definition: smart_ptr.h:1506
SmartPtr< T > SharedPtr
Alias for smart pointer widely used in the library.
Definition: smart_ptr.h:1779
decltype(Ref(std::declval< T & >())) Ref(const std::reference_wrapper< T > &wrapper)
Wrapper to make sure Ref(std::ref(DynamicWeakPtr)) works.
Definition: dynamic_weak_ptr.h:207
SmartPtr< Y > dynamic_pointer_cast(SmartPtr< X > const &x)
Casts smart pointers using dynamic_cast.
Definition: smart_ptr.h:1679
Decimal operator*(const T &x, const Decimal &d)
Returns a new instance of Decimal class that represents a value that is a result of multiplication of...
Definition: decimal.h:556
class ASPOSECPP_SHARED_CLASS Array
Definition: smart_ptr.h:22
T * get_pointer(System::SmartPtr< T > const &x)
Gets referenced object of smart pointer.
Definition: smart_ptr.h:1770
std::ostream & operator<<(std::ostream &stream, DateTime date_time)
Insert data into the stream using UTF-8 encoding.
Definition: date_time.h:729
constexpr bool operator<(std::nullptr_t, DateTime)
Definition: date_time.h:712
bool operator==(ArraySegment< T > a, ArraySegment< T > b)
Definition: array_segment.h:151
Trait class to check if a type is a specialization of SmartPtr class.
Definition: smart_ptr.h:1499
Performs cheapest cast possible from static_cast and dynamic_cast.
Definition: detail.h:34
Checks whether IsNull method exists. If so, inherits std::true_type, otherwise inherits std::false_ty...
Definition: detail.h:246
Tests if specific type is a specialization of specific template. If it is, inherits std::true_type,...
Definition: detail.h:80