Base Framework
Classes | Public Member Functions | List of all members
ReferenceCountedObject Class Reference

Reference counted object. More...

#include <base/mem/ReferenceCountedObject.h>

Inherits DynamicObject.

Inherited by AnyValue, ArgumentParser::Option, AsynchronousReadContext, AsynchronousWriteContext, BinaryTree< TYPE >::BinaryTreeImpl, CollectionOwnerContext, GraphicsContext::GraphicsContextObjectHandle, Handle, HashSet< TYPE >::HashSetImpl, HashTable< KEY, VALUE >::HashTableImpl, HTMLAttribute, HTMLItem, IEEE1394Common::IsochronousReadChannelImpl, IEEE1394Common::IsochronousRequestImpl, IEEE1394Common::IsochronousWriteChannelImpl, IEEE1394Impl, List< TYPE >::ListImpl, Module, Moveable::Stats, ObjectModel, ObjectModel::Value, OpenCL::HandleImpl, OrbBufferPool, OrbChannel, OrbConnection, OrbConnectionFactory [virtual], OrbDecoder [virtual], OrbEncoder [virtual], OrbEncoding [virtual], OrbScheme, OrbSkeleton [virtual], OrbStub [virtual], Profiler::ReferenceCounters, Profiler::ReferenceIO, Profiler::ReferenceResource, Profiler::ReferenceString, Profiler::ReferenceValue, Queue< TYPE, LOCK >::QueueImpl, ReferenceCountedAllocator< TYPE >, ReferenceCountedAllocator< char >, ReferenceCountedAllocator< ucs4 >, ReferenceCountedAllocator< uint8 >, ReferenceCountedAllocator< unsigned long >, ReferenceCountedAllocator< Value >, ReferenceCountedObjectWrapper< TYPE >, ResourceHandle, SharedMemory::SharedMemoryImpl, Stack< TYPE >::StackImpl, Stream [virtual], Translation, UnitTest, UnitTest::Run, and WebAssembly::FunctionContext.

Classes

class  ReferenceImpl
 

Public Member Functions

 ReferenceCountedObject () noexcept
 
 ReferenceCountedObject (const ReferenceCountedObject &copy) noexcept
 
 ReferenceCountedObject (ReferenceCountedObject &&move) noexcept
 
ReferenceCountedObjectoperator= (const ReferenceCountedObject &copy) noexcept
 
ReferenceCountedObjectoperator= (ReferenceCountedObject &&move) noexcept
 
MemorySize getNumberOfReferences_INTERNAL () const noexcept
 
virtual bool useGarbageCollector () const noexcept
 
- Public Member Functions inherited from DynamicObject
 DynamicObject () noexcept
 
bool isValidObject () const noexcept
 
virtual ~DynamicObject () noexcept(false)
 
 _COM_AZURE_DEV__BASE__OVERRIDE_ALLOC ()
 

Detailed Description

Reference counted object.

A reference counted object is used to count the number of references from a reference counting automation pointer. You should always use the automation pointer Reference or similar to access a ReferenceCountedObject. The ReferenceCountedObject is nothing more than an encapsulation of the number of references. To avoid any invalidation of the number of references only Reference can make changes to the number of references. Not even subclasses of ReferenceCountedObject are allowed to change the number of references. The number of references is not considered a part of the state of the object and can thus be modified for constant reference counted objects. Or to put it simple, you can reference count constant objects. Use ReferenceCounter to count the number of references to any object.

To make your own reference counted class you simply inherit from this class. Like illustrated by this example.

class MyClass : public virtual Object, public virtual ReferenceCountedObject {
...
};
See also
Reference ReferenceCounter
Version
1.2

Constructor & Destructor Documentation

◆ ReferenceCountedObject() [1/3]

ReferenceCountedObject::ReferenceCountedObject ( )
inlinenoexcept

Initializes reference counted object with zero references.

◆ ReferenceCountedObject() [2/3]

ReferenceCountedObject::ReferenceCountedObject ( const ReferenceCountedObject copy)
inlinenoexcept

Initializes object from other reference counted object. The new object is initialized with zero references. This is an unusual behavior for a copy constructor but makes sense since a new object cannot have any references.

◆ ReferenceCountedObject() [3/3]

ReferenceCountedObject::ReferenceCountedObject ( ReferenceCountedObject &&  move)
inlinenoexcept

Initializes object from other reference counted object. The new object is initialized with zero references. This is an unusual behavior for a copy constructor but makes sense since a new object cannot have any references.

Member Function Documentation

◆ getNumberOfReferences_INTERNAL()

MemorySize ReferenceCountedObject::getNumberOfReferences_INTERNAL ( ) const
inlinenoexcept

Returns the number of references. Avoid this.

◆ operator=() [1/2]

ReferenceCountedObject& ReferenceCountedObject::operator= ( const ReferenceCountedObject copy)
inlinenoexcept

Assignment of reference counted object does not change this object. This is unusual behavior for the assignment operator but makes sense since the assignment doesn't influence the number of Reference objects that point to this object.

◆ operator=() [2/2]

ReferenceCountedObject& ReferenceCountedObject::operator= ( ReferenceCountedObject &&  move)
inlinenoexcept

Assignment of reference counted object does not change this object. This is unusual behavior for the assignment operator but makes sense since the assignment doesn't influence the number of Reference objects that point to this object.

◆ useGarbageCollector()

virtual bool ReferenceCountedObject::useGarbageCollector ( ) const
inlinevirtualnoexcept

Returns true if the object should be garbage collected automatically.

ReferenceCountedObject
Reference counted object.
Definition: ReferenceCountedObject.h:50
Object
Object.
Definition: Object.h:28