std-vector equivalent

This commit is contained in:
LagoLunatic
2025-04-04 19:44:14 -04:00
parent f9a862ae73
commit 4de0fd7eff
7 changed files with 621 additions and 69 deletions
+8 -10
View File
@@ -7,7 +7,7 @@
#include "dolphin/types.h"
namespace JGadget {
/* 802BFF14-802BFF1C .text extend_default__Q27JGadget6vectorFUlUlUl */
u32 vector::extend_default(u32, u32 param_2, u32) {
return param_2 * 2;
@@ -15,26 +15,24 @@ u32 vector::extend_default(u32, u32 param_2, u32) {
/* 802BFF1C-802BFF48 .text __ct__Q27JGadget20TVector_pointer_voidFRCQ27JGadget14TAllocator<Pv> */
TVector_pointer_void::TVector_pointer_void(const TAllocator<void*>& allocator) {
_00 = allocator._00;
mAllocator = allocator;
mBegin = NULL;
mEnd = mBegin;
_0C = NULL;
mCapacity = 0;
mExtend = vector::extend_default;
}
/* 802BFF48-802BFFF0 .text __dt__Q27JGadget20TVector_pointer_voidFv */
TVector_pointer_void::~TVector_pointer_void() {
/* Nonmatching */
}
TVector_pointer_void::~TVector_pointer_void() {}
/* 802BFFF0-802C0010 .text insert__Q27JGadget20TVector_pointer_voidFPPvRCPv */
void TVector_pointer_void::insert(void**, void* const&) {
/* Nonmatching */
void** TVector_pointer_void::insert(void** position, void* const& value) {
return TVector<void*>::insert(position, value);
}
/* 802C0010-802C0068 .text erase__Q27JGadget20TVector_pointer_voidFPPvPPv */
void TVector_pointer_void::erase(void**, void**) {
/* Nonmatching */
void** TVector_pointer_void::erase(void** start, void** end) {
return TVector<void*>::erase(start, end);
}
// /* 802C0068-802C00D8 .text insert__Q27JGadget38TVector<Pv,Q27JGadget14TAllocator<Pv>>FPPvUlRCPv */
@@ -1,9 +1,29 @@
#ifndef MSL_ALGORITHM_H_
#define MSL_ALGORITHM_H_
#include <iterator.h>
namespace std {
template <class ForwardIterator, class T>
ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T& val);
ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, const T& val) {
typedef typename iterator_traits<ForwardIterator>::difference_type difference_type;
difference_type len = std::distance(first, last);
while (len > 0) {
ForwardIterator i = first;
difference_type step = len / 2;
std::advance(i, step);
if (*i < val) {
first = ++i;
len -= step + 1;
} else {
len = step;
}
}
return first;
}
template <class ForwardIterator, class T>
ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, const T& val);
@@ -38,11 +58,62 @@ void __fill(ForwardIt first, ForwardIt last, const T& value, std::random_access_
*/
template<class ForwardIt, class T>
void fill(ForwardIt first, ForwardIt last, const T& value) {
inline void fill(ForwardIt first, ForwardIt last, const T& value) {
for (; first != last; ++first){
*first = value;
}
}
template<class InputIt, class OutputIt>
inline OutputIt copy(InputIt first, InputIt last,
OutputIt d_first) {
for (; first < last; ++first, ++d_first) {
*d_first = *first;
}
return d_first;
}
template <class BidirectionalIterator1, class BidirectionalIterator2>
inline BidirectionalIterator2 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result) {
while (last != first)
*--result = *--last;
return result;
}
template <class T, bool A>
struct __copy_backward
{
static T* copy_backward(T* first, T* last, T* result)
{
while (last > first)
*--result = *--last;
return result;
}
};
template <class T>
struct __copy_backward<T, true>
{
static T* copy_backward(T* first, T* last, T* result)
{
#ifdef DEBUG
size_t n = static_cast<size_t>(last - first);
result -= n;
memmove(result, first, n*sizeof(T));
return result;
#else
while (last > first)
*--result = *--last;
return result;
#endif
}
};
template <class T>
inline T* copy_backward(T* first, T* last, T* result) {
return __copy_backward<T, true>::copy_backward(first, last, result);
}
} // namespace std
#endif
@@ -0,0 +1,100 @@
#ifndef ITERATOR_H
#define ITERATOR_H
#ifndef MSL_ITERATOR_H_
#define MSL_ITERATOR_H_
#include "stddef.h"
namespace std {
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 <class Iterator>
struct iterator_traits {
typedef typename Iterator::difference_type difference_type;
typedef typename Iterator::value_type value_type;
typedef typename Iterator::pointer pointer;
typedef typename Iterator::reference reference;
typedef typename Iterator::iterator_category iterator_category;
};
template <class T>
struct iterator_traits<T*> {
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef random_access_iterator_tag iterator_category;
};
template <class InputIterator, class Distance>
inline void __advance(InputIterator& i, Distance n, input_iterator_tag) {
for (; n > 0; --n)
++i;
}
template <class BidirectionalIterator, class Distance>
inline void __advance(BidirectionalIterator& i, Distance n, bidirectional_iterator_tag) {
if (n >= 0)
for (; n > 0; --n)
++i;
else
for (; n < 0; ++n)
--i;
}
template <class RandomAccessIterator, class Distance>
inline void __advance(RandomAccessIterator& i, Distance n, random_access_iterator_tag) {
i += n;
}
template <class InputIterator, class Distance>
inline void advance(InputIterator& i, Distance n) {
__advance(i, n, typename iterator_traits<InputIterator>::iterator_category());
}
// TODO: combine this with above later
template <class InputIt, class Distance>
inline void advance_fake(InputIt& it, Distance n) {
while (n > 0) {
--n;
++it;
}
}
template <class InputIterator>
inline typename iterator_traits<InputIterator>::difference_type
__distance(InputIterator first, InputIterator last, input_iterator_tag) {
typename iterator_traits<InputIterator>::difference_type result = 0;
for (; first != last; ++first)
++result;
return result;
}
template <class RandomAccessIterator>
inline typename iterator_traits<RandomAccessIterator>::difference_type
__distance(RandomAccessIterator first, RandomAccessIterator last, random_access_iterator_tag) {
return last - first;
}
template <class InputIterator>
inline typename iterator_traits<InputIterator>::difference_type distance(InputIterator first,
InputIterator last) {
return __distance(first, last, typename iterator_traits<InputIterator>::iterator_category());
}
// This needs to be defined with gcc concepts or something similar. Workaround.
template <class InputIt, class Distance>
inline void advance_pointer(InputIt& it, Distance n) {
it += n;
}
} // namespace std
#endif
#endif /* ITERATOR_H */
@@ -0,0 +1,58 @@
#ifndef MSL_MEMORY_H
#define MSL_MEMORY_H
#ifndef MSL_MEMORY_H_
#define MSL_MEMORY_H_
#include "stddef.h"
namespace std {
template<class ForwardIt, class Size, class T>
inline ForwardIt uninitialized_fill_n(ForwardIt first, Size count, const T& value) {
for (; count--; ++first) {
if (first != NULL) {
*first = value;
}
}
return first;
}
template<class InputIterator, class ForwardIterator>
inline ForwardIterator __uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result) {
ForwardIterator __save = result;
for (; first != last; ++first, ++result) {
*result = *first;
}
return result;
}
template <class T, bool A, bool B>
struct __uninitialized_copy_helper {
static T* uninitialized_copy(T* first, T* last, T* result) {
return __uninitialized_copy(first, last, result);
}
};
template <class T>
struct __uninitialized_copy_helper<T, true, false>
{
static T* uninitialized_copy(T* first, T* last, T* result)
{
for (; first < last; ++result, ++first)
*result = *first;
return result;
}
};
template <class T>
inline T* uninitialized_copy(T* first, T* last, T* result) {
return __uninitialized_copy_helper<T, true, false>::uninitialized_copy(first, last, result);
}
}
#endif
#endif /* MSL_MEMORY_H */