-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the definition of the DynamicArray class. Basic completion. S…
…ome of the iterators were not completed correctly.
- Loading branch information
Showing
11 changed files
with
1,100 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// Copyright 2024 AQ authors, All Rights Reserved. | ||
// This program is licensed under the AQ License. You can find the AQ license in | ||
// the root directory. | ||
|
||
#include "compiler/dynamic_array/const_iterator.h" | ||
|
||
#include <cstddef> | ||
|
||
#include "debugger/debugger.h" | ||
|
||
namespace Aq { | ||
template <typename T> | ||
Compiler::DynamicArray<T>::const_iterator::const_iterator(DynamicArray<T>* array, | ||
std::size_t index) { | ||
array_ = array; | ||
index_ = index; | ||
data_ = array_->at(index); | ||
} | ||
template <typename T> | ||
Compiler::DynamicArray<T>::const_iterator::~const_iterator() = default; | ||
|
||
template <typename T> | ||
const T& Compiler::DynamicArray<T>::const_iterator::operator*() const { | ||
return data_; | ||
} | ||
template <typename T> | ||
const T* Compiler::DynamicArray<T>::const_iterator::operator->() const { | ||
return &data_; | ||
} | ||
|
||
template <typename T> | ||
Compiler::DynamicArray<T>::const_iterator& | ||
Compiler::DynamicArray<T>::const_iterator::operator++() { | ||
return *this += 1; | ||
} | ||
template <typename T> | ||
Compiler::DynamicArray<T>::const_iterator | ||
Compiler::DynamicArray<T>::const_iterator::operator++(int) { | ||
const_iterator copy = *this; | ||
*this += 1; | ||
return copy; | ||
} | ||
|
||
template <typename T> | ||
Compiler::DynamicArray<T>::const_iterator& | ||
Compiler::DynamicArray<T>::const_iterator::operator--() { | ||
return *this -= 1; | ||
} | ||
template <typename T> | ||
Compiler::DynamicArray<T>::const_iterator | ||
Compiler::DynamicArray<T>::const_iterator::operator--(int) { | ||
const_iterator copy = *this; | ||
*this -= 1; | ||
return copy; | ||
} | ||
|
||
template <typename T> | ||
Compiler::DynamicArray<T>::const_iterator | ||
Compiler::DynamicArray<T>::const_iterator::operator+(std::ptrdiff_t n) const { | ||
const_iterator copy = *this; | ||
copy += n; | ||
return copy; | ||
} | ||
template <typename T> | ||
Compiler::DynamicArray<T>::const_iterator& | ||
Compiler::DynamicArray<T>::const_iterator::operator+=(std::ptrdiff_t n) { | ||
index_ += n; | ||
if (index_ > array_->size()) { | ||
Debugger error(Debugger::Level::ERROR, | ||
"Aq::Compiler::DynamicArray::const_iterator::operator++", | ||
"operator++_IndexError", "Index out of range.", nullptr); | ||
} | ||
if (index_ == array_->size()) { | ||
data_ = T(); | ||
return *this; | ||
} | ||
data_ = array_->at(index_); | ||
return *this; | ||
} | ||
|
||
template <typename T> | ||
Compiler::DynamicArray<T>::const_iterator | ||
Compiler::DynamicArray<T>::const_iterator::operator-(std::ptrdiff_t n) const { | ||
const_iterator copy = *this; | ||
copy -= n; | ||
return copy; | ||
} | ||
template <typename T> | ||
Compiler::DynamicArray<T>::const_iterator | ||
Compiler::DynamicArray<T>::const_iterator::operator-=(std::ptrdiff_t n) { | ||
index_ -= n; | ||
if (index_ < 0) { | ||
Debugger error(Debugger::Level::ERROR, | ||
"Aq::Compiler::DynamicArray::const_iterator::operator--", | ||
"operator--_IndexError", "Index out of range.", nullptr); | ||
} | ||
if (index_ == array_->size()) { | ||
data_ = T(); | ||
return *this; | ||
} | ||
data_ = array_->at(index_); | ||
return *this; | ||
} | ||
|
||
template <typename T> | ||
Compiler::DynamicArray<T>::const_iterator& | ||
Compiler::DynamicArray<T>::const_iterator::operator[](std::size_t n) { | ||
std::size_t original_index = index_; | ||
index_ = n; | ||
if (index_ > array_->size() || index_ < 0) { | ||
Debugger error(Debugger::Level::ERROR, | ||
"Aq::Compiler::DynamicArray::const_iterator::operator[]", | ||
"operator[]_IndexError", "Index out of range.", nullptr); | ||
index_ = original_index; | ||
return *this; | ||
} | ||
if (index_ == array_->size()) { | ||
data_ = T(); | ||
return *this; | ||
} | ||
data_ = array_->at(index_); | ||
return *this; | ||
} | ||
|
||
template <typename T> | ||
bool Compiler::DynamicArray<T>::const_iterator::operator==( | ||
const const_iterator& other) const { | ||
return array_ == other.array_ && index_ == other.index_; | ||
} | ||
template <typename T> | ||
bool Compiler::DynamicArray<T>::const_iterator::operator!=( | ||
const const_iterator& other) const { | ||
return !(*this == other); | ||
} | ||
|
||
template <typename T> | ||
std::ptrdiff_t Compiler::DynamicArray<T>::const_iterator::operator-( | ||
const const_iterator& other) const { | ||
return index_ - other.index_; | ||
} | ||
} // namespace Aq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2024 AQ authors, All Rights Reserved. | ||
// This program is licensed under the AQ License. You can find the AQ license in | ||
// the root directory. | ||
|
||
#ifndef AQ_COMPILER_DYNAMIC_ARRAY_CONST_ITERATOR_H_ | ||
#define AQ_COMPILER_DYNAMIC_ARRAY_CONST_ITERATOR_H_ | ||
|
||
#include "compiler/compiler.h" | ||
#include "compiler/dynamic_array/dynamic_array.h" | ||
|
||
#include <cstddef> | ||
|
||
namespace Aq { | ||
template <typename T> | ||
class Compiler::DynamicArray<T>::const_iterator { | ||
public: | ||
const_iterator(DynamicArray<T>* array, std::size_t index); | ||
~const_iterator(); | ||
|
||
const_iterator(const const_iterator&) = default; | ||
const_iterator(const_iterator&&) noexcept = default; | ||
const_iterator& operator=(const const_iterator&) = default; | ||
const_iterator& operator=(const_iterator&&) noexcept = default; | ||
|
||
const T& operator*() const; | ||
const T* operator->() const; | ||
|
||
const_iterator& operator++(); | ||
const_iterator operator++(int); | ||
|
||
const_iterator& operator--(); | ||
const_iterator operator--(int); | ||
|
||
const_iterator operator+(std::ptrdiff_t n) const; | ||
const_iterator& operator+=(std::ptrdiff_t n); | ||
|
||
const_iterator operator-(std::ptrdiff_t n) const; | ||
const_iterator operator-=(std::ptrdiff_t n); | ||
|
||
const_iterator& operator[](std::size_t n); | ||
|
||
bool operator==(const const_iterator& other) const; | ||
bool operator!=(const const_iterator& other) const; | ||
|
||
std::ptrdiff_t operator-(const const_iterator& other) const; | ||
|
||
private: | ||
DynamicArray<T>* array_; | ||
std::size_t index_; | ||
const T& data_; | ||
}; | ||
} // namespace Aq | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// Copyright 2024 AQ authors, All Rights Reserved. | ||
// This program is licensed under the AQ License. You can find the AQ license in | ||
// the root directory. | ||
|
||
#include "compiler/dynamic_array/const_reverse_iterator.h" | ||
|
||
#include <cstddef> | ||
|
||
#include "debugger/debugger.h" | ||
|
||
namespace Aq { | ||
template <typename T> | ||
Compiler::DynamicArray<T>::const_reverse_iterator::const_reverse_iterator(DynamicArray<T>* array, | ||
std::size_t index) { | ||
array_ = array; | ||
index_ = index; | ||
data_ = array_->at(index); | ||
} | ||
template <typename T> | ||
Compiler::DynamicArray<T>::const_reverse_iterator::~const_reverse_iterator() = default; | ||
|
||
template <typename T> | ||
T& Compiler::DynamicArray<T>::const_reverse_iterator::operator*() const { | ||
return data_; | ||
} | ||
template <typename T> | ||
T* Compiler::DynamicArray<T>::const_reverse_iterator::operator->() const { | ||
return &data_; | ||
} | ||
|
||
template <typename T> | ||
Compiler::DynamicArray<T>::const_reverse_iterator& | ||
Compiler::DynamicArray<T>::const_reverse_iterator::operator++() { | ||
return *this += 1; | ||
} | ||
template <typename T> | ||
Compiler::DynamicArray<T>::const_reverse_iterator | ||
Compiler::DynamicArray<T>::const_reverse_iterator::operator++(int) { | ||
const_reverse_iterator copy = *this; | ||
*this += 1; | ||
return copy; | ||
} | ||
|
||
template <typename T> | ||
Compiler::DynamicArray<T>::const_reverse_iterator& | ||
Compiler::DynamicArray<T>::const_reverse_iterator::operator--() { | ||
return *this -= 1; | ||
} | ||
template <typename T> | ||
Compiler::DynamicArray<T>::const_reverse_iterator | ||
Compiler::DynamicArray<T>::const_reverse_iterator::operator--(int) { | ||
const_reverse_iterator copy = *this; | ||
*this -= 1; | ||
return copy; | ||
} | ||
|
||
template <typename T> | ||
Compiler::DynamicArray<T>::const_reverse_iterator | ||
Compiler::DynamicArray<T>::const_reverse_iterator::operator+(std::ptrdiff_t n) const { | ||
const_reverse_iterator copy = *this; | ||
copy += n; | ||
return copy; | ||
} | ||
template <typename T> | ||
Compiler::DynamicArray<T>::const_reverse_iterator& | ||
Compiler::DynamicArray<T>::const_reverse_iterator::operator+=(std::ptrdiff_t n) { | ||
index_ += n; | ||
if (index_ > array_->size()) { | ||
Debugger error(Debugger::Level::ERROR, | ||
"Aq::Compiler::DynamicArray::const_reverse_iterator::operator++", | ||
"operator++_IndexError", "Index out of range.", nullptr); | ||
} | ||
if (index_ == array_->size()) { | ||
data_ = T(); | ||
return *this; | ||
} | ||
data_ = array_->at(index_); | ||
return *this; | ||
} | ||
|
||
template <typename T> | ||
Compiler::DynamicArray<T>::const_reverse_iterator | ||
Compiler::DynamicArray<T>::const_reverse_iterator::operator-(std::ptrdiff_t n) const { | ||
const_reverse_iterator copy = *this; | ||
copy -= n; | ||
return copy; | ||
} | ||
template <typename T> | ||
Compiler::DynamicArray<T>::const_reverse_iterator | ||
Compiler::DynamicArray<T>::const_reverse_iterator::operator-=(std::ptrdiff_t n) { | ||
index_ -= n; | ||
if (index_ < 0) { | ||
Debugger error(Debugger::Level::ERROR, | ||
"Aq::Compiler::DynamicArray::const_reverse_iterator::operator--", | ||
"operator--_IndexError", "Index out of range.", nullptr); | ||
} | ||
if (index_ == array_->size()) { | ||
data_ = T(); | ||
return *this; | ||
} | ||
data_ = array_->at(index_); | ||
return *this; | ||
} | ||
|
||
template <typename T> | ||
Compiler::DynamicArray<T>::const_reverse_iterator& | ||
Compiler::DynamicArray<T>::const_reverse_iterator::operator[](std::size_t n) { | ||
std::size_t original_index = index_; | ||
index_ = n; | ||
if (index_ > array_->size() || index_ < 0) { | ||
Debugger error(Debugger::Level::ERROR, | ||
"Aq::Compiler::DynamicArray::const_reverse_iterator::operator[]", | ||
"operator[]_IndexError", "Index out of range.", nullptr); | ||
index_ = original_index; | ||
return *this; | ||
} | ||
if (index_ == array_->size()) { | ||
data_ = T(); | ||
return *this; | ||
} | ||
data_ = array_->at(index_); | ||
return *this; | ||
} | ||
|
||
template <typename T> | ||
bool Compiler::DynamicArray<T>::const_reverse_iterator::operator==( | ||
const const_reverse_iterator& other) const { | ||
return array_ == other.array_ && index_ == other.index_; | ||
} | ||
template <typename T> | ||
bool Compiler::DynamicArray<T>::const_reverse_iterator::operator!=( | ||
const const_reverse_iterator& other) const { | ||
return !(*this == other); | ||
} | ||
|
||
template <typename T> | ||
std::ptrdiff_t Compiler::DynamicArray<T>::const_reverse_iterator::operator-( | ||
const const_reverse_iterator& other) const { | ||
return index_ - other.index_; | ||
} | ||
} // namespace Aq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2024 AQ authors, All Rights Reserved. | ||
// This program is licensed under the AQ License. You can find the AQ license in | ||
// the root directory. | ||
|
||
#ifndef AQ_COMPILER_DYNAMIC_ARRAY_ITERATOR_H_ | ||
#define AQ_COMPILER_DYNAMIC_ARRAY_ITERATOR_H_ | ||
|
||
#include "compiler/compiler.h" | ||
#include "compiler/dynamic_array/dynamic_array.h" | ||
|
||
#include <cstddef> | ||
|
||
namespace Aq { | ||
template <typename T> | ||
class Compiler::DynamicArray<T>::const_reverse_iterator { | ||
public: | ||
const_reverse_iterator(DynamicArray<T>* array, std::size_t index); | ||
~const_reverse_iterator(); | ||
|
||
const_reverse_iterator(const const_reverse_iterator&) = default; | ||
const_reverse_iterator(const_reverse_iterator&&) noexcept = default; | ||
const_reverse_iterator& operator=(const const_reverse_iterator&) = default; | ||
const_reverse_iterator& operator=(const_reverse_iterator&&) noexcept = default; | ||
|
||
T& operator*() const; | ||
T* operator->() const; | ||
|
||
const_reverse_iterator& operator++(); | ||
const_reverse_iterator operator++(int); | ||
|
||
const_reverse_iterator& operator--(); | ||
const_reverse_iterator operator--(int); | ||
|
||
const_reverse_iterator operator+(std::ptrdiff_t n) const; | ||
const_reverse_iterator& operator+=(std::ptrdiff_t n); | ||
|
||
const_reverse_iterator operator-(std::ptrdiff_t n) const; | ||
const_reverse_iterator operator-=(std::ptrdiff_t n); | ||
|
||
const_reverse_iterator& operator[](std::size_t n); | ||
|
||
bool operator==(const const_reverse_iterator& other) const; | ||
bool operator!=(const const_reverse_iterator& other) const; | ||
|
||
std::ptrdiff_t operator-(const const_reverse_iterator& other) const; | ||
|
||
private: | ||
DynamicArray<T>* array_; | ||
std::size_t index_; | ||
T& data_; | ||
}; | ||
} // namespace Aq | ||
|
||
#endif |
Oops, something went wrong.