SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWTCountingBody< Mutex > Class Template Reference

Base class for classes that must maintain a reference count. More...

#include <rw/pointer/RWTCountingBody.h>

Inheritance diagram for RWTCountingBody< Mutex >:
RWTMonitor< Mutex > RWTCounter< Mutex >

Public Member Functions

 ~RWTCountingBody (void)
 
unsigned addReference (void)
 
unsigned references (void) const
 
unsigned removeReference (void)
 

Protected Types

typedef RWTLockGuard< RWTMonitor< Mutex > > LockGuard
 
typedef RWTTryLockGuard< RWTMonitor< Mutex > > TryLockGuard
 
typedef RWTUnlockGuard< RWTMonitor< Mutex > > UnlockGuard
 
- Protected Types inherited from RWTMonitor< Mutex >
typedef RWTLockGuard< RWTMonitor< Mutex > > LockGuard
 
typedef RWTTryLockGuard< RWTMonitor< Mutex > > TryLockGuard
 
typedef RWTUnlockGuard< RWTMonitor< Mutex > > UnlockGuard
 

Protected Member Functions

 RWTCountingBody (const RWTCountingBody< Mutex > &second)
 
 RWTCountingBody (RWStaticCtor)
 
 RWTCountingBody (unsigned initCount=0)
 
RWTCountingBody< Mutex > & operator= (const RWTCountingBody< Mutex > &second)
 
- Protected Member Functions inherited from RWTMonitor< Mutex >
 RWTMonitor (const RWTMonitor< Mutex > &second)
 
 RWTMonitor (RWStaticCtor)
 
 RWTMonitor (void)
 
 ~RWTMonitor (void)
 
void acquire (void)
 
bool isAcquired (void) const
 
RWTMonitor< Mutex > & monitor (void) const
 
Mutex & mutex (void)
 
RWTMonitor< Mutex > & operator= (const RWTMonitor< Mutex > &)
 
void release (void)
 
bool tryAcquire (void)
 

Detailed Description

template<class Mutex>
class RWTCountingBody< Mutex >

RWTCountingBody is a base class for classes that must maintain a reference count. It can be safely used in a multithreaded environment.

Example
#include <rw/pointer/RWTCountedPointer.h>
#include <rw/pointer/RWTCountingBody.h>
#include <rw/sync/RWMutexLock.h>
#include <iostream>
class Foo : public RWTCountingBody<RWMutexLock> {
public:
void bar(void) { std::cout << "I'm a foo example" << std::endl; }
};
typedef RWTCountedPointer<Foo> FooPointer;
int main(void) {
try {
FooPointer p1(new Foo);
p1->bar();
} catch (const RWxmsg& msg) {
std::cout << msg.why() << std::endl;
}
return 0;
}
A smart pointer handle to a reference-counting body.
Definition RWTCountedPointer.h:82
Base class for classes that must maintain a reference count.
Definition RWTCountingBody.h:64
Base class for the hierarchy of exceptions in the Essential Tools Module.
Definition rwerr.h:57
virtual const char * why() const

Member Typedef Documentation

◆ LockGuard

template<class Mutex >
typedef RWTLockGuard<RWTMonitor<Mutex> > RWTCountingBody< Mutex >::LockGuard
protected

Predefined type for compatible guard.

◆ TryLockGuard

template<class Mutex >
typedef RWTTryLockGuard<RWTMonitor<Mutex> > RWTCountingBody< Mutex >::TryLockGuard
protected

Predefined type for compatible guard.

◆ UnlockGuard

template<class Mutex >
typedef RWTUnlockGuard<RWTMonitor<Mutex> > RWTCountingBody< Mutex >::UnlockGuard
protected

Predefined type for compatible guard.

Constructor & Destructor Documentation

◆ ~RWTCountingBody()

template<class Mutex >
RWTCountingBody< Mutex >::~RWTCountingBody ( void )
inline

Destructor.

◆ RWTCountingBody() [1/3]

template<class Mutex >
RWTCountingBody< Mutex >::RWTCountingBody ( unsigned initCount = 0)
inlineprotected

Constructs a default instance (initializes the reference count). Throws no exceptions.

◆ RWTCountingBody() [2/3]

template<class Mutex >
RWTCountingBody< Mutex >::RWTCountingBody ( RWStaticCtor )
inlineprotected

Constructs a static instance (does not initialize the reference count). Throws no exceptions.

◆ RWTCountingBody() [3/3]

template<class Mutex >
RWTCountingBody< Mutex >::RWTCountingBody ( const RWTCountingBody< Mutex > & second)
inlineprotected

Defines a copy constructor that creates a new instance and initializes the reference count. This constructor does not actually create a copy, but allows derived classes to provide a meaningful copy constructor. Throws no exceptions.

Member Function Documentation

◆ addReference()

template<class Mutex >
unsigned RWTCountingBody< Mutex >::addReference ( void )

Increments the reference count and then returns the previous value minus one.

◆ operator=()

template<class Mutex >
RWTCountingBody< Mutex > & RWTCountingBody< Mutex >::operator= ( const RWTCountingBody< Mutex > & second)
inlineprotected

Defines an assignment operator, allowing derived classes to do assignments. Don't assign the reference count. Throws no exceptions.

◆ references()

template<class Mutex >
unsigned RWTCountingBody< Mutex >::references ( void ) const

Queries the current reference count. Throws no exceptions.

◆ removeReference()

template<class Mutex >
unsigned RWTCountingBody< Mutex >::removeReference ( void )

Decrements the reference count and then returns the previous value minus one.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.