NL3D::CFastPtrListBase Class Reference

#include <fast_ptr_list.h>

Inheritance diagram for NL3D::CFastPtrListBase:

NL3D::CFastPtrList< T >

Detailed Description

This class store actually an array of void*, for very fast acces (list is slower because of RAM access). CFastPtrListBase advantages are the insert() and erase() are in O(1) Overhead Cost is 8 bytes per node + 4 bytes in the _Nodes array.
Author:
Lionel Berenguier

Nevrax France

Date:
2002

Definition at line 80 of file fast_ptr_list.h.

Public Member Functions

void ** begin ()
 Get the head on the array of elements. NULL if none.

 CFastPtrListBase (const CFastPtrListBase &o)
 CFastPtrListBase ()
 Constructor.

void clear ()
 clear the list

bool empty () const
void erase (CFastPtrListNode *node)
 erase an element in the list through its Node. No-op if the list does not have this element

void insert (void *element, CFastPtrListNode *node)
 insert an element in the list through its Node, unlinking older if necessary

CFastPtrListBaseoperator= (const CFastPtrListBase &o)
uint size () const
 get the number of elements

 ~CFastPtrListBase ()

Private Attributes

std::vector< void * > _Elements
std::vector< CFastPtrListNode * > _Nodes


Constructor & Destructor Documentation

NL3D::CFastPtrListBase::CFastPtrListBase  )  [inline]
 

Constructor.

Definition at line 84 of file fast_ptr_list.h.

00084 {}

NL3D::CFastPtrListBase::CFastPtrListBase const CFastPtrListBase o  )  [inline]
 

Definition at line 85 of file fast_ptr_list.h.

00085 {}

NL3D::CFastPtrListBase::~CFastPtrListBase  ) 
 

Definition at line 49 of file fast_ptr_list.cpp.

References clear().

00050 {
00051         clear();
00052 }


Member Function Documentation

void** NL3D::CFastPtrListBase::begin  )  [inline]
 

Get the head on the array of elements. NULL if none.

Reimplemented in NL3D::CFastPtrList< T >, NL3D::CFastPtrList< CQuadGridClipCluster >, NL3D::CFastPtrList< CPointLightModel >, and NL3D::CFastPtrList< CTransform >.

Definition at line 94 of file fast_ptr_list.h.

References _Elements.

00094 { if(_Elements.empty()) return NULL; else return &_Elements[0];}

void NL3D::CFastPtrListBase::clear  ) 
 

clear the list

Reimplemented in NL3D::CFastPtrList< T >, NL3D::CFastPtrList< CQuadGridClipCluster >, NL3D::CFastPtrList< CPointLightModel >, and NL3D::CFastPtrList< CTransform >.

Definition at line 56 of file fast_ptr_list.cpp.

References _Nodes, erase(), and size().

Referenced by ~CFastPtrListBase().

00057 {
00058         while(size())
00059         {
00060                 CFastPtrListNode *node= _Nodes[0];
00061                 erase(node);
00062         }
00063 }

bool NL3D::CFastPtrListBase::empty  )  const [inline]
 

Reimplemented in NL3D::CFastPtrList< T >, NL3D::CFastPtrList< CQuadGridClipCluster >, NL3D::CFastPtrList< CPointLightModel >, and NL3D::CFastPtrList< CTransform >.

Definition at line 97 of file fast_ptr_list.h.

References _Elements.

00097 {return _Elements.empty();}

void NL3D::CFastPtrListBase::erase CFastPtrListNode node  ) 
 

erase an element in the list through its Node. No-op if the list does not have this element

Reimplemented in NL3D::CFastPtrList< T >, NL3D::CFastPtrList< CQuadGridClipCluster >, NL3D::CFastPtrList< CPointLightModel >, and NL3D::CFastPtrList< CTransform >.

Definition at line 87 of file fast_ptr_list.cpp.

References _Elements, NL3D::CFastPtrListNode::_IndexInOwner, _Nodes, NL3D::CFastPtrListNode::_Owner, and uint.

Referenced by clear(), and NL3D::CFastPtrListNode::unlink().

00088 {
00089         // not mine?
00090         if(node->_Owner!=this)
00091                 return;
00092 
00093         // Take the indexes,
00094         uint    nodeIndex= node->_IndexInOwner;
00095         uint    lastIndex= _Nodes.size()-1;
00096 
00097         // swap the last element and the erased one.
00098         swap(_Elements[nodeIndex], _Elements[lastIndex]);
00099         swap(_Nodes[nodeIndex], _Nodes[lastIndex]);
00100         // change the swapped node index. NB: work also in the particular case nodeIndex==lastIndex
00101         _Nodes[nodeIndex]->_IndexInOwner= nodeIndex;
00102         // erase the last elements
00103         _Elements.pop_back();
00104         _Nodes.pop_back();
00105 
00106         // reset erased node.
00107         node->_Owner= NULL;
00108 }

void NL3D::CFastPtrListBase::insert void *  element,
CFastPtrListNode node
 

insert an element in the list through its Node, unlinking older if necessary

Definition at line 67 of file fast_ptr_list.cpp.

References _Elements, NL3D::CFastPtrListNode::_IndexInOwner, _Nodes, NL3D::CFastPtrListNode::_Owner, nlassert, and NL3D::CFastPtrListNode::unlink().

00068 {
00069         nlassert(element);
00070         nlassert(node);
00071 
00072         // if this node is already linked to me, no-op!
00073         if(node->_Owner==this)
00074                 return;
00075 
00076         // first unlink the node from its older list if any.
00077         node->unlink();
00078 
00079         // then add the elements to the list, and update node info
00080         _Elements.push_back(element);
00081         _Nodes.push_back(node);
00082         node->_Owner= this;
00083         node->_IndexInOwner= _Nodes.size()-1;
00084 }

CFastPtrListBase& NL3D::CFastPtrListBase::operator= const CFastPtrListBase o  )  [inline]
 

Definition at line 103 of file fast_ptr_list.h.

00103 {return *this;}

uint NL3D::CFastPtrListBase::size  )  const [inline]
 

get the number of elements

Reimplemented in NL3D::CFastPtrList< T >, NL3D::CFastPtrList< CQuadGridClipCluster >, NL3D::CFastPtrList< CPointLightModel >, and NL3D::CFastPtrList< CTransform >.

Definition at line 96 of file fast_ptr_list.h.

References _Elements, and uint.

Referenced by clear().

00096 {return _Elements.size();}


Field Documentation

std::vector<void*> NL3D::CFastPtrListBase::_Elements [private]
 

Definition at line 108 of file fast_ptr_list.h.

Referenced by begin(), empty(), erase(), insert(), and size().

std::vector<CFastPtrListNode*> NL3D::CFastPtrListBase::_Nodes [private]
 

Definition at line 109 of file fast_ptr_list.h.

Referenced by clear(), erase(), and insert().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 06:46:32 2004 for NeL by doxygen 1.3.6