AaronCameron.net
I care not for your petty politics.
Jimmy's World Games
Not a Member? - Login or Create an Account
Friday the 3rd of September 2010 @ 10:26am
[]
Front Page Journal Projects Your Profile About

LibN2L-4 Library Code Reference

Classes
Compounds
Files
Members
Method Index
Full Reference

n2l::cAutoPtr< TPtr > Class Template Reference

A template based reference counting auto pointer. More...

#include <cAutoPtr.h>

List of all members.

Public Member Functions


Detailed Description

template<class TPtr>
class n2l::cAutoPtr< TPtr >

A template based reference counting auto pointer.

This class has behaviour very similar to a standard simple dumb pointer except that it reference counts its target to ensure that no autopointer ever dangles. cAutoPtr also allows cAutoPtr<Parent> to cAutoPtr<Child> to cAutoPtr<Parent> in assignment by providing cAutoPtr casts using dynamic_cast as necessary.

Warning:
No precautions have been taken to make this class thread safe.
Todo:
Analysis of the risk of use in multithreaded environments.

Note:
cAutoPtr _ALWAYS_ takes control of the memory it points to, and so should never be given the address of anything on the stack, or something that is deleted manually later.

Definition at line 51 of file cAutoPtr.h.


Constructor & Destructor Documentation

template<class TPtr>
n2l::cAutoPtr< TPtr >::cAutoPtr  )  [inline]
 

Standard boring default constructor.

Make the autopointer null by default.

Definition at line 84 of file cAutoPtr.h.

template<class TPtr>
n2l::cAutoPtr< TPtr >::cAutoPtr const cAutoPtr< TPtr > &  i_autoPtr  )  [inline]
 

Standard copy constructor.

Parameters:
i_autoPtr Another auto pointer to copy
See also:
assign()

Definition at line 94 of file cAutoPtr.h.

template<class TPtr>
n2l::cAutoPtr< TPtr >::cAutoPtr tValue *  io_ptr  )  [inline]
 

Construct & take control of a passed dumb pointer.

Parameters:
io_ptr The dumb pointer address to take control of
See also:
assign()

Definition at line 104 of file cAutoPtr.h.

template<class TPtr>
n2l::cAutoPtr< TPtr >::~cAutoPtr  )  [inline]
 

Deconstruct this pointer by releasing its reference.

See release() for more information.

Definition at line 113 of file cAutoPtr.h.


Member Function Documentation

template<class TPtr>
void n2l::cAutoPtr< TPtr >::_setRealPtr tValue *  i_newPtr  )  [inline]
 

Set the address of the actual internal instance.

This should never EVER be used by outside methods. It is provided publicly only to allow typcasting to other cAutoPtr instances of other types. Any use of these methods besides strictly in the typecast provided in this class is *strictly and expressly* not allowed. Any use of this method in any other way should be considered a critical error and may result in leaks, segfaults, and undefined behaviour. You have been warned. The more appropriate way to do this is with a friend template, which apparently isn't implemented correctly on some compilers.

Note:
DO NOT USE THIS METHOD, EVER
Parameters:
i_newPtr The address to set the internal data pointer to. Not that you should even know that.

Definition at line 303 of file cAutoPtr.h.

Referenced by n2l::cAutoPtr< cSubSysHolder >::as(), and n2l::cAutoPtr< cSubSysHolder >::operator cAutoPtr().

template<class TPtr>
void n2l::cAutoPtr< TPtr >::_setRealRefCountPtr tRefCount *  i_newRefCountPtr  )  [inline]
 

Set the address of the actual internal instance.

This should never EVER be used by outside methods. It is provided publicly only to allow typcasting to other cAutoPtr instances of other types. Any use of these methods besides strictly in the typecast provided in this class is *strictly and expressly* not allowed. Any use of this method in any other way should be considered a critical error and may result in leaks, segfaults, and undefined behaviour. You have been warned. The more appropriate way to do this is with a friend template, which apparently isn't implemented correctly on some compilers.

Note:
DO NOT USE THIS METHOD, EVER
Parameters:
i_newRefCountPtr The address to set the internal data pointer to. Not that you should even know that.

Definition at line 284 of file cAutoPtr.h.

Referenced by n2l::cAutoPtr< cSubSysHolder >::as(), and n2l::cAutoPtr< cSubSysHolder >::operator cAutoPtr().

template<class TPtr>
template<class TOtherPtr>
cAutoPtr<TOtherPtr> n2l::cAutoPtr< TPtr >::as  )  const [inline]
 

cAutoPtr to cAutoPtr dynamic_cast method which won't throw.

Ths method behaves exactly like the cAutoPtr assignment except it will not throw a bad cast exception instead returning a 0 autopointer.

Definition at line 313 of file cAutoPtr.h.

Referenced by n2l::vfsGetExecBinaryDir().

template<class TPtr>
void n2l::cAutoPtr< TPtr >::assign tValue *  i_ptr  )  [inline]
 

Take control of the provided pointer and begin reference counting it.

May be assigned NULL (or better, 0) to clear the current reference and become a 'null' cAutoPtr. Assigning memory this way will (as always) take control of the memory and delete it automatically when it leaves addressed scope.

Parameters:
i_ptr The dumb pointer to take control of. After assignment this dumb pointer should not be used in any way.

Definition at line 159 of file cAutoPtr.h.

template<class TPtr>
void n2l::cAutoPtr< TPtr >::assign const cAutoPtr< TPtr > &  i_autoPtr  )  [inline]
 

Share references with another cAutoPtr Appropriately calls release for its current reference, if any.

May be assigned a 'null' cAutoPtr to release itself and become a 'null' pointer itself.

Parameters:
i_autoPtr Another cAutoPtr to share references with.

Definition at line 132 of file cAutoPtr.h.

Referenced by n2l::cAutoPtr< cSubSysHolder >::cAutoPtr(), and n2l::cAutoPtr< cSubSysHolder >::operator=().

template<class TPtr>
const tRefCount n2l::cAutoPtr< TPtr >::count  )  const [inline]
 

Return the value of the internal reference counter.

Returns:
The value of the internal reference counter

Definition at line 121 of file cAutoPtr.h.

Referenced by n2l::cAutoPtr< cSubSysHolder >::release().

template<class TPtr>
tValue* const n2l::cAutoPtr< TPtr >::dumbPtr  )  const [inline]
 

Definition at line 383 of file cAutoPtr.h.

Referenced by n2l::cGuiCanvas::add(), and n2l::cParticle::textureID().

template<class TPtr>
const tBool n2l::cAutoPtr< TPtr >::equals const tValue *const   i_ptr  )  const [inline]
 

Compair a cAutoPtr to a dumb pointer of the same type.

Not terribly useful, this allows the compairison of a tValue pointer to the internal tValue pointer.

Note:
In general, if you're using this operator it means you're doing something naughty. Dumb pointers should never EVER be mixed with cAutoPtrs.
Parameters:
i_ptr A dumb pointer to compair the internal pointer to.
Returns:
True if the provided dumb pointer points to the same memory as this.

Definition at line 230 of file cAutoPtr.h.

template<class TPtr>
const tBool n2l::cAutoPtr< TPtr >::equals const cAutoPtr< TPtr > &  i_autoPtr  )  const [inline]
 

Compair two cAutoPtrs.

Parameters:
i_autoPtr Another cAutoPtr to compair this to.
Returns:
True if the two cAutoPtrs point to the same memory, false otherwise.

Definition at line 216 of file cAutoPtr.h.

Referenced by n2l::cAutoPtr< cSubSysHolder >::operator!=(), and n2l::cAutoPtr< cSubSysHolder >::operator==().

template<class TPtr>
const tBool n2l::cAutoPtr< TPtr >::isSet  )  const [inline]
 

Return the 'set' status of this autopointer.

Note:
This fucntion is utterly redundant, but some compilers seem to have issue with casting cAutoPtr<X> to bool, so we'll make a way that won't offend anybody

Definition at line 381 of file cAutoPtr.h.

Referenced by n2l::cGuiSButtonSelectBox::addButton(), n2l::cGuiButtonSelectBox::addButton(), n2l::cRSkyMobile::addSprite(), n2l::cAudioSource::cAudioSource(), n2l::cGuiACAddEffect::cGuiACAddEffect(), n2l::cGuiApp::cGuiApp(), n2l::cGuiSButtonSelectBox::clearButtons(), n2l::cGuiButtonSelectBox::clearButtons(), n2l::cGuiTextDisplay::cloneInto(), n2l::cGuiACIfProp::cloneInto(), n2l::cGuiACIf::cloneInto(), n2l::cRSkyMobileSprite::cRSkyMobileSprite(), n2l::cGuiTextDisplay::dimensionChanged(), n2l::cGuiSButtonSelectBox::dimensionChanged(), n2l::cGuiButtonSelectBox::dimensionChanged(), n2l::cGuiTextStyle::draw(), n2l::cGuiTextDisplay::draw(), n2l::cGuiSButtonSelectBox::draw(), n2l::cGuiModelView::draw(), n2l::cGuiButtonSelectBox::draw(), n2l::cGuiACIfProp::execute(), n2l::cGuiACIf::execute(), n2l::cGuiCanvas::get(), n2l::cGuiModelView::mesh(), n2l::cGuiElement::mustGet(), n2l::cGuiSound::play(), n2l::cGuiACIfProp::preserveAction(), n2l::cGuiACIf::preserveAction(), n2l::cGuiTextDisplay::propertyChanged(), n2l::cGuiCanvas::remove(), n2l::cRWavefrontModel::render(), n2l::cRVisualTriMesh::render(), n2l::cGuiApp::run(), n2l::cGuiTextDisplay::systemEvent(), n2l::cGuiSButtonSelectBox::systemEvent(), n2l::cGuiButtonSelectBox::systemEvent(), n2l::cGuiTextDisplay::systemEventOutside(), n2l::cGuiSButtonSelectBox::systemEventOutside(), n2l::cGuiButtonSelectBox::systemEventOutside(), n2l::cGuiModelView::update(), n2l::cPEmitter::updateInto(), n2l::vfsGetExecBinaryDir(), and n2l::cGuiTextStyle::wouldDraw().

template<class TPtr>
tValue& n2l::cAutoPtr< TPtr >::operator *  )  const [inline]
 

Dereference override to return the dereferenced internal pointer.

Returns:
The dereferenced internal pointer.

Definition at line 255 of file cAutoPtr.h.

template<class TPtr>
template<class TOtherPtr>
n2l::cAutoPtr< TPtr >::operator cAutoPtr  )  const [inline]
 

Definition at line 357 of file cAutoPtr.h.

template<class TPtr>
template<class TOtherPtr>
n2l::cAutoPtr< TPtr >::operator cAutoPtr  )  const [inline]
 

cAutoPtr to cAutoPtr dynamic_cast.

This allows the dymamic cast of one cAutoPtr<Child> to a cAutoPtr<Parent> and back in a simple assignment. The pointers internal to cAutoPtr should never be discovered and casted manually because it destroys the entire reason for using cAutoPtrs to begin with.

Note:
This isn't as expensive as your first instincts might tell you, since dynamic_casts will take place when you know a static_cast would be sufficient. The good news is that modern compilers will recognize obviously allowable transversals through an inheritance tree and optimize accordingly. This has been seen in practice, it isn't just theory.

Definition at line 340 of file cAutoPtr.h.

template<class TPtr>
n2l::cAutoPtr< TPtr >::operator tBool  )  const [inline]
 

Boolean type cast to return 0 or NULL if this cAutoPtr doesn't point to anything.

Allows the syntax of checking for a null pointer to be the same for cAutoPtrs as for dumb pointers.

Returns:
True if this cAutoPtr points to something, false otherwise.

Definition at line 267 of file cAutoPtr.h.

template<class TPtr>
const tBool n2l::cAutoPtr< TPtr >::operator!= const cAutoPtr< TPtr > &  i_autoPtr  )  const [inline]
 

Definition at line 248 of file cAutoPtr.h.

template<class TPtr>
const tBool n2l::cAutoPtr< TPtr >::operator!= const tValue *const   i_ptr  )  const [inline]
 

Definition at line 239 of file cAutoPtr.h.

template<class TPtr>
tValue* n2l::cAutoPtr< TPtr >::operator->  )  const [inline]
 

Provide access to internal class members.

Returns:
The standard result of accessing the internal dumb pointer.

Definition at line 260 of file cAutoPtr.h.

template<class TPtr>
const tBool n2l::cAutoPtr< TPtr >::operator< const cAutoPtr< TPtr > &  iAutoPtr  )  const [inline]
 

Definition at line 184 of file cAutoPtr.h.

template<class TPtr>
const tBool n2l::cAutoPtr< TPtr >::operator<= const cAutoPtr< TPtr > &  iAutoPtr  )  const [inline]
 

Definition at line 192 of file cAutoPtr.h.

template<class TPtr>
void n2l::cAutoPtr< TPtr >::operator= const cAutoPtr< TPtr > &  i_autoPtr  )  [inline]
 

An alias to the appropriate assign().

Definition at line 178 of file cAutoPtr.h.

template<class TPtr>
void n2l::cAutoPtr< TPtr >::operator= tValue *  i_ptr  )  [inline]
 

An alias to the appropriate assign().

Definition at line 175 of file cAutoPtr.h.

template<class TPtr>
const tBool n2l::cAutoPtr< TPtr >::operator== const cAutoPtr< TPtr > &  i_autoPtr  )  const [inline]
 

An alias to the appropriate equals() method.

Definition at line 244 of file cAutoPtr.h.

template<class TPtr>
const tBool n2l::cAutoPtr< TPtr >::operator== const tValue *const   i_ptr  )  const [inline]
 

An alias to the appropriate equals() method.

Definition at line 235 of file cAutoPtr.h.

template<class TPtr>
const tBool n2l::cAutoPtr< TPtr >::operator> const cAutoPtr< TPtr > &  iAutoPtr  )  const [inline]
 

Definition at line 180 of file cAutoPtr.h.

template<class TPtr>
const tBool n2l::cAutoPtr< TPtr >::operator>= const cAutoPtr< TPtr > &  iAutoPtr  )  const [inline]
 

Definition at line 188 of file cAutoPtr.h.

template<class TPtr>
void n2l::cAutoPtr< TPtr >::release  )  [inline]
 

Release the current reference (deleteing the reference counter and controlled memory as needed.

Make the cAutoPtr in effect, a null pointer.

Definition at line 200 of file cAutoPtr.h.

Referenced by n2l::cAutoPtr< cSubSysHolder >::assign(), and n2l::cAutoPtr< cSubSysHolder >::~cAutoPtr().


The documentation for this class was generated from the following file:
©2010 Aaron Cameron
Benchmarks