Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::SparsePtr< T > Class Template Reference

Core class that represents a pointer and the step between two elements. More...

Public Types

using BytePtr = typename std::conditional< std::is_const< T >::value, const UInt8 *, UInt8 * >::type
 
using VoidPtr = typename std::conditional< std::is_const< T >::value, const void *, void * >::type
 

Public Member Functions

 SparsePtr ()
 Constructs a SparsePtr object by default.
 
 SparsePtr (T *ptr)
 Constructs a SparsePtr object with a pointer. More...
 
 SparsePtr (VoidPtr ptr, int stride)
 Constructs a SparsePtr object with a pointer and a step. More...
 
 SparsePtr (VoidPtr ptr, std::size_t stride)
 Constructs a SparsePtr object with a pointer and a step. More...
 
template<typename U >
 SparsePtr (const SparsePtr< U > &ptr)
 Constructs a SparsePtr object from another type of SparsePtr. More...
 
 SparsePtr (const SparsePtr &ptr)=default
 
VoidPtr GetPtr () const
 Gets the original pointer. More...
 
int GetStride () const
 Gets the stride. More...
 
void Reset ()
 Resets the SparsePtr.
 
void Reset (T *ptr)
 Resets the SparsePtr with a pointer. More...
 
void Reset (VoidPtr ptr, int stride)
 Resets the SparsePtr with a pointer and its stride. More...
 
void Reset (const SparsePtr &ptr)
 Resets the SparsePtr with another SparsePtr. More...
 
template<typename U >
void Reset (const SparsePtr< U > &ptr)
 Resets the SparsePtr with another type of SparsePtr. More...
 
void SetPtr (VoidPtr ptr)
 Sets the pointer. More...
 
void SetStride (int stride)
 Sets the stride. More...
 
 operator bool () const
 Converts the pointer to bool. More...
 
 operator T* () const
 Converts the pointer to a pointer to the value. More...
 
T & operator* () const
 Dereferences the pointer. More...
 
T * operator-> () const
 Dereferences the pointer. More...
 
T & operator[] (int index) const
 Gets the ith element of the stride pointer. More...
 
SparsePtroperator= (const SparsePtr &ptr)=default
 
SparsePtr operator+ (int count) const
 Gets the SparsePtr with an offset. More...
 
SparsePtr operator+ (unsigned int count) const
 Gets the SparsePtr with an offset. More...
 
SparsePtr operator- (int count) const
 Gets the SparsePtr with an offset. More...
 
SparsePtr operator- (unsigned int count) const
 Gets the SparsePtr with an offset. More...
 
std::ptrdiff_t operator- (const SparsePtr &ptr) const
 Gets the difference between the two SparsePtr. More...
 
SparsePtroperator+= (int count)
 Gets the SparsePtr with an offset. More...
 
SparsePtroperator-= (int count)
 Gets the SparsePtr with an offset. More...
 
SparsePtroperator++ ()
 Gets the SparsePtr with the next element. More...
 
SparsePtr operator++ (int)
 Gets the SparsePtr with the next element. More...
 
SparsePtroperator-- ()
 Gets the SparsePtr with the previous element. More...
 
SparsePtr operator-- (int)
 Gets the SparsePtr with the previous element. More...
 
bool operator== (const SparsePtr &ptr) const
 Compares the SparsePtr to another one. More...
 
bool operator!= (const SparsePtr &ptr) const
 Compares the SparsePtr to another one. More...
 
bool operator< (const SparsePtr &ptr) const
 Compares the SparsePtr to another one. More...
 
bool operator> (const SparsePtr &ptr) const
 Compares the SparsePtr to another one. More...
 
bool operator<= (const SparsePtr &ptr) const
 Compares the SparsePtr to another one. More...
 
bool operator>= (const SparsePtr &ptr) const
 Compares the SparsePtr to another one. More...
 

Detailed Description

template<typename T>
class Nz::SparsePtr< T >

Core class that represents a pointer and the step between two elements.

Constructor & Destructor Documentation

◆ SparsePtr() [1/4]

template<typename T>
Nz::SparsePtr< T >::SparsePtr ( T *  ptr)

Constructs a SparsePtr object with a pointer.

Parameters
ptrPointer to data

◆ SparsePtr() [2/4]

template<typename T>
Nz::SparsePtr< T >::SparsePtr ( VoidPtr  ptr,
int  stride 
)

Constructs a SparsePtr object with a pointer and a step.

Parameters
ptrPointer to data
strideStep between two elements

◆ SparsePtr() [3/4]

template<typename T>
Nz::SparsePtr< T >::SparsePtr ( VoidPtr  ptr,
std::size_t  stride 
)

Constructs a SparsePtr object with a pointer and a step.

Parameters
ptrPointer to data
strideStep between two elements
Remarks
This constructor only exists because std::size_t is a frequent type for constructing this object, but stride may not be higher than int max

◆ SparsePtr() [4/4]

template<typename T >
template<typename U >
Nz::SparsePtr< T >::SparsePtr ( const SparsePtr< U > &  ptr)

Constructs a SparsePtr object from another type of SparsePtr.

Parameters
ptrPointer to data of type U to convert to type T

Member Function Documentation

◆ GetPtr()

template<typename T >
SparsePtr< T >::VoidPtr Nz::SparsePtr< T >::GetPtr ( ) const

Gets the original pointer.

Returns
Pointer to the first data

◆ GetStride()

template<typename T >
int Nz::SparsePtr< T >::GetStride ( ) const

Gets the stride.

Returns
Step between two elements

◆ operator bool()

template<typename T >
Nz::SparsePtr< T >::operator bool ( ) const
explicit

Converts the pointer to bool.

Returns
true if pointer is not nullptr

◆ operator T*()

template<typename T >
Nz::SparsePtr< T >::operator T* ( ) const

Converts the pointer to a pointer to the value.

Returns
The value of the pointer

◆ operator!=()

template<typename T >
bool Nz::SparsePtr< T >::operator!= ( const SparsePtr< T > &  ptr) const

Compares the SparsePtr to another one.

Returns
false if the two SparsePtr are pointing to the same memory
Parameters
ptrOther SparsePtr to compare with

◆ operator*()

template<typename T >
T & Nz::SparsePtr< T >::operator* ( ) const

Dereferences the pointer.

Returns
The dereferencing of the pointer

◆ operator+() [1/2]

template<typename T >
SparsePtr< T > Nz::SparsePtr< T >::operator+ ( int  count) const

Gets the SparsePtr with an offset.

Returns
A SparsePtr with the new stride
Parameters
countNumber of stride to do

◆ operator+() [2/2]

template<typename T >
SparsePtr< T > Nz::SparsePtr< T >::operator+ ( unsigned int  count) const

Gets the SparsePtr with an offset.

Returns
A SparsePtr with the new stride
Parameters
countNumber of stride to do

◆ operator++() [1/2]

template<typename T >
SparsePtr< T > & Nz::SparsePtr< T >::operator++ ( )

Gets the SparsePtr with the next element.

Returns
A reference to this pointer updated

◆ operator++() [2/2]

template<typename T >
SparsePtr< T > Nz::SparsePtr< T >::operator++ ( int  )

Gets the SparsePtr with the next element.

Returns
A SparsePtr not updated

◆ operator+=()

template<typename T >
SparsePtr< T > & Nz::SparsePtr< T >::operator+= ( int  count)

Gets the SparsePtr with an offset.

Returns
A reference to this pointer with the new stride
Parameters
countNumber of stride to do

◆ operator-() [1/3]

template<typename T >
SparsePtr< T > Nz::SparsePtr< T >::operator- ( int  count) const

Gets the SparsePtr with an offset.

Returns
A SparsePtr with the new stride
Parameters
countNumber of stride to do

◆ operator-() [2/3]

template<typename T >
SparsePtr< T > Nz::SparsePtr< T >::operator- ( unsigned int  count) const

Gets the SparsePtr with an offset.

Returns
A SparsePtr with the new stride
Parameters
countNumber of stride to do

◆ operator-() [3/3]

template<typename T >
std::ptrdiff_t Nz::SparsePtr< T >::operator- ( const SparsePtr< T > &  ptr) const

Gets the difference between the two SparsePtr.

Returns
The difference of elements: ptr - this->ptr
Parameters
ptrOther ptr

◆ operator--() [1/2]

template<typename T >
SparsePtr< T > & Nz::SparsePtr< T >::operator-- ( )

Gets the SparsePtr with the previous element.

Returns
A reference to this pointer updated

◆ operator--() [2/2]

template<typename T >
SparsePtr< T > Nz::SparsePtr< T >::operator-- ( int  )

Gets the SparsePtr with the previous element.

Returns
A SparsePtr not updated

◆ operator-=()

template<typename T >
SparsePtr< T > & Nz::SparsePtr< T >::operator-= ( int  count)

Gets the SparsePtr with an offset.

Returns
A reference to this pointer with the new stride
Parameters
countNumber of stride to do

◆ operator->()

template<typename T >
T * Nz::SparsePtr< T >::operator-> ( ) const

Dereferences the pointer.

Returns
The dereferencing of the pointer

◆ operator<()

template<typename T >
bool Nz::SparsePtr< T >::operator< ( const SparsePtr< T > &  ptr) const

Compares the SparsePtr to another one.

Returns
true if the first SparsePtr is pointing to memory inferior to the second one
Parameters
ptrOther SparsePtr to compare with

◆ operator<=()

template<typename T >
bool Nz::SparsePtr< T >::operator<= ( const SparsePtr< T > &  ptr) const

Compares the SparsePtr to another one.

Returns
true if the first SparsePtr is pointing to memory inferior or equal to the second one
Parameters
ptrOther SparsePtr to compare with

◆ operator==()

template<typename T >
bool Nz::SparsePtr< T >::operator== ( const SparsePtr< T > &  ptr) const

Compares the SparsePtr to another one.

Returns
true if the two SparsePtr are pointing to the same memory
Parameters
ptrOther SparsePtr to compare with

◆ operator>()

template<typename T >
bool Nz::SparsePtr< T >::operator> ( const SparsePtr< T > &  ptr) const

Compares the SparsePtr to another one.

Returns
true if the first SparsePtr is pointing to memory superior to the second one
Parameters
ptrOther SparsePtr to compare with

◆ operator>=()

template<typename T >
bool Nz::SparsePtr< T >::operator>= ( const SparsePtr< T > &  ptr) const

Compares the SparsePtr to another one.

Returns
true if the first SparsePtr is pointing to memory superior or equal to the second one
Parameters
ptrOther SparsePtr to compare with

◆ operator[]()

template<typename T >
T & Nz::SparsePtr< T >::operator[] ( int  index) const

Gets the ith element of the stride pointer.

Returns
A reference to the ith value
Parameters
indexNumber of stride to do

◆ Reset() [1/4]

template<typename T>
void Nz::SparsePtr< T >::Reset ( T *  ptr)

Resets the SparsePtr with a pointer.

Parameters
ptrPointer to data
Remarks
stride is set to sizeof(T)

◆ Reset() [2/4]

template<typename T>
void Nz::SparsePtr< T >::Reset ( VoidPtr  ptr,
int  stride 
)

Resets the SparsePtr with a pointer and its stride.

Parameters
ptrPointer to data
strideStep between two elements

◆ Reset() [3/4]

template<typename T>
void Nz::SparsePtr< T >::Reset ( const SparsePtr< T > &  ptr)

Resets the SparsePtr with another SparsePtr.

Parameters
ptrAnother sparsePtr

◆ Reset() [4/4]

template<typename T >
template<typename U >
void Nz::SparsePtr< T >::Reset ( const SparsePtr< U > &  ptr)

Resets the SparsePtr with another type of SparsePtr.

Parameters
ptrAnother sparsePtr

◆ SetPtr()

template<typename T >
void Nz::SparsePtr< T >::SetPtr ( VoidPtr  ptr)

Sets the pointer.

Parameters
ptrPointer to data

◆ SetStride()

template<typename T >
void Nz::SparsePtr< T >::SetStride ( int  stride)

Sets the stride.

Parameters
strideStep between two elements

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