Skip to content

Commit

Permalink
refactor(ptr): removed RawArrayPointer from lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliot MCNAB authored and Eliot MCNAB committed Nov 28, 2023
1 parent 7845d92 commit e44af10
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 179 deletions.
93 changes: 0 additions & 93 deletions include/RawArrayPointer.hpp

This file was deleted.

86 changes: 0 additions & 86 deletions pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,92 +78,6 @@ namespace mini {
UniquePtr<T> make_unique() {
return (UniquePtr<T>(new T()));
}


// =============================[ ACCESSORS ]============================ //

template<typename T>
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<typename T>
RawArrayPointer<T>::RawArrayPointer(std::size_t size) :
_size(size),
_data(static_cast<T*>(operator new[](size * sizeof(T))))
{}

template<typename T>
RawArrayPointer<T>::~RawArrayPointer(void) {
for (std::size_t index = 0; index < this->_size; index++) {
this->_data[index].~T();
}

delete (this->_data);
}

// =============================[ ACCESSORS ]============================ //

template<typename T>
const T* RawArrayPointer<T>::getPtr(void) const {
return (this->_data);
}

// =============================[ OPERATORS ]============================ //

template<typename T>
T& RawArrayPointer<T>::operator*(void) {
return (*this->_data);
}

template<typename T>
T* RawArrayPointer<T>::operator->(void) {
return (this->_data);
}

template<typename T>
T& RawArrayPointer<T>::operator[](std::size_t index) {
if (index >= this->_size)
throw (std::invalid_argument("index"));
return (this->_data[index]);
}

template<typename T>
RawArrayPointer<T>::operator T*(void) const {
return (this->_data);
}

template<typename T>
std::ostream& operator<<(std::ostream& os, RawArrayPointer<T>& rawArray) {
os << std::hex << rawArray.getPtr();
return (os);
}

// =============================[ FUNCTIONS ]============================ //

template<typename T>
void RawArrayPointer<T>::construct(std::size_t index, T& value) {
if (index >= this->_size)
throw (std::invalid_argument("index"));
new(this->_data[index]) T(value);
}
}

#endif

0 comments on commit e44af10

Please sign in to comment.