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.
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.
- See also
- Reference ReferenceCounter
- Version
- 1.2
◆ ReferenceCountedObject() [1/3]
ReferenceCountedObject::ReferenceCountedObject |
( |
| ) |
|
|
inlinenoexcept |
Initializes reference counted object with zero references.
◆ ReferenceCountedObject() [2/3]
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]
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.
◆ getNumberOfReferences_INTERNAL()
MemorySize ReferenceCountedObject::getNumberOfReferences_INTERNAL |
( |
| ) |
const |
|
inlinenoexcept |
Returns the number of references. Avoid this.
◆ operator=() [1/2]
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]
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.