Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members

RCObject Class Reference

This the base class for a shared data class that is used in a reference counted copy-on-write object (see RCArray). More...

#include <RCObject.h>

Inheritance diagram for RCObject:

Inheritance graph
[legend]
List of all members.

Public Member Functions

void addReference ()
void removeReference ()
const bool isShared () const
const size_t refCnt () const

Protected Member Functions

 RCObject ()
 RCObject (const RCObject &rhs)
RCObjectoperator= (const RCObject &rhs)
virtual ~RCObject ()

Private Attributes

size_t refCount

Detailed Description

This the base class for a shared data class that is used in a reference counted copy-on-write object (see RCArray).

This class encapsulates the reference count. The shared data class is derived from this class and is a container for the the shared data.

This class is based on the RCObject class published in More Effective C++ by Scott Meyers, Addison-Wesley, 1996. This is part of Scott Meyers reference counted String class, published in "Item 29". This code is in the public domain.

I have the first edition and first printing of Mr. Meyers' book. I've added some of the changes from Mr. Meyers' errata pages, which are not included in this edition. I've also made some to Mr. Meyers' version of RCObject. In particular, I've removed the shareable flag, since as far as I can tell, it is not needed. I have also made the reference count available for testing purposes.

Author:
Ian Kaplan www.bearcave.com

Definition at line 38 of file RCObject.h.


Constructor & Destructor Documentation

RCObject::RCObject  )  [inline, protected]
 

Definition at line 56 of file RCObject.h.

00056 : refCount(0) {}

RCObject::RCObject const RCObject rhs  )  [inline, protected]
 

Definition at line 59 of file RCObject.h.

00059 : refCount(0) {}

RCObject::~RCObject  )  [inline, protected, virtual]
 

Definition at line 68 of file RCObject.h.

00068 {}


Member Function Documentation

void RCObject::addReference  )  [inline]
 

Definition at line 71 of file RCObject.h.

References refCount.

00071 { refCount++; }

const bool RCObject::isShared  )  const [inline]
 

Definition at line 82 of file RCObject.h.

References refCount.

00083 {
00084   return refCount > 1;
00085 }

RCObject & RCObject::operator= const RCObject rhs  )  [inline, protected]
 

Definition at line 62 of file RCObject.h.

00063 {
00064   return *this;
00065 }

const size_t RCObject::refCnt  )  const [inline]
 

Definition at line 88 of file RCObject.h.

References refCount.

Referenced by SubString::SharedData::getRefCnt(), and RCArray< T >::SharedData::getRefCnt().

00089 {
00090   return refCount;
00091 }

void RCObject::removeReference  )  [inline]
 

Definition at line 74 of file RCObject.h.

References refCount.

00075 { 
00076   if (--refCount == 0) {
00077     delete this; 
00078   }
00079 }


Member Data Documentation

size_t RCObject::refCount [private]
 

Definition at line 52 of file RCObject.h.

Referenced by addReference(), isShared(), refCnt(), and removeReference().


The documentation for this class was generated from the following file:
Generated on Mon Sep 22 20:23:02 2003 by doxygen 1.3.3