CORGI
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
corgi::VectorPool< T >::VectorPoolReference Class Reference

A reference object for pointing into the vector pool. It acts as a pointer for vector pool elements and can be queried to check if it has become invalid. (i.e. If the element it pointed at has either been deallocated, or replaced with a new element). More...

#include <vector_pool.h>

Detailed Description

template<typename T>
class corgi::VectorPool< T >::VectorPoolReference

A reference object for pointing into the vector pool. It acts as a pointer for vector pool elements and can be queried to check if it has become invalid. (i.e. If the element it pointed at has either been deallocated, or replaced with a new element).

It also correctly handles situations where the underlying vector resizes, moving the elements around in memory.

Public Member Functions

 VectorPoolReference ()
 Default constructor for a VectorPoolReference.
 
 VectorPoolReference (VectorPool< T > *container, size_t index)
 Constructor for a VectorPoolReference given a VectorPool. More...
 
bool operator== (const VectorPoolReference &other) const
 Standard equality operator for VectorPoolReferences. More...
 
bool operator!= (const VectorPoolReference &other) const
 Standard inequality operator for VectorPoolReferences. More...
 
bool IsValid () const
 Verifies that the reference is still valid. More...
 
 operator bool () const
 An alternate way to check to make sure the reference is still valid. More...
 
T * operator-> ()
 The member access operator. More...
 
const T * operator-> () const
 Const member access operator. More...
 
T & operator* ()
 The dereference operator. More...
 
const T & operator* () const
 The const dereference operator. More...
 
T * ToPointer ()
 Get a direct pointer to the element the VectorPoolReference is referring to. More...
 
const T * ToPointer () const
 Get a direct pointer to the element the VectorPoolReference is referring to. More...
 
Iterator ToIterator () const
 Get an iterator that points to the element referenced by the VectorPoolReference. More...
 
size_t index () const
 Get the raw index into the underlying vector for this object. More...
 
VectorPool< T > * container () const
 Gets a pointer to the underlying vector for this object. More...
 

Friends

class VectorPool< T >
 
template<bool >
class IteratorTemplate
 

Constructor & Destructor Documentation

template<typename T>
corgi::VectorPool< T >::VectorPoolReference::VectorPoolReference ( VectorPool< T > *  container,
size_t  index 
)
inline

Constructor for a VectorPoolReference given a VectorPool.

Parameters
[in]containerA VectorPool to be referenced.
[in]indexThe index into the VectorPool's underlying vector.

Member Function Documentation

template<typename T>
VectorPool<T>* corgi::VectorPool< T >::VectorPoolReference::container ( ) const
inline

Gets a pointer to the underlying vector for this object.

Returns
Returns a VectorPool pointer to the underlying vector.
template<typename T>
size_t corgi::VectorPool< T >::VectorPoolReference::index ( ) const
inline

Get the raw index into the underlying vector for this object.

Returns
Returns a size_t corresponding to the index into the underlying vector.
template<typename T>
bool corgi::VectorPool< T >::VectorPoolReference::IsValid ( ) const
inline

Verifies that the reference is still valid.

Returns
Will return false if the object pointed to has been freed, even if the location was later filled with a new object.
template<typename T>
corgi::VectorPool< T >::VectorPoolReference::operator bool ( ) const
inline

An alternate way to check to make sure the reference is still valid.

This is similar to most smart pointer types, which supply an operator bool as syntactic sugar to check if they are nullptrs.

Returns
Will return false if the object pointed to has been freed, even if the location was later filled with a new object.
template<typename T>
bool corgi::VectorPool< T >::VectorPoolReference::operator!= ( const VectorPoolReference other) const
inline

Standard inequality operator for VectorPoolReferences.

Parameters
[in]otherThe other VectorPoolReference to compare in-equality to.
Returns
Returns false if the two VectorPoolReferences point to the same VectorPool with the same index. Otherwise, it returns true.
template<typename T>
T& corgi::VectorPool< T >::VectorPoolReference::operator* ( )
inline

The dereference operator.

Warning
Throws an assert if the VectorPoolReference is no longer valid. (i.e. If something has deleted the thing we are pointing to).
Returns
Returns a reference variable for the data the VectorPoolReference points to, allowing you to use VectorPoolReference like a pointer. (e.g. MyDataVariable = (*MyVectorPoolReference);)
template<typename T>
const T& corgi::VectorPool< T >::VectorPoolReference::operator* ( ) const
inline

The const dereference operator.

Note
Throws an assert if the VectorPoolReference is no longer valid. (i.e. If something has deleted the thing we are pointing to).
Returns
Returns a const reference variable for the data the VectorPoolReference points to, allowing you to use VectorPoolReference like a pointer. (e.g. MyDataVariable = (*MyVectorPoolReference);)
template<typename T>
T* corgi::VectorPool< T >::VectorPoolReference::operator-> ( )
inline

The member access operator.

Warning
Throws an assert if the VectorPoolReference is no longer valid. (i.e. If something has deleted the thing we were pointing to.)
Returns
Returns a pointer to the data that the VectorPoolReference is referring to, allowing you to use VectorPoolReferences like pointers, syntactically. (e.g. myVectorPoolReference->MyDataMember = x;)
template<typename T>
const T* corgi::VectorPool< T >::VectorPoolReference::operator-> ( ) const
inline

Const member access operator.

Warning
Throws an assert if the VectorPoolReference is no longer valid. (i.e. If something has deleted the thing we were pointing to).
Returns
Returns a pointer to the data that the VectorPoolReference is referring to, allowing you to use VectorPoolReferences like pointers, syntactically. (e.g. x = myVectorPoolReference->MyDataMember;)
template<typename T>
bool corgi::VectorPool< T >::VectorPoolReference::operator== ( const VectorPoolReference other) const
inline

Standard equality operator for VectorPoolReferences.

Parameters
[in]otherThe other VectorPoolReference to compare equality to.
Returns
Returns true if the two VectorPoolReferences point to the same VectorPool with the same index. Otherwise, it returns false.
template<typename T>
Iterator corgi::VectorPool< T >::VectorPoolReference::ToIterator ( ) const
inline

Get an iterator that points to the element referenced by the VectorPoolReference.

Returns
Returns an Iterator that points to the element referenced by the VectorPoolReference.
template<typename T>
T* corgi::VectorPool< T >::VectorPoolReference::ToPointer ( )
inline

Get a direct pointer to the element the VectorPoolReference is referring to.

Note
This pointer is not guaranteed to remain valid, since the vector may need to relocate the data in memory. It is recommended that when working with data, it be left as a VectorPoolReference, and only converted to a pointer when needed.
Returns
Returns a pointer to the element that the VectorPoolReference is referring to. If the VectorPoolReference is not referring to any data, it returns a nullptr.
template<typename T>
const T* corgi::VectorPool< T >::VectorPoolReference::ToPointer ( ) const
inline

Get a direct pointer to the element the VectorPoolReference is referring to.

Note
This pointer is not guaranteed to remain valid, since the vector may need to relocate the data in memory. It is recommended that when working with data, it be left as a VectorPoolReference, and only converted to a pointer when needed.
Returns
Returns a const pointer to the element that the VectorPoolReference is referring to. If the VectorPoolReference is not referring to any data, it returns a nullptr.

The documentation for this class was generated from the following file: