First runnable render loop
This commit is contained in:
@@ -54,8 +54,8 @@ namespace Seele
|
||||
{
|
||||
_data = new T[other.allocated];
|
||||
assert(_data != nullptr);
|
||||
std::memcpy(_data, other._data, sizeof(T) * allocated);
|
||||
refreshIterators();
|
||||
std::copy(other.begin(), other.end(), beginIt);
|
||||
}
|
||||
Array(Array &&other) noexcept
|
||||
: allocated(std::move(other.allocated)), arraySize(std::move(other.arraySize))
|
||||
@@ -68,7 +68,7 @@ namespace Seele
|
||||
}
|
||||
Array &operator=(const Array &other) noexcept
|
||||
{
|
||||
if (*this != other)
|
||||
if (this != &other)
|
||||
{
|
||||
if (_data != nullptr)
|
||||
{
|
||||
@@ -77,14 +77,14 @@ namespace Seele
|
||||
allocated = other.allocated;
|
||||
arraySize = other.arraySize;
|
||||
_data = new T[other.allocated];
|
||||
std::memcpy(_data, other._data, sizeof(T) * allocated);
|
||||
refreshIterators();
|
||||
std::copy(other.begin(), other.end(), beginIt);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
Array &operator=(Array &&other) noexcept
|
||||
{
|
||||
if (*this != other)
|
||||
if (this != &other)
|
||||
{
|
||||
if (_data != nullptr)
|
||||
{
|
||||
@@ -94,6 +94,7 @@ namespace Seele
|
||||
arraySize = std::move(other.arraySize);
|
||||
_data = other._data;
|
||||
other._data = nullptr;
|
||||
refreshIterators();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,64 @@ public:
|
||||
tail = nullptr;
|
||||
beginIt = Iterator(root);
|
||||
endIt = Iterator(tail);
|
||||
size = 0;
|
||||
_size = 0;
|
||||
}
|
||||
List(const List& other)
|
||||
{
|
||||
//TODO: improve
|
||||
for(const auto& it : other)
|
||||
{
|
||||
add(it);
|
||||
}
|
||||
}
|
||||
List(List&& other)
|
||||
: root(std::move(other.root))
|
||||
, tail(std::move(other.tail))
|
||||
, beginIt(std::move(other.beginIt))
|
||||
, endIt(std::move(other.endIt))
|
||||
, _size(std::move(other._size))
|
||||
{
|
||||
}
|
||||
~List()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
List& operator=(const List& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(root != nullptr)
|
||||
{
|
||||
delete root;
|
||||
}
|
||||
if(tail != nullptr)
|
||||
{
|
||||
delete tail;
|
||||
}
|
||||
_size = 0;
|
||||
for(const auto& it : other)
|
||||
{
|
||||
add(it);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
List& operator=(List&& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(root != nullptr)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
root = other.root;
|
||||
tail = other.tail;
|
||||
beginIt = other.beginIt;
|
||||
endIt = other.endIt;
|
||||
_size = other._size;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <typename X>
|
||||
class IteratorBase
|
||||
{
|
||||
@@ -44,6 +96,29 @@ public:
|
||||
: node(i.node)
|
||||
{
|
||||
}
|
||||
IteratorBase(IteratorBase&& i)
|
||||
: node(std::move(i.node))
|
||||
{
|
||||
}
|
||||
~IteratorBase()
|
||||
{
|
||||
}
|
||||
IteratorBase& operator=(const IteratorBase& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
node = other.node;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
IteratorBase& operator=(IteratorBase&& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
node = std::move(other.node);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
reference operator*() const
|
||||
{
|
||||
return node->data;
|
||||
@@ -129,7 +204,7 @@ public:
|
||||
Iterator insertedElement(tail);
|
||||
tail = newTail;
|
||||
refreshIterators();
|
||||
size++;
|
||||
_size++;
|
||||
return insertedElement;
|
||||
}
|
||||
Iterator add(T&& value)
|
||||
@@ -147,12 +222,12 @@ public:
|
||||
Iterator insertedElement(tail);
|
||||
tail = newTail;
|
||||
refreshIterators();
|
||||
size++;
|
||||
_size++;
|
||||
return insertedElement;
|
||||
}
|
||||
Iterator remove(Iterator pos)
|
||||
{
|
||||
size--;
|
||||
_size--;
|
||||
Node *prev = pos.node->prev;
|
||||
Node *next = pos.node->next;
|
||||
if (prev == nullptr)
|
||||
@@ -177,7 +252,7 @@ public:
|
||||
}
|
||||
Iterator insert(Iterator pos, const T &value)
|
||||
{
|
||||
size++;
|
||||
_size++;
|
||||
if (root == nullptr)
|
||||
{
|
||||
root = new Node();
|
||||
@@ -212,20 +287,28 @@ public:
|
||||
}
|
||||
bool empty()
|
||||
{
|
||||
return size == 0;
|
||||
return _size == 0;
|
||||
}
|
||||
uint32 length()
|
||||
uint32 size()
|
||||
{
|
||||
return size;
|
||||
return _size;
|
||||
}
|
||||
Iterator begin()
|
||||
{
|
||||
return beginIt;
|
||||
}
|
||||
const Iterator begin() const
|
||||
{
|
||||
return beginIt;
|
||||
}
|
||||
Iterator end()
|
||||
{
|
||||
return endIt;
|
||||
}
|
||||
const Iterator end() const
|
||||
{
|
||||
return endIt;
|
||||
}
|
||||
|
||||
private:
|
||||
void refreshIterators()
|
||||
@@ -237,6 +320,6 @@ private:
|
||||
Node *tail;
|
||||
Iterator beginIt;
|
||||
Iterator endIt;
|
||||
uint32 size;
|
||||
uint32 _size;
|
||||
};
|
||||
} // namespace Seele
|
||||
+117
-2
@@ -27,12 +27,28 @@ private:
|
||||
Pair<K, V> pair;
|
||||
Node *leftChild;
|
||||
Node *rightChild;
|
||||
Node()
|
||||
: leftChild(nullptr), rightChild(nullptr), pair(K(), V())
|
||||
{
|
||||
}
|
||||
Node(const K &key)
|
||||
: leftChild(nullptr), rightChild(nullptr), pair(key, V())
|
||||
{
|
||||
}
|
||||
Node()
|
||||
: leftChild(nullptr), rightChild(nullptr), pair(K(), V())
|
||||
Node(const Node& other)
|
||||
: pair(other.pair.key, other.pair.value)
|
||||
{
|
||||
if(other.leftChild != nullptr)
|
||||
{
|
||||
leftChild = new Node(*other.leftChild);
|
||||
}
|
||||
if(other.rightChild != nullptr)
|
||||
{
|
||||
rightChild = new Node(*other.rightChild);
|
||||
}
|
||||
}
|
||||
Node(Node&& other)
|
||||
: leftChild(std::move(other.leftChild)), rightChild(std::move(other.rightChild))
|
||||
{
|
||||
}
|
||||
~Node()
|
||||
@@ -46,6 +62,45 @@ private:
|
||||
delete rightChild;
|
||||
}
|
||||
}
|
||||
Node& operator=(const Node& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(leftChild != nullptr)
|
||||
{
|
||||
delete leftChild;
|
||||
}
|
||||
if(rightChild != nullptr)
|
||||
{
|
||||
delete rightChild;
|
||||
}
|
||||
if(other.leftChild != nullptr)
|
||||
{
|
||||
leftChild = new Node(*other.leftChild);
|
||||
}
|
||||
if(other.rightChild != nullptr)
|
||||
{
|
||||
rightChild = new Node(*other.rightChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
Node& operator=(Node&& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(leftChild != nullptr)
|
||||
{
|
||||
delete leftChild;
|
||||
}
|
||||
if(rightChild != nullptr)
|
||||
{
|
||||
delete rightChild;
|
||||
}
|
||||
leftChild = std::move(other.leftChild);
|
||||
rightChild = std::move(other.rightChild);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
@@ -53,10 +108,48 @@ public:
|
||||
: root(nullptr), _size(0)
|
||||
{
|
||||
}
|
||||
Map(const Map& other)
|
||||
: root(new Node(*other.root)), _size(other._size)
|
||||
{
|
||||
refreshIterators();
|
||||
}
|
||||
Map(Map&& other)
|
||||
: root(std::move(other.root)), _size(other._size)
|
||||
{
|
||||
refreshIterators();
|
||||
}
|
||||
~Map()
|
||||
{
|
||||
delete root;
|
||||
}
|
||||
Map& operator=(const Map& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(root != nullptr)
|
||||
{
|
||||
delete root;
|
||||
}
|
||||
root = new Node(*other.root);
|
||||
_size = other.size;
|
||||
refreshIterators();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
Map& operator=(Map&& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
if(root != nullptr)
|
||||
{
|
||||
delete root;
|
||||
}
|
||||
root = new Node(std::move(*other.root));
|
||||
_size = std::move(other._size);
|
||||
refreshIterators();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
@@ -78,6 +171,28 @@ public:
|
||||
: node(i.node), traversal(i.traversal)
|
||||
{
|
||||
}
|
||||
Iterator(Iterator&& i)
|
||||
: node(std::move(i.node)), traversal(std::move(i.traversal))
|
||||
{
|
||||
}
|
||||
Iterator& operator=(const Iterator& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
node = other.node; // No copy, since no ownership
|
||||
traversal = other.traversal;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
Iterator& operator=(Iterator&& other)
|
||||
{
|
||||
if(this != &other)
|
||||
{
|
||||
node = std::move(other.node);
|
||||
traversal = std::move(other.traversal);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
reference operator*() const
|
||||
{
|
||||
return node->pair;
|
||||
|
||||
Reference in New Issue
Block a user