Xavax C++ Library | Class Index FAQ Overview |
Copy semantics for RCObject are controlled by a
shareable flag
which defaults to true
and is set by the
shareable method.
When a RCObject is shareable,
new references increment the reference count
and share the object.
If a RCObject is not shareable,
a new copy of the object is created for each new reference.
RCObject works in conjunction with
RCPointer
to implement a copy-on-write mechanism.
Before a derived class method modifies an object,
it must call one of two methods provided by RCPointer.
The modify
method
should be called when an object will be overwritten,
which is usually the case in an assignment operator.
If the object is shared,
the modify method will create a new object.
The modifyCopy
method should be called when an object will be modified.
If the object is shared,
the modifyCopy method will create a new copy
of the object.
Constructor Summary |
RCPointer<T>(T*)
Construct a RCPointer<T>. |
RCPointer<T>(const RCPointer&)
Construct a copy of a RCPointer<T>. |
Operator Summary | |
RCPointer<T>&
|
operator=(const RCPointer<T>&)
Assignment operator. |
bool
|
operator==(const RCPointer<T>&)
Test for equality. |
T*
|
operator->() const
Return the pointer cast as a pointer to T. |
T&
|
operator*() const
Return the dereferenced pointer cast as a reference to T. |
Method Summary | |
void
|
modify()
Prepare to modify the referenced object. |
void
|
modifyCopy()
Prepare to modify a copy of the referenced object. |
Methods Inherited From Object | |
cast<T>,
cast<T>,
classRecord,
ClassRecord,
clone,
hashCode
|
Related Classes | |
Object, RCObject |
Constructor Detail |
RCPointer<T>()
RCPointer<T>(const RCPointer<T>& src)
src
- the object to be copied.
Operator Detail |
RCPointer<T>&operator=(const RCPointer<T>& src)
src
- the pointer to be copied.bool operator==(const RCPointer<T>& rhs)
src
- the right hand side of the == operator.T* operator->()
T& operator*()
NullPointerException
- if the underlying pointer to T is null.
Method Detail |
void modify()
void modifyCopy()
Example Code |
Copyright © 2003 Xavax Inc. -- All Rights Reserved