From e44af10b3f50f56e04f7e63024889c63d1e3a65d Mon Sep 17 00:00:00 2001 From: Eliot MCNAB Date: Tue, 28 Nov 2023 20:44:27 +0100 Subject: [PATCH] refactor(ptr): removed RawArrayPointer from lib --- include/RawArrayPointer.hpp | 93 ------------------------------------- pointer.hpp | 86 ---------------------------------- 2 files changed, 179 deletions(-) delete mode 100644 include/RawArrayPointer.hpp diff --git a/include/RawArrayPointer.hpp b/include/RawArrayPointer.hpp deleted file mode 100644 index ff736ce..0000000 --- a/include/RawArrayPointer.hpp +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef RAW_ARRAY_POINTER_HPP -# define RAW_ARRAY_POINTER_HPP - -#include -#include -#include - -namespace mini { - template - class RawArrayPointer { - public: - explicit RawArrayPointer(std::size_t size); - ~RawArrayPointer(void); - - const T* getPtr(void) const; - - T& operator*(void); - T* operator->(void); - T& operator[](std::size_t index); - operator T*(void) const; - - void construct(std::size_t index, T& value); - - private: - const std::size_t _size; - T* const _data; - }; - - // ============================[ CONTRUCTOR ]============================ // - - template - RawArrayPointer::RawArrayPointer(std::size_t size) : - _size(size), - _data(static_cast(operator new[](size * sizeof(T)))) - {} - - template - RawArrayPointer::~RawArrayPointer(void) { - for (std::size_t index = 0; index < this->_size; index++) { - this->_data[index].~T(); - } - - delete (this->_data); - } - - // =============================[ ACCESSORS ]============================ // - - template - const T* RawArrayPointer::getPtr(void) const { - return (this->_data); - } - - // =============================[ OPERATORS ]============================ // - - template - T& RawArrayPointer::operator*(void) { - return (*this->_data); - } - - template - T* RawArrayPointer::operator->(void) { - return (this->_data); - } - - template - T& RawArrayPointer::operator[](std::size_t index) { - if (index >= this->_size) - throw (std::invalid_argument("index")); - return (this->_data[index]); - } - - template - RawArrayPointer::operator T*(void) const { - return (this->_data); - } - - template - std::ostream& operator<<(std::ostream& os, RawArrayPointer& rawArray) { - os << std::hex << rawArray.getPtr(); - return (os); - } - - // =============================[ FUNCTIONS ]============================ // - - template - void RawArrayPointer::construct(std::size_t index, T& value) { - if (index >= this->_size) - throw (std::invalid_argument("index")); - new(this->_data[index]) T(value); - } -} - -#endif diff --git a/pointer.hpp b/pointer.hpp index 7937092..8718542 100644 --- a/pointer.hpp +++ b/pointer.hpp @@ -78,92 +78,6 @@ namespace mini { UniquePtr make_unique() { return (UniquePtr(new T())); } - - - // =============================[ ACCESSORS ]============================ // - - template - class RawArrayPointer { - public: - explicit RawArrayPointer(std::size_t size); - ~RawArrayPointer(void); - - const T* getPtr(void) const; - - T& operator*(void); - T* operator->(void); - T& operator[](std::size_t index); - operator T*(void) const; - - void construct(std::size_t index, T& value); - - private: - const std::size_t _size; - T* const _data; - }; - - // ============================[ CONTRUCTOR ]============================ // - - template - RawArrayPointer::RawArrayPointer(std::size_t size) : - _size(size), - _data(static_cast(operator new[](size * sizeof(T)))) - {} - - template - RawArrayPointer::~RawArrayPointer(void) { - for (std::size_t index = 0; index < this->_size; index++) { - this->_data[index].~T(); - } - - delete (this->_data); - } - - // =============================[ ACCESSORS ]============================ // - - template - const T* RawArrayPointer::getPtr(void) const { - return (this->_data); - } - - // =============================[ OPERATORS ]============================ // - - template - T& RawArrayPointer::operator*(void) { - return (*this->_data); - } - - template - T* RawArrayPointer::operator->(void) { - return (this->_data); - } - - template - T& RawArrayPointer::operator[](std::size_t index) { - if (index >= this->_size) - throw (std::invalid_argument("index")); - return (this->_data[index]); - } - - template - RawArrayPointer::operator T*(void) const { - return (this->_data); - } - - template - std::ostream& operator<<(std::ostream& os, RawArrayPointer& rawArray) { - os << std::hex << rawArray.getPtr(); - return (os); - } - - // =============================[ FUNCTIONS ]============================ // - - template - void RawArrayPointer::construct(std::size_t index, T& value) { - if (index >= this->_size) - throw (std::invalid_argument("index")); - new(this->_data[index]) T(value); - } } #endif