// Copyright (C) 2015 Jérôme Leclercq // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include namespace Nz { template SparsePtr::SparsePtr() { Reset(); } template SparsePtr::SparsePtr(T* ptr) { Reset(ptr); } template SparsePtr::SparsePtr(VoidPtr ptr, int stride) { Reset(ptr, stride); } template template SparsePtr::SparsePtr(const SparsePtr& ptr) { Reset(ptr); } template typename SparsePtr::VoidPtr SparsePtr::GetPtr() const { return m_ptr; } template int SparsePtr::GetStride() const { return m_stride; } template void SparsePtr::Reset() { SetPtr(nullptr); SetStride(0); } template void SparsePtr::Reset(T* ptr) { SetPtr(ptr); SetStride(sizeof(T)); } template void SparsePtr::Reset(VoidPtr ptr, int stride) { SetPtr(ptr); SetStride(stride); } template void SparsePtr::Reset(const SparsePtr& ptr) { SetPtr(ptr.GetPtr()); SetStride(ptr.GetStride()); } template template void SparsePtr::Reset(const SparsePtr& ptr) { static_assert(std::is_convertible::value, "Source type pointer cannot be implicitely converted to target type pointer"); SetPtr(static_cast(ptr.GetPtr())); SetStride(ptr.GetStride()); } template void SparsePtr::SetPtr(VoidPtr ptr) { m_ptr = reinterpret_cast(ptr); } template void SparsePtr::SetStride(int stride) { m_stride = stride; } template SparsePtr::operator bool() const { return m_ptr != nullptr; } template SparsePtr::operator T*() const { return reinterpret_cast(m_ptr); } template T& SparsePtr::operator*() const { return *reinterpret_cast(m_ptr); } template T* SparsePtr::operator->() const { return reinterpret_cast(m_ptr); } template T& SparsePtr::operator[](int index) const { return *reinterpret_cast(m_ptr + index*m_stride); } template SparsePtr SparsePtr::operator+(int count) const { return SparsePtr(m_ptr + count*m_stride, m_stride); } template SparsePtr SparsePtr::operator+(unsigned int count) const { return SparsePtr(m_ptr + count*m_stride, m_stride); } template SparsePtr SparsePtr::operator-(int count) const { return SparsePtr(m_ptr - count*m_stride, m_stride); } template SparsePtr SparsePtr::operator-(unsigned int count) const { return SparsePtr(m_ptr - count*m_stride, m_stride); } template std::ptrdiff_t SparsePtr::operator-(const SparsePtr& ptr) const { return (m_ptr - ptr.m_ptr)/m_stride; } template SparsePtr& SparsePtr::operator+=(int count) { m_ptr += count*m_stride; return *this; } template SparsePtr& SparsePtr::operator-=(int count) { m_ptr -= count*m_stride; return *this; } template SparsePtr& SparsePtr::operator++() { m_ptr += m_stride; return *this; } template SparsePtr SparsePtr::operator++(int) { // On fait une copie de l'objet SparsePtr tmp(*this); // On modifie l'objet operator++(); // On retourne la copie return tmp; } template SparsePtr& SparsePtr::operator--() { m_ptr -= m_stride; return *this; } template SparsePtr SparsePtr::operator--(int) { // On fait une copie de l'objet SparsePtr tmp(*this); // On modifie l'objet operator--(); // On retourne la copie return tmp; } template bool SparsePtr::operator==(const SparsePtr& ptr) const { return m_ptr == ptr.m_ptr; } template bool SparsePtr::operator!=(const SparsePtr& ptr) const { return m_ptr != ptr.m_ptr; } template bool SparsePtr::operator<(const SparsePtr& ptr) const { return m_ptr < ptr.m_ptr; } template bool SparsePtr::operator>(const SparsePtr& ptr) const { return m_ptr > ptr.m_ptr; } template bool SparsePtr::operator<=(const SparsePtr& ptr) const { return m_ptr <= ptr.m_ptr; } template bool SparsePtr::operator>=(const SparsePtr& ptr) const { return m_ptr >= ptr.m_ptr; } } namespace std { template struct iterator_traits> { using difference_type = ptrdiff_t; using iterator_category = random_access_iterator_tag; using reference = const T&; using pointer = const T*; using value_type = T; }; } #include