Module: Threads Package: Smart Pointer
RWTCountingBody<Mutex> RWTMonitor<Mutex>
addReference() LockGuard operator=() |
references() removeReference() RWTCountingBody() |
TryLockGuard UnlockGuard ~RWTCountingBody() |
#include <rw/pointer/RWTCountingBody.h>
RWTCountingBody<Mutex> is a base class for classes that must maintain a reference count. It can be safely used in a multithreaded environment, when parameterized with a non-null mutex. If multithread safety is not an issue, use a null mutex as the template type.
#include <rw/pointer/RWTCountedPointer.h> #include <rw/pointer/RWTCountingBody.h> #include <rw/sync/RWMutexLock.h> #include <iostream.h> class Foo : public RWTCountingBody<RWMutexLock> {public: void bar(void) { cout << "I'm a foo example" << endl; } }; typedef RWTCountedPointer<Foo> FooPointer; int main(void) { try { FooPointer p1(new Foo); p1->bar(); } catch(RWxmsg& msg) { cout << msg.why() << endl; } return 0; }
typedef RWTLockGuard<RWTMonitor<Mutex> > LockGuard; typedef RWTUnlockGuard<RWTMonitor<Mutex> > UnlockGuard; typedef RWTTryLockGuard<RWTMonitor<Mutex> > TryLockGuard;
~RWTCountingBody();
Destructor.
unsigned addReference();
Increments and returns the reference count.
unsigned references() const;
Queries the current reference count. Throws no exceptions.
unsigned removeReference();
Decrements and returns the reference count.
RWTCountingBody(RWStaticCtor);
Constructs a static instance (does not initialize the reference count). Throws no exceptions.
RWTCountingBody(const RWTCountingBody<Mutex>& second);
Defines copy constructor, which creates a new instance and initializes the reference count. It doesn't actually copy anything, but allows derived classes to provide a meaningful copy constructor. Throws no exceptions.
RWTCountingBody(unsigned initCount = 0);
Constructs a default instance (initializes the reference count). Throws no exceptions.
RWTCountingBody<Mutex>& operator=(const RWTCountingBody<Mutex>& second);
Defines an assignment operator so derived classes can do assignments. Don't assign the reference count. Throws no exceptions.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.