CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
object.h
1
2#pragma once
3
4#include <defines.h>
5
6#include <system/type_info.h>
7#include <system/reflection.h>
8#include <system/smart_ptr.h>
9#include <system/weak_ptr.h>
10#include <system/dynamic_weak_ptr.h>
11#include <system/refcount.h>
12
13#include <system/cycles_detection.h>
14#include <system/details/dbg_tools.h>
15#include <system/details/dbg_garbage_collection.h>
16#include <system/details/leakage_detector.h>
17#include <system/details/lock_context.h>
18
19#include <type_traits>
20#include <string>
21#include <list>
22#include <utility>
23#include <map>
24#include <memory>
25#include <cmath>
26#include <mutex>
27
28namespace System
29{
30
31class String;
32class Details_Exception;
33
50class ASPOSECPP_SHARED_CLASS Object
51{
52public:
55#ifdef ASPOSE_GET_SHARED_MEMBERS
57 typedef System::Details::SharedMembersType shared_members_type;
58#endif
60 ASPOSECPP_SHARED_API Object();
62 virtual ASPOSECPP_SHARED_API ~Object();
63
64 // the following 2 members needed for MemberwiseClone()
67 ASPOSECPP_SHARED_API Object(Object const& x);
70 Object& operator = (Object const& x){ ASPOSE_UNUSED(x); return *this; } // does nothing
73 Object* SharedRefAdded();
76 int SharedRefRemovedSafe();
80 int RemovedSharedRefs(int count);
83 Detail::SmartPtrCounter* WeakRefAdded();
85 void WeakRefRemoved();
88 inline Detail::SmartPtrCounter* GetCounter();
91 int SharedCount() const;
93 ASPOSECPP_SHARED_API void Lock();
95 ASPOSECPP_SHARED_API void Unlock();
99 virtual ASPOSECPP_SHARED_API bool Equals(ptr obj);
104 static bool ReferenceEquals(ptr const& objA, ptr const& objB)
105 {
106 return objA == objB;
107 }
113 template<typename T>
114 static typename std::enable_if<!IsSmartPtr<T>::value, bool>::type ReferenceEquals(T const& objA, T const& objB)
115 {
116 return &objA == &objB;
117 }
122 template<typename T>
123 static typename std::enable_if<!IsSmartPtr<T>::value, bool>::type ReferenceEquals(T const& objA, std::nullptr_t)
124 {
125 return false;
126 }
133 template<typename T1, typename T2>
134 static typename std::enable_if<IsSmartPtr<T1>::value && IsSmartPtr<T2>::value, bool>::type Equals(T1 const& objA, T2 const& objB)
135 {
136 return ReferenceEquals(objA, objB) || (objA != nullptr && objB != nullptr && objA->Equals(objB));
137 }
144 template<typename T1, typename T2>
145 static typename std::enable_if<!IsSmartPtr<T1>::value && !IsSmartPtr<T2>::value, bool>::type Equals(T1 const& objA, T2 const& objB)
146 {
147 return objA == objB;
148 }
151 virtual ASPOSECPP_SHARED_API int32_t GetHashCode() const;
154 virtual ASPOSECPP_SHARED_API String ToString() const;
158 virtual ASPOSECPP_SHARED_API ptr MemberwiseClone() const;
161 static const TypeInfo& Type()
162 {
163 return *static_holder<ThisTypeInfo>();
164 }
167 virtual ASPOSECPP_SHARED_API const TypeInfo& GetType() const;
171 virtual ASPOSECPP_SHARED_API bool Is(const TypeInfo& targetType) const;
174 virtual ASPOSECPP_SHARED_API void SetTemplateWeakPtr(uint32_t argument);
175#ifdef ASPOSE_GET_SHARED_MEMBERS
177 virtual ASPOSECPP_SHARED_API void GetSharedMembers(shared_members_type&) const;
178#endif
183 virtual ASPOSECPP_SHARED_API bool FastCast(const Details::FastRttiBase& helper, void** out_ptr) const;
184
185#ifdef __DBG_TOOLS
186private:
187 friend struct ::System::Details::DbgTools;
188
190 System::Details::DbgTools::stack_s_int_string_t m_personal_st;
192 bool m_rec_personal_st;
194 mutable int m_instanceNo;
195#endif
196
197#if defined(ENABLE_CYCLES_DETECTION_EXT)
198private:
199 friend class System::Debug::ExternalObjectCollector;
200 unsigned m_instance_id;
201#endif
202
203#ifdef __DBG_FOR_EACH_MEMBER
204public:
207 virtual ASPOSECPP_SHARED_API void DBG_for_each_member(DBG::for_each_member_visitor &visitor) const;
210 virtual const char* DBG_class_name() const { return "Object"; }
211#endif
212
213private:
214 friend class ::System::Detail::SmartPtrCounter;
215 friend class ::System::Details::LeakageDetector;
216
217#ifdef ENABLE_EXTERNAL_REFCOUNT
219 std::unique_ptr<Detail::SmartPtrCounter> m_external_count;
220#else
222 std::atomic<Detail::SmartPtrCounter*> m_external_count;
224 Detail::RefCount m_shared_count;
225#endif
226
228 struct ThisTypeInfo : TypeInfoPtr
229 {
231 ThisTypeInfo()
232 : TypeInfoPtr(u"System::Object")
233 {}
234
235 // Explicitly deleting several members to avoid warnings
236 ThisTypeInfo(const ThisTypeInfo&) = delete;
237 ThisTypeInfo(ThisTypeInfo&&) = delete;
238 ThisTypeInfo& operator = (const ThisTypeInfo&) = delete;
239 ThisTypeInfo& operator = (ThisTypeInfo&&) = delete;
240 };
241
243 typedef std::recursive_mutex mutex;
245 class GlobalMutexHolder;
247 static GlobalMutexHolder s_globalMutex;
248
249 mutex* volatile m_objectMutex;
250
251#ifdef ASPOSECPP_DEBUG
253 mutable const std::string* m_currentConstructor;
254#endif
255
256#ifdef __DBG_GARBAGE_COLLECTION
258 int m_generation;
259 friend bool ASPOSECPP_SHARED_API System::Details::__buildIsolationIsland(Object *&last, std::map<const Object*, shared_members_type> &island, int generation);
260#endif
261};
262
268template<>
269inline bool Object::Equals<float, float>(float const& objA, float const& objB)
270{
271 return (std::isnan(objA) && std::isnan(objB)) ? true : objA == objB;
272}
273
279template<>
280inline bool Object::Equals<double, double>(double const& objA, double const& objB)
281{
282 return (std::isnan(objA) && std::isnan(objB)) ? true : objA == objB;
283}
284
287{
288#ifdef ENABLE_EXTERNAL_REFCOUNT
289 return GetCounter()->SharedRefAdded();
290#else
291 ++m_shared_count;
292 return this;
293#endif
294}
295
298{
299#ifdef ENABLE_EXTERNAL_REFCOUNT
300 return GetCounter()->SharedRefRemovedSafe();
301#else
302 return --m_shared_count;
303#endif
304}
305
307inline int Object::RemovedSharedRefs(int count)
308{
309#ifdef ENABLE_EXTERNAL_REFCOUNT
310 return m_external_count->DecreaseSharedRef(count);
311#else
312 return (m_shared_count -= count);
313#endif
314}
315
317inline Detail::SmartPtrCounter* Object::WeakRefAdded()
318{
319 return GetCounter()->WeakRefAdded();
320}
321
324{
325 GetCounter()->WeakRefRemoved();
326}
327
329inline Detail::SmartPtrCounter* Object::GetCounter()
330{
331#ifdef ENABLE_EXTERNAL_REFCOUNT
332 return m_external_count.get();
333#else
334 Detail::SmartPtrCounter *counter = m_external_count.load();
335 if (counter == nullptr)
336 {
337 std::unique_ptr<Detail::SmartPtrCounter> new_counter(new Detail::SmartPtrCounter(this));
338 if (m_external_count.compare_exchange_strong(counter, new_counter.get()))
339 return new_counter.release();
340 }
341 return counter;
342#endif
343}
344
346inline int Object::SharedCount() const
347{
348#ifdef ENABLE_EXTERNAL_REFCOUNT
349 return m_external_count->SharedCount();
350#else
351 return m_shared_count;
352#endif
353}
354
355// ------------------------ casting implemetation --------------------------------
356namespace Details {
359 [[noreturn]] ASPOSECPP_SHARED_API void ThrowInvalidCastException();
363 template <typename T>
364 T ThrowInvalidCastException_helper()
365 {
366 ThrowInvalidCastException();
367 return T();
368 }
369}
370
372template <typename TTo>
374{
377};
378
380template <typename TTo>
381struct CastResult<SmartPtr<TTo>>
382{
384 typedef SmartPtr<TTo> type;
385};
387
389struct ExceptionWrapperType {};
391
394template <typename T> struct IsExceptionWrapper : std::is_base_of<System::ExceptionWrapperType, T> {};
395
401template<typename TTo, typename TFrom>
402typename std::enable_if<!IsExceptionWrapper<TTo>::value, typename CastResult<TTo>::type>::type
403Cast_noexcept(SmartPtr<TFrom> const& obj) // throw()
404{
405 return obj.template dynamic_pointer_cast<TTo>();
406}
407
414template<typename TTo, typename TFrom>
415typename std::enable_if<!IsExceptionWrapper<TTo>::value, typename CastResult<TTo>::type>::type
416Cast(SmartPtr<TFrom> const& obj) // throw(System::InvalidCastException)
417{
418 auto casted = dynamic_cast<TTo*>(obj.get());
419 return obj && !casted
420 ? Details::ThrowInvalidCastException_helper<typename CastResult<TTo>::type>()
421 : SmartPtr<TTo>(obj, casted, obj.get_Mode());
422}
423
426
433template<typename TTo, typename TFrom>
434[[deprecated]] typename std::enable_if<IsExceptionWrapper<TFrom>::value && IsExceptionWrapper<TTo>::value && (std::is_convertible<TTo, TFrom>::value || std::is_base_of<TTo, TFrom>::value), TTo>::type
435DynamicCast_noexcept(const TFrom& obj) noexcept
436{
437 return
438 (DynamicCast_noexcept<typename TTo::ExceptionType>(obj.Get()) != nullptr)
439 ? TTo(obj.Get())
440 : TTo(nullptr)
441 ;
442}
443
451template<typename TTo, typename TFrom>
452[[deprecated]] typename std::enable_if<IsExceptionWrapper<TFrom>::value && IsExceptionWrapper<TTo>::value && (std::is_convertible<TTo, TFrom>::value || std::is_base_of<TTo, TFrom>::value), TTo>::type
453DynamicCast(const TFrom& obj) // throw(System::InvalidCastException)
454{
455 return
456 obj != nullptr
457 ? ((DynamicCast_noexcept<typename TTo::ExceptionType>(obj.Get()) != nullptr)
458 ? TTo(obj.Get())
459 : Details::ThrowInvalidCastException_helper<TTo>())
460 : TTo(nullptr)
461 ;
462}
463
464// static cast
465
472template<typename TTo, typename TFrom>
473[[deprecated]] typename std::enable_if<!IsExceptionWrapper<TTo>::value, typename CastResult<TTo>::type>::type
475{
476 return Cast_noexcept<TTo, TFrom>(obj);
477}
478
486template<typename TTo, typename TFrom>
487[[deprecated]] typename std::enable_if<!IsExceptionWrapper<TTo>::value, typename CastResult<TTo>::type>::type
488StaticCast(SmartPtr<TFrom> const& obj) // throw(System::InvalidCastException)
489{
490 return Cast<TTo, TFrom>(obj);
491}
492
499template<typename TTo, typename TFrom>
500[[deprecated]] typename CastResult<TTo>::type StaticCast_noexcept(WeakPtr<TFrom> const& obj) // throw()
501{
502 return Cast_noexcept<TTo, TFrom>(obj);
503}
504
512template<typename TTo, typename TFrom>
513[[deprecated]] typename CastResult<TTo>::type StaticCast(WeakPtr<TFrom> const& obj) // throw(System::InvalidCastException)
514{
515 return obj != nullptr ? Cast<TTo, TFrom>(obj) : typename CastResult<TTo>::type();
516}
517
522template<typename TTo>
523[[deprecated]] typename CastResult<TTo>::type StaticCast(std::nullptr_t) // throw()
524{
525 // to process code like System::ExplicitCast<System::Object>(nullptr)
526 return typename CastResult<TTo>::type(nullptr);
527}
528
530template<typename TTo, typename TFrom>
531[[deprecated]] typename std::enable_if<std::is_arithmetic<TFrom>::value, TTo>::type StaticCast(TFrom value)
532{
533 return TTo(value);
534}
535
537template<typename TTo>
538[[deprecated]] typename std::enable_if<std::is_same<TTo, System::String>::value, TTo>::type StaticCast(TTo value)
539{
540 return value;
541};
542
544template<typename TTo, typename TFrom>
545[[deprecated]] typename std::enable_if<std::is_arithmetic<TFrom>::value, TTo>::type StaticCast(const TFrom* value)
546{
547 return TTo(value);
548}
549
557template<typename TTo, typename TFrom>
558[[deprecated]] typename std::enable_if<!std::is_same<TFrom, System::String>::value && !IsExceptionWrapper<TFrom>::value && !IsSmartPtr<TFrom>::value && !std::is_arithmetic<TFrom>::value, TTo>::type StaticCast(const TFrom& obj)
559{
560 //it is for special cases, like exception classes
561 if (!obj.Is(TTo::Type()))
562 Details::ThrowInvalidCastException();
563 return static_cast<TTo&>(obj);
564}
565
566// dynamic cast
567
574template<typename TTo, typename TFrom>
575[[deprecated]] typename std::enable_if<!IsExceptionWrapper<TTo>::value, typename CastResult<TTo>::type>::type
577{
578 return Cast_noexcept<TTo, TFrom>(obj);
579}
580
587template<typename TTo, typename TFrom>
588[[deprecated]] typename std::enable_if<IsExceptionWrapper<TFrom>::value && IsExceptionWrapper<TTo>::value && (std::is_convertible<TTo, TFrom>::value || std::is_base_of<TTo, TFrom>::value), TTo>::type
589StaticCast_noexcept(const TFrom& obj) // throw()
590{
591 return
592 (DynamicCast_noexcept<typename TTo::ExceptionType>(obj.Get()) != nullptr)
593 ? TTo(obj.Get())
594 : TTo(nullptr)
595 ;
596}
597
605template<typename TTo, typename TFrom>
606[[deprecated]] typename std::enable_if<IsExceptionWrapper<TFrom>::value && IsExceptionWrapper<TTo>::value && (std::is_convertible<TTo, TFrom>::value || std::is_base_of<TTo, TFrom>::value), TTo>::type
607StaticCast(const TFrom& obj) // throw(System::InvalidCastException)
608{
609 return
610 obj != nullptr
611 ? ((DynamicCast_noexcept<typename TTo::ExceptionType>(obj.Get()) != nullptr)
612 ? TTo(obj.Get())
613 : Details::ThrowInvalidCastException_helper<TTo>())
614 : TTo(nullptr)
615 ;
616}
617
618
626template<typename TTo, typename TFrom>
627[[deprecated]] typename std::enable_if<!std::is_enum<TTo>::value && !IsExceptionWrapper<TTo>::value, typename CastResult<TTo>::type>::type
628DynamicCast(SmartPtr<TFrom> const& obj) // throw(System::InvalidCastException)
629{
630 return Cast<TTo, TFrom>(obj);
631}
632
633namespace Detail {
638 ASPOSECPP_SHARED_API uint64_t GetIEnumUnsignedLongLongValue(const SmartPtr<Object>& obj);
639}
640
648template<typename TTo, typename TFrom>
649[[deprecated]] typename std::enable_if<std::is_enum<TTo>::value, TTo>::type DynamicCast(SmartPtr<TFrom> obj)
650{
651 return static_cast<TTo>(Detail::GetIEnumUnsignedLongLongValue(obj));
652}
653
658template<typename TTo>
659[[deprecated]] typename CastResult<TTo>::type DynamicCast(std::nullptr_t) noexcept
660{
661 // to process code like System::ExplicitCast<System::Object>(nullptr)
662 return SmartPtr<TTo>();
663}
664
671template<typename TTo, typename TFrom>
672[[deprecated]] typename std::enable_if<
673 !IsExceptionWrapper<TFrom>::value && !IsSmartPtr<TFrom>::value && std::is_convertible<TTo, TFrom>::value /* check if TFrom is base for TTo */
674 , TTo>::type DynamicCast(TFrom &obj)
675{
676 return *dynamic_cast<TTo*>(&obj);
677}
678
685template<typename TTo, typename TFrom>
686[[deprecated]] typename std::enable_if<std::is_same<System::Object, TFrom>::value && IsExceptionWrapper<TTo>::value, TTo>::type
688{
689 auto exception_ptr = DynamicCast_noexcept<typename TTo::ExceptionType>(obj);
690 return exception_ptr != nullptr ? TTo(StaticCast_noexcept<System::Details_Exception>(exception_ptr)) : TTo(nullptr);
691}
692
700template<typename TTo, typename TFrom>
701[[deprecated]] typename std::enable_if<std::is_same<System::Object, TFrom>::value && IsExceptionWrapper<TTo>::value, TTo>::type
703{
704 if (obj == nullptr)
705 return TTo(nullptr);
706
707 auto exception_ptr = DynamicCast_noexcept<typename TTo::ExceptionType>(obj);
708 return exception_ptr != nullptr ? TTo(StaticCast_noexcept<System::Details_Exception>(exception_ptr)) : Details::ThrowInvalidCastException_helper<TTo>();
709}
710
717template<typename TTo, typename TFrom>
718[[deprecated]] typename std::enable_if<std::is_same<System::Object, TFrom>::value && IsExceptionWrapper<TTo>::value, TTo>::type
720{
721 auto exception_ptr = DynamicCast_noexcept<typename TTo::ExceptionType>(obj);
722 return exception_ptr != nullptr ? TTo(StaticCast_noexcept<System::Details_Exception>(exception_ptr)) : TTo(nullptr);
723}
724
732template <typename TTo, typename TFrom>
733[[deprecated]] typename std::enable_if<std::is_same<System::Object, TFrom>::value && IsExceptionWrapper<TTo>::value, TTo>::type
734DynamicCast(SmartPtr<TFrom> obj) // throw(System::InvalidCastException)
735{
736 if (obj == nullptr)
737 return TTo(nullptr);
738
739 auto exception_ptr = DynamicCast_noexcept<typename TTo::ExceptionType>(obj);
740 return exception_ptr != nullptr ? TTo(StaticCast_noexcept<System::Details_Exception>(exception_ptr)) : Details::ThrowInvalidCastException_helper<TTo>();
741}
742
749template<typename TTo, typename TFrom>
750[[deprecated]] typename std::enable_if<std::is_pointer<TTo>::value && std::is_same<IntPtr, TFrom>::value, TTo>::type DynamicCast(TFrom value) noexcept
751{
752 return reinterpret_cast<TTo>(value);
753}
754
757
763template<typename TTo, typename TFrom>
764typename CastResult<TTo>::type ConstCast(const SmartPtr<TFrom>& obj) // throw()
765{
766 return obj->Is(TTo::Type()) ? System::const_pointer_cast<TTo>(obj) : SmartPtr<TTo>();
767}
768
774template <typename TTo, typename TFrom>
775typename CastResult<TTo>::type ForceStaticCast(SmartPtr<TFrom> const& obj) // throw(System::InvalidCastException)
776{
777 return SmartPtr<TTo>(obj, static_cast<TTo*>(obj.get()));
778}
779
784template<typename T>
786{
787 return MakeObject<T>(*ptr);
788}
789
796template<typename T, typename A>
797SharedPtr<T> With(const SharedPtr<T>& record, const A& initializer)
798{
799 auto result = MakeSharedPtr<T>(static_cast<T*>(record->_Clone_()));
800 initializer(*result);
801 return result;
802}
803
810template <typename T, typename A>
811T With(const T& record, const A& initializer)
812{
813 auto result = record;
814 initializer(result);
815 return result;
817
818namespace Runtime {
819 namespace CompilerServices {
822 {
823 public:
828 template<typename T>
829 static int GetHashCode(SmartPtr<T> const& obj)
830 {
831 return obj->Object::GetHashCode();
832 }
833 };
834 }
835}
836
838inline System::Object* System::Detail::SmartPtrCounter::Lock()
839{
840#ifdef ENABLE_EXTERNAL_REFCOUNT
841 return SharedRefAdded();
842#else
843 return m_object->SharedRefAdded();
844#endif
845}
846
848template <typename T>
850{
851 return SmartPtr<Object>(GetObjectOrNull());
852}
853
855template <typename T>
856void SmartPtr<T>::SetContainedTemplateWeakPtr(uint32_t argument) const
857{
858 if (Object *const object = GetObjectOrNull())
859 object->SetTemplateWeakPtr(argument);
860}
861
863template <typename T>
864bool SmartPtr<T>::Is(const System::TypeInfo &target) const
865{
866 if (m_data.IsNull())
867 return false;
868 else if (m_data.GetMode() == SmartPtrMode::Shared)
869 return m_data.SharedGetObject()->Is(target);
870 else
871 return m_data.WeakGetCounter()->GetObject()->Is(target);
872}
873
875template <typename T>
877{
878 const int count = releaser->SharedRefRemovedSafe();
879
880 System::Details::MakeObjectLeakageDetector::ReportLeakCycle(count);
881
882#ifdef ENABLE_EXTERNAL_REFCOUNT
883 if (releaser->GetOwnershipState() != System::Detail::SmartPtrCounter::ObjectOwnershipState::OwnedByPointers)
884 return nullptr;
885
886 Object *const object = releaser->GetObject();
887#else
888 Object *const& object = releaser;
889#endif
890
891 if (count == 0)
892 return object;
893
894 return nullptr;
895}
896
897
898namespace Details {
899
901 template <unsigned int leaf, unsigned int ...leafs>
902 void WeakLeafMaker<leaf, leafs...>::Apply(System::Object *ptr)
903 {
904 ptr->SetTemplateWeakPtr(leaf);
905 WeakLeafMaker<leafs...>::Apply(ptr);
906 }
907}
908
910ASPOSECPP_SHARED_API void PrintTo(const System::Object& value, std::ostream* stream);
911
916ASPOSECPP_SHARED_API std::ostream& operator<<(std::ostream& stream, const System::Object& object);
917
922ASPOSECPP_SHARED_API std::wostream& operator<<(std::wostream& stream, const System::Object& object);
923
924} // namespace System
925
927typedef System::Object object;
928
929#include <system/details/this_protector.h>
930#include <system/details/for_each_member_visitor.h>
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:51
Object * SharedRefAdded()
Increments shared reference count. Shouldn't be called directly; instead, use smart pointers or ThisP...
Definition: object.h:286
virtual int32_t GetHashCode() const
Analog of C# Object.GetHashCode() method. Enables hashing of custom objects.
void Lock()
Implements C# lock() statement locking. Call directly or use LockContext sentry object.
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals(T const &objA, std::nullptr_t)
Reference-compares value type object with nullptr.
Definition: object.h:123
virtual const TypeInfo & GetType() const
Gets actual type of object. Analog of C# System.Object.GetType() call.
virtual bool Is(const TypeInfo &targetType) const
Check if object represents an instance of type described by targetType. Analog of C# 'is' operator.
virtual bool Equals(ptr obj)
Compares objects using C# Object.Equals semantics.
void WeakRefRemoved()
Decrements weak reference count. Shouldn't be called directly; instead, use smart pointers or ThisPro...
Definition: object.h:323
Detail::SmartPtrCounter * GetCounter()
Gets reference counter data structure associated with the object.
Definition: object.h:329
static bool ReferenceEquals(ptr const &objA, ptr const &objB)
Compares objects by reference.
Definition: object.h:104
Object()
Creates object. Initializes all internal data structures.
virtual String ToString() const
Analog of C# Object.ToString() method. Enables converting custom objects to string.
virtual ptr MemberwiseClone() const
Analog of C# Object.MemberwiseClone() method. Enables cloning custom types.
Detail::SmartPtrCounter * WeakRefAdded()
Increments weak reference count. Shouldn't be called directly; instead, use smart pointers or ThisPro...
Definition: object.h:317
static std::enable_if< IsSmartPtr< T1 >::value &&IsSmartPtr< T2 >::value, bool >::type Equals(T1 const &objA, T2 const &objB)
Compares reference type objects in C# style.
Definition: object.h:134
void Unlock()
Implements C# lock() statement unlocking. Call directly or use LockContext sentry object.
static std::enable_if<!IsSmartPtr< T1 >::value &&!IsSmartPtr< T2 >::value, bool >::type Equals(T1 const &objA, T2 const &objB)
Compares value type objects in C# style.
Definition: object.h:145
int RemovedSharedRefs(int count)
Decreases shared reference count by specified value.
Definition: object.h:307
int SharedCount() const
Gets current value of shared reference counter.
Definition: object.h:346
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals(T const &objA, T const &objB)
Compares objects by reference.
Definition: object.h:114
virtual ~Object()
Destroys object. Frees all internal data structures.
static const TypeInfo & Type()
Implements C# typeof(System.Object) construct.
Definition: object.h:161
int SharedRefRemovedSafe()
Decrements and returns shared reference count. Shouldn't be called directly; instead,...
Definition: object.h:297
Object(Object const &x)
Copy constructor. Doesn't copy anything, really, just initializes new object and enables copy constru...
virtual bool FastCast(const Details::FastRttiBase &helper, void **out_ptr) const
For internal purposes only.
SmartPtr< Object > ptr
Alias for smart pointer type.
Definition: object.h:54
virtual void SetTemplateWeakPtr(uint32_t argument)
Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containe...
Helper class to get some object information in runtime.
Definition: object.h:822
static int GetHashCode(SmartPtr< T > const &obj)
Gets hash code on arbitrary type. Calls Object::GetHashCode() to do so.
Definition: object.h:829
SmartPtr< Object > ToObjectPtr() const
Converts any pointer type to pointer to Object. Doesn't require Pointee_ type to be complete.
Definition: object.h:849
Pointee_ * get() const
Gets pointed object.
Definition: smart_ptr.h:518
void SetContainedTemplateWeakPtr(uint32_t argument) const
Calls SetTemplateWeakPtr() method on pointed object (if any).
Definition: object.h:856
bool Is(const System::TypeInfo &target) const
Checks if pointed object is of specific type or its child type. Follows C# 'is' semantics.
Definition: object.h:864
SmartPtrMode get_Mode() const
Gets pointer mode.
Definition: smart_ptr.h:543
Object * ReleaseSharedAndGetObjectToDelete()
Decrements currently referenced object's shared pointer counter.
Definition: smart_ptr.h:1033
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
Represents a particular type and provides information about it.
Definition: type_info.h:109
Subclass of System::SmartPtr which sets itself to weak mode at construction. Please note that this cl...
Definition: weak_ptr.h:18
Definition: db_command.h:9
void PrintTo(DateTime value, std::ostream *stream)
Prints value to ostream. Mostly used for debug.
@ Shared
Shared mode: pointer participates in reference counting.
CastResult< TTo >::type ConstCast(const SmartPtr< TFrom > &obj)
End of deprecated casts.
Definition: object.h:764
std::enable_if<!IsExceptionWrapper< TTo >::value, typenameCastResult< TTo >::type >::type StaticCast(SmartPtr< TFrom > const &obj)
Performs static cast on SmartPtr objects.
Definition: object.h:488
std::enable_if<!IsExceptionWrapper< TTo >::value, typenameCastResult< TTo >::type >::type Cast(SmartPtr< TFrom > const &obj)
Performs cast on SmartPtr objects.
Definition: object.h:416
std::enable_if< IsExceptionWrapper< TFrom >::value &&IsExceptionWrapper< TTo >::value &&(std::is_convertible< TTo, TFrom >::value||std::is_base_of< TTo, TFrom >::value), TTo >::type DynamicCast_noexcept(const TFrom &obj) noexcept
Old obsolete casts. Will be removed in future versions.
Definition: object.h:435
std::enable_if<!IsExceptionWrapper< TTo >::value, typenameCastResult< TTo >::type >::type StaticCast_noexcept(SmartPtr< TFrom > const &obj)
Performs static cast on SmartPtr objects.
Definition: object.h:474
std::enable_if<!IsExceptionWrapper< TTo >::value, typenameCastResult< TTo >::type >::type Cast_noexcept(SmartPtr< TFrom > const &obj)
Performs cast on SmartPtr objects.
Definition: object.h:403
CastResult< TTo >::type ForceStaticCast(SmartPtr< TFrom > const &obj)
Performs real static cast on SmartPtr objects.
Definition: object.h:775
SharedPtr< T > With(const SharedPtr< T > &record, const A &initializer)
Clones reference record and applies initializer functor to it.
Definition: object.h:797
SmartPtr< Object > MemberwiseClone(T *ptr)
Performs memberwise cloning using copy constructor.
Definition: object.h:785
std::ostream & operator<<(std::ostream &stream, DateTime date_time)
Insert data into the stream using UTF-8 encoding.
Definition: date_time.h:729
std::enable_if< IsExceptionWrapper< TFrom >::value &&IsExceptionWrapper< TTo >::value &&(std::is_convertible< TTo, TFrom >::value||std::is_base_of< TTo, TFrom >::value), TTo >::type DynamicCast(const TFrom &obj)
Performs dynamic cast on Exception objects.
Definition: object.h:453
Template magic to deduce cast results.
Definition: object.h:374
SmartPtr< TTo > type
An alias for a pointer to an instance of TTo.
Definition: object.h:376
A template predicate that determines if the specified type is a Exception class or its descendant.
Definition: object.h:394
Trait class to check if a type is a specialization of SmartPtr class.
Definition: smart_ptr.h:1499
Wrapper for a pointer to an instance of TypeInfo class. This type should be allocated on stack and pa...
Definition: type_info.h:72