#include <referenceCount.h>
Public Member Functions | |
| ReferenceCount (size_t count=1) | |
| The default constructor sets the reference count to 1, indicating a new and unshared condition. | |
| ReferenceCount (const ReferenceCount &other) | |
| This is the copy constructor. | |
| ~ReferenceCount () | |
| Decrements the count and destroys the ReferenceCount instance. | |
| ReferenceCount & | operator++ () |
| The pre-increment operator increments the count by one. | |
| ReferenceCount | operator++ (int) |
| Due to the semantics of the ReferenceCount class, the post-increment operator is identical to the the pre-increment operator. | |
| ReferenceCount & | operator-- () |
| The pre-decrement operator decrements the count by one. | |
| ReferenceCount | operator-- (int) |
| Due to the semantics of the ReferenceCount class, the post-decrement operator is identical to the the pre-decrement operator. | |
| ReferenceCount & | operator+= (size_t offset) |
| This operator has the same effect as incrementing *this offset times, but runs in O(1) time. | |
| ReferenceCount & | operator-= (size_t offset) |
| This operator has the same effect as decrementing *this offset times, but runs in O(1) time. | |
| ReferenceCount & | operator= (const ReferenceCount &source) |
| The assignment operator copies its argument. | |
| size_t | count () const |
| This member function returns the current count. | |
| bool | isShared () const |
| This member function returns true if more than one ReferenceCount object is sharing the same data. | |
| void | reset (size_t count=1) |
| This member function decrements the count and releases the reference, then reinitializes with a fresh count. | |
| bool | shared () const |
| This member function is identical to member function isShared(). | |
One note regarding thread safety: if you use ReferenceCount as a member of a class which is shared between threads, and which manages its own mutex locking (such as dlrThread::Monitor) construction and destruction of the members of the containing class will most likely happen outside of the locked sections of code. This means that the ReferenceCount copy constructor and destructor will be called without protection, which is not thread-safe. To solve this, you can dynamically allocate the ReferenceCount instance using new, keep a pointer to the ReferenceCount as a member of the class, and explicitly manage copying, incrementing, and decrementing of the ReferenceCount inside the locked sections of code.
Definition at line 40 of file referenceCount.h.
| dlr::common::ReferenceCount::ReferenceCount | ( | size_t | count = 1 |
) | [inline] |
The default constructor sets the reference count to 1, indicating a new and unshared condition.
To indicate that there are existing references, pass a constructor argument greater than 1. Use an argument of zero to indicate that the shared data has not been initialized.
| count | This argument specifies to what value the count should be initialized. For most applications, this argument should be set to 1. |
Definition at line 54 of file referenceCount.h.
References count().
| dlr::common::ReferenceCount::ReferenceCount | ( | const ReferenceCount & | other | ) | [inline] |
This is the copy constructor.
After copying, both ReferenceCount instances share the same count, and the count is incremented by one.
| other | The ReferenceCount instance to be copied. |
Definition at line 69 of file referenceCount.h.
| dlr::common::ReferenceCount::~ReferenceCount | ( | ) | [inline] |
Decrements the count and destroys the ReferenceCount instance.
Definition at line 78 of file referenceCount.h.
| ReferenceCount& dlr::common::ReferenceCount::operator++ | ( | ) | [inline] |
The pre-increment operator increments the count by one.
Definition at line 87 of file referenceCount.h.
| ReferenceCount dlr::common::ReferenceCount::operator++ | ( | int | ) | [inline] |
Due to the semantics of the ReferenceCount class, the post-increment operator is identical to the the pre-increment operator.
Definition at line 101 of file referenceCount.h.
| ReferenceCount& dlr::common::ReferenceCount::operator-- | ( | ) | [inline] |
The pre-decrement operator decrements the count by one.
Definition at line 110 of file referenceCount.h.
| ReferenceCount dlr::common::ReferenceCount::operator-- | ( | int | ) | [inline] |
Due to the semantics of the ReferenceCount class, the post-decrement operator is identical to the the pre-decrement operator.
Definition at line 126 of file referenceCount.h.
| ReferenceCount& dlr::common::ReferenceCount::operator+= | ( | size_t | offset | ) | [inline] |
This operator has the same effect as incrementing *this offset times, but runs in O(1) time.
| offset | This argument specifies how many times to increment |
Definition at line 137 of file referenceCount.h.
| ReferenceCount& dlr::common::ReferenceCount::operator-= | ( | size_t | offset | ) | [inline] |
This operator has the same effect as decrementing *this offset times, but runs in O(1) time.
| offset | This argument specifies how many times to decrement |
Definition at line 151 of file referenceCount.h.
| ReferenceCount& dlr::common::ReferenceCount::operator= | ( | const ReferenceCount & | source | ) | [inline] |
The assignment operator copies its argument.
After copying, both ReferenceCount instances share the same count, and the count is incremented by one.
| source | The ReferenceCount instance to be copied. |
Definition at line 169 of file referenceCount.h.
References m_countPtr.
| size_t dlr::common::ReferenceCount::count | ( | ) | const [inline] |
This member function returns the current count.
Definition at line 186 of file referenceCount.h.
Referenced by ReferenceCount(), and reset().
| bool dlr::common::ReferenceCount::isShared | ( | ) | const [inline] |
This member function returns true if more than one ReferenceCount object is sharing the same data.
That is, it returns true if the internal count is greater than 1.
Definition at line 197 of file referenceCount.h.
Referenced by shared().
| void dlr::common::ReferenceCount::reset | ( | size_t | count = 1 |
) | [inline] |
This member function decrements the count and releases the reference, then reinitializes with a fresh count.
Use this if you want to release the shared resource and create a new one.
| count | This argument specifies to what value the count should be reinitialized. For most applications, this argument should be set to 1. |
Definition at line 214 of file referenceCount.h.
References count().
| bool dlr::common::ReferenceCount::shared | ( | ) | const [inline] |
This member function is identical to member function isShared().
It is included for backwards compatibility with previous versions of ReferenceCount.
Definition at line 231 of file referenceCount.h.
References isShared().
1.5.2