Add CAnimationDatabaseGame

This commit is contained in:
Henrique Gemignani Passos Lima
2022-11-17 17:46:10 +02:00
parent c29af5f67d
commit 1f30508cd3
22 changed files with 303 additions and 82 deletions

30
include/rstl/iterator.hpp Normal file
View File

@@ -0,0 +1,30 @@
#ifndef _RSTL_ITERATOR
#define _RSTL_ITERATOR
namespace rstl {
struct input_iterator_tag {};
struct output_iterator_tag {};
struct forward_iterator_tag : public input_iterator_tag {};
struct bidirectional_iterator_tag : public forward_iterator_tag {};
struct random_access_iterator_tag : public bidirectional_iterator_tag {};
template < typename It >
typename It::difference_type __distance(It first, It last, forward_iterator_tag) {
typename It::difference_type result = 0;
It it = first;
while (it != last) {
++result;
++it;
}
return result;
}
template < typename It >
typename It::difference_type distance(It first, It last) {
return __distance(first, last, typename It::iterator_category());
}
} // namespace rstl
#endif // _RSTL_ITERATOR

View File

@@ -5,13 +5,9 @@
#include "types.h"
#include "rstl/construct.hpp"
#include "rstl/iterator.hpp"
namespace rstl {
struct input_iterator_tag {};
struct output_iterator_tag {};
struct forward_iterator_tag : public input_iterator_tag {};
struct bidirectional_iterator_tag : public forward_iterator_tag {};
struct random_access_iterator_tag : public bidirectional_iterator_tag {};
template < typename T, typename Vec, typename Alloc >
class const_pointer_iterator {
@@ -131,10 +127,7 @@ inline typename It::difference_type __distance(It first, It last, random_access_
return last - first;
}
template < typename It >
inline typename It::difference_type distance(It first, It last) {
return __distance(first, last, typename It::iterator_category());
}
} // namespace rstl
#endif // _RSTL_POINTER_ITERATOR

View File

@@ -5,6 +5,7 @@
#include "rstl/pair.hpp"
#include "rstl/rmemory_allocator.hpp"
#include "rstl/iterator.hpp"
namespace rstl {
template < typename P >
@@ -82,6 +83,10 @@ private:
public:
struct const_iterator {
typedef int difference_type;
typedef forward_iterator_tag iterator_category;
typedef P* value_type;
node* mNode;
const header* mHeader;
// bool x8_;
@@ -136,6 +141,15 @@ public:
return const_iterator(nullptr, &x8_header, false);
}
iterator begin() {
// TODO
return iterator(x8_header.get_leftmost(), &x8_header, false);
}
iterator end() {
// TODO
return iterator(nullptr, &x8_header, false);
}
const_iterator find(const T& key) const {
node* n = x8_header.get_root();
node* needle = nullptr;
@@ -197,6 +211,8 @@ public:
x4_count = 0;
}
int size() const { return x4_count; }
private:
uchar x0_;
uchar x1_;

View File

@@ -24,11 +24,14 @@ public:
const_iterator begin() const { return inner.begin(); }
const_iterator end() const { return inner.end(); }
iterator begin() { return inner.begin(); }
iterator end() { return inner.end(); }
iterator find(const T& key) { return inner.find(key); }
const_iterator find(const T& key) const { return inner.find(key); }
void erase(iterator it) { inner.erase(it); }
int size() const { return inner.size(); }
private:
rep_type inner;
};

View File

@@ -48,7 +48,7 @@ public:
uninitialized_fill_n(xc_items, count, v);
}
vector(int count, const T& v, const Alloc& alloc);
vector(const vector& other) : x4_count(other.x4_count), x8_capacity(other.x8_capacity) {
if (other.x4_count == 0 && other.x8_capacity == 0) {
xc_items = nullptr;
@@ -65,7 +65,8 @@ public:
void reserve(int size);
void resize(int size, const T& in);
iterator insert(iterator it, const T& value); // TODO
iterator insert(iterator it, const T& value);
template < typename from_iterator >
iterator insert(iterator it, from_iterator begin, from_iterator end);
@@ -104,15 +105,7 @@ public:
protected:
template < typename In >
void insert_into(iterator at, int n, In in) {
// int insertAt = xc_items + n;
// TODO: finish
if (x8_capacity < n) {
int newCapacity = x8_capacity != 0 ? x8_capacity * 2 : 4;
T* newData;
x0_allocator.allocate(newData, newCapacity);
}
}
iterator insert_into(iterator at, int n, In in);
};
template < typename T, typename Alloc >
@@ -149,6 +142,50 @@ typename vector< T, Alloc >::iterator vector< T, Alloc >::insert(iterator it, co
return begin() + diff;
}
template < typename T, typename Alloc >
template < typename from_iterator >
typename vector< T, Alloc >::iterator vector< T, Alloc >::insert(iterator it, from_iterator begin,
from_iterator end) {
return insert_into(it, rstl::distance(begin, end), begin);
}
template < typename T, typename Alloc >
template < typename In >
typename vector< T, Alloc >::iterator vector< T, Alloc >::insert_into(iterator at, int n, In in) {
// TODO: correct
// An implementation can be found in CAnimationDatabaseGame.o
int newCount = x4_count + n;
if (newCount <= x8_capacity) {
int diffFromAt = at - begin();
int diff = x4_count - diffFromAt - 1;
for (int i = diff; 0 <= diff; --i) {
construct(xc_items + (diffFromAt + i), xc_items[i]);
destroy(data() + i);
}
uninitialized_copy_n(in, n, begin() + diffFromAt);
x4_count += n;
} else {
int newCapacity = x8_capacity != 0 ? x8_capacity * 2 : 4;
for (; newCapacity < newCount; newCapacity *= 2);
T* newData;
x0_allocator.allocate(newData, newCapacity);
int diffFromAt = at - begin();
uninitialized_copy_n(begin(), diffFromAt, newData);
uninitialized_copy_n(in, n, newData + diffFromAt);
uninitialized_copy_n(begin() + diffFromAt, x4_count - diffFromAt, newData + diffFromAt + n);
destroy(xc_items, xc_items + x4_count);
x0_allocator.deallocate(xc_items);
xc_items = newData;
x8_capacity = newCapacity;
x4_count += n;
}
}
template < typename T, typename Alloc >
vector< T, Alloc >& vector< T, Alloc >::operator=(const vector< T, Alloc >& other) {
if (this == &other)
@@ -177,7 +214,7 @@ typename vector< T, Alloc >::iterator vector< T, Alloc >::erase(iterator first,
destroy(first, last);
iterator start = begin();
int newCount = rstl::distance(first, start);
iterator moved = start + newCount;
for (iterator it = last; it != end(); ++it) {
construct(&*moved, *it);