Improved SparsePtr class
Added implicit conversion from a normal pointer to a sparse pointer Added implicit conversion to boolean Added implicit conversion to normal pointer Added support for const pointers Renamed Get/Set to GetPtr/SetPtr Former-commit-id: 32d5d2ec6a7b296c5b89b722de9ca142d5c64aae
This commit is contained in:
@@ -10,21 +10,34 @@
|
||||
///FIXME: Est-ce que SparsePtr est vraiment le meilleur nom pour cette classe ?
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
template<typename T>
|
||||
class NzSparsePtr
|
||||
{
|
||||
public:
|
||||
using BytePtr = typename std::conditional<std::is_const<T>::value, const nzUInt8*, nzUInt8*>::type;
|
||||
using VoidPtr = typename std::conditional<std::is_const<T>::value, const void*, void*>::type;
|
||||
|
||||
NzSparsePtr();
|
||||
NzSparsePtr(void* ptr, unsigned int stride);
|
||||
NzSparsePtr(T* ptr);
|
||||
NzSparsePtr(VoidPtr ptr, unsigned int stride);
|
||||
NzSparsePtr(const NzSparsePtr& ptr) = default;
|
||||
~NzSparsePtr() = default;
|
||||
|
||||
void* Get() const;
|
||||
VoidPtr GetPtr() const;
|
||||
unsigned int GetStride() const;
|
||||
void Set(void* ptr);
|
||||
|
||||
void Reset();
|
||||
void Reset(T* ptr);
|
||||
void Reset(VoidPtr ptr, unsigned int stride);
|
||||
void Reset(const NzSparsePtr& ptr);
|
||||
|
||||
void SetPtr(VoidPtr ptr);
|
||||
void SetStride(unsigned int stride);
|
||||
|
||||
operator bool() const;
|
||||
operator T*() const;
|
||||
T& operator*() const;
|
||||
T& operator->() const;
|
||||
T& operator[](unsigned int index) const;
|
||||
@@ -51,7 +64,7 @@ class NzSparsePtr
|
||||
NzSparsePtr& operator=(const NzSparsePtr& ptr) = default;
|
||||
|
||||
private:
|
||||
nzUInt8* m_ptr;
|
||||
BytePtr m_ptr;
|
||||
unsigned int m_stride;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user