Various rstl fixes; continue CScriptMazeNode & CScriptPlatform

Former-commit-id: 7608f27ed2
This commit is contained in:
2022-09-18 13:51:07 -04:00
parent 0d94a5a5f3
commit f6f1040fff
25 changed files with 171 additions and 96 deletions

View File

@@ -14,14 +14,11 @@ struct random_access_iterator_tag : public bidirectional_iterator_tag {};
template < typename T, typename Vec, typename Alloc >
class const_pointer_iterator {
protected:
const T* current;
public:
typedef random_access_iterator_tag iterator_category;
const_pointer_iterator() : current(nullptr) {}
const_pointer_iterator(const T* begin) : current(begin) {}
const_pointer_iterator(const T* begin) : current(const_cast< T* >(begin)) {}
const_pointer_iterator& operator++() {
++current;
return *this;
@@ -30,10 +27,8 @@ public:
--current;
return *this;
}
T* get_pointer() const { return const_cast< T* >(current); }
const T& operator*() const { return *get_pointer(); }
const T* operator->() const { return get_pointer(); }
bool CheckValid() const { return current != nullptr; }
const T& operator*() const { return *current; }
const T* operator->() const { return current; }
bool operator==(const const_pointer_iterator& other) { return current == other.current; }
bool operator!=(const const_pointer_iterator& other) { return current != other.current; }
@@ -43,6 +38,9 @@ public:
friend const_pointer_iterator operator-(const const_pointer_iterator& x, int v) {
return const_pointer_iterator(x.current - v);
}
protected:
T* current;
};
template < typename T, typename Vec, typename Alloc >
@@ -50,34 +48,28 @@ class pointer_iterator : public const_pointer_iterator< T, Vec, Alloc > {
public:
pointer_iterator() : const_pointer_iterator< T, Vec, Alloc >(nullptr) {}
pointer_iterator(T* begin) : const_pointer_iterator< T, Vec, Alloc >(begin) {}
void operator=(const T& other) {
if (this->CheckValid()) {
*get_pointer() = other;
}
}
T* get_pointer() const { return const_cast< T* >(this->current); }
// T* operator*() const { if (CheckValid()) return get_pointer(); else return
// nullptr; }
T* operator->() const { return get_pointer(); }
void operator=(const T& other) { rstl::construct(this->current, other); }
T& operator*() { return *this->current; }
T* operator->() { return this->current; }
void destroy() const {
if (this->CheckValid()) {
rstl::destroy(get_pointer());
if (this->current != nullptr) {
rstl::destroy(this->current);
}
}
pointer_iterator& operator++() {
++current;
++this->current;
return *this;
}
pointer_iterator& operator--() {
--current;
--this->current;
return *this;
}
friend pointer_iterator operator+(const pointer_iterator& x, int v) {
return pointer_iterator(x.get_pointer() + v);
return pointer_iterator(x.current + v);
}
friend pointer_iterator operator-(const pointer_iterator& x, int v) {
return pointer_iterator(x.get_pointer() - v);
return pointer_iterator(x.current - v);
}
};
} // namespace rstl