fix TEnumerator (#1192)

This commit is contained in:
Jcw87
2026-08-31 09:37:06 -07:00
committed by GitHub
parent e9f0482395
commit 18e0b77903
6 changed files with 69 additions and 56 deletions
+55 -41
View File
@@ -22,6 +22,12 @@ public:
struct TNodeLinkList {
struct iterator {
typedef ptrdiff_t difference_type;
typedef TLinkListNode value_type;
typedef TLinkListNode* pointer;
typedef TLinkListNode& reference;
typedef std::bidirectional_iterator_tag iterator_category;
iterator() { node = NULL; }
explicit iterator(TLinkListNode* pNode) { node = pNode; }
iterator& operator=(const iterator& other) { node = other.node; return *this; }
@@ -41,6 +47,12 @@ struct TNodeLinkList {
};
struct const_iterator {
typedef ptrdiff_t difference_type;
typedef const TLinkListNode value_type;
typedef const TLinkListNode* pointer;
typedef const TLinkListNode& reference;
typedef std::bidirectional_iterator_tag iterator_category;
explicit const_iterator(TLinkListNode* pNode) { node = pNode; }
explicit const_iterator(iterator it) { node = it.node; }
@@ -119,6 +131,12 @@ struct TLinkList : public TNodeLinkList {
TLinkList() : TNodeLinkList() {}
struct iterator {
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef std::bidirectional_iterator_tag iterator_category;
iterator() {}
explicit iterator(TNodeLinkList::iterator iter) : base(iter) {}
@@ -146,17 +164,17 @@ struct TLinkList : public TNodeLinkList {
T* operator->() const { return Element_toValue(base.operator->()); }
T& operator*() const { return *operator->(); }
typedef s32 difference_type;
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef std::bidirectional_iterator_tag iterator_category;
public:
/* 0x00 */ TNodeLinkList::iterator base;
};
struct const_iterator {
typedef ptrdiff_t difference_type;
typedef const T value_type;
typedef const T* pointer;
typedef const T& reference;
typedef std::bidirectional_iterator_tag iterator_category;
explicit const_iterator(TNodeLinkList::const_iterator iter) : base(iter) {}
explicit const_iterator(iterator iter) : base(iter.base) {}
@@ -251,38 +269,17 @@ TLinkList_factory<T, I>::~TLinkList_factory() {
JGADGET_ASSERTWARN(934, empty());
}
template <typename T>
template <typename Iterator>
struct TEnumerator {
inline TEnumerator(T _current, T _end)
typedef typename std::iterator_traits<Iterator>::reference reference;
inline TEnumerator(Iterator _current, Iterator _end)
: current(_current), end(_end) {}
bool isEnd() const { return current != end; }
operator bool() const { return isEnd(); }
T operator*() {
T rv = current;
++current;
return rv;
}
T current;
T end;
};
// TEnumerator2 should be the same but there are two issues:
// 1. How to derive the iterator return type for operator* (the debug makes it seem like operator* is called
// so the return value should be what the iterator points to)
// 2. Calling the * operator seems to make functions using TEnumerator<T*> not work. See
// JStudio::TAdaptor::adaptor_setVariableValue_n
// Perhaps template specialization?
template <typename Iterator, typename T>
struct TEnumerator2 {
inline TEnumerator2(Iterator _current, Iterator _end)
: current(_current), end(_end) {}
bool isEnd() const { return current != end; }
operator bool() const { return isEnd(); }
T& operator*() {
T& rv = *current;
reference operator*() {
reference rv = *current;
++current;
return rv;
}
@@ -291,17 +288,34 @@ struct TEnumerator2 {
Iterator end;
};
template <typename T, int I>
struct TContainerEnumerator : public TEnumerator2<typename TLinkList<T, I>::iterator, T> {
inline TContainerEnumerator(TLinkList<T, I>* param_0)
: TEnumerator2<typename TLinkList<T, I>::iterator, T>(param_0->begin(), param_0->end()) {}
template <typename T>
struct TEnumerator<T*> {
inline TEnumerator(T* _current, T* _end)
: current(_current), end(_end) {}
bool isEnd() const { return current != end; }
operator bool() const { return isEnd(); }
T* operator*() {
T* rv = current;
++current;
return rv;
}
T* current;
T* end;
};
template <typename T>
struct TContainerEnumerator : public TEnumerator<typename T::iterator> {
inline TContainerEnumerator(T& param_0)
: TEnumerator<typename T::iterator>(param_0.begin(), param_0.end()) {}
};
template <typename T, int I>
struct TContainerEnumerator_const : public TEnumerator2<typename TLinkList<T, I>::const_iterator, const T> {
inline TContainerEnumerator_const(const TLinkList<T, I>* param_0)
: TEnumerator2<typename TLinkList<T, I>::const_iterator, const T>(param_0->begin(), param_0->end()) {}
template <typename T>
struct TContainerEnumerator_const : public TEnumerator<typename T::const_iterator> {
inline TContainerEnumerator_const(const T& param_0)
: TEnumerator<typename T::const_iterator>(param_0.begin(), param_0.end()) {}
};
namespace {
+6
View File
@@ -15,6 +15,9 @@ typedef u32 (*ExtendFunc)(u32, u32, u32);
template <typename T, class Allocator = JGadget::TAllocator<T> /***/>
struct TVector {
typedef T* iterator;
typedef const T* const_iterator;
struct TDestructed_deallocate_ {
TDestructed_deallocate_(JGadget::TAllocator<T>& alloc, T* pointer)
{
@@ -244,6 +247,9 @@ struct TVector_pointer_void : public TVector<void*, TAllocator<void*> > {
template <typename T>
struct TVector_pointer : public TVector_pointer_void {
typedef T* iterator;
typedef const T* const_iterator;
TVector_pointer(const TAllocator<void*>& allocator)
: TVector_pointer_void(allocator)
{
+1 -1
View File
@@ -18,7 +18,7 @@ JMessage::TResourceContainer::TResourceContainer() {
/* 8029FD04-8029FD90 .text Get_groupID__Q28JMessage18TResourceContainerFUs */
JMessage::TResource* JMessage::TResourceContainer::Get_groupID(u16 groupID) {
JGadget::TContainerEnumerator<TResource, 0> enumerator(this);
JGadget::TContainerEnumerator<TResourceContainer> enumerator(*this);
while (enumerator) {
const TResource* res = &(*enumerator);
if (res->mInfo.get_groupID() == groupID)
+5 -12
View File
@@ -332,17 +332,10 @@ f64 TFunctionValue_composite::composite_index(const JGadget::TVector_pointer<TFu
return pFront->getValue(param_3);
}
// TODO: remove when TContainerEnumerator_const is generic enough
template <typename T>
struct TContainerEnumerator_const_TVector : public JGadget::TEnumerator<const T*> {
inline TContainerEnumerator_const_TVector(JGadget::TVector_pointer<T> const& param_1)
: JGadget::TEnumerator<const T*>(param_1.begin(), param_1.end()) {}
};
/* 80271A04-80271A70 .text composite_parameter__Q27JStudio24TFunctionValue_compositeFRCQ27JGadget44TVector_pointer<PQ27JStudio14TFunctionValue>RCQ37JStudio24TFunctionValue_composite5TDatad */
f64 TFunctionValue_composite::composite_parameter(const JGadget::TVector_pointer<TFunctionValue*>& param_1, const TFunctionValue_composite::TData& param_2, f64 param_3) {
f64 dVar4 = param_3 - param_2.get_value();
TContainerEnumerator_const_TVector<TFunctionValue*> aTStack_18(param_1);
JGadget::TContainerEnumerator_const<JGadget::TVector_pointer<TFunctionValue*> > aTStack_18(param_1);
while (aTStack_18) {
TFunctionValue* const* ppiVar3 = *aTStack_18;
TFunctionValue* piVar3 = *ppiVar3;
@@ -354,7 +347,7 @@ f64 TFunctionValue_composite::composite_parameter(const JGadget::TVector_pointer
/* 80271A70-80271AF8 .text composite_add__Q27JStudio24TFunctionValue_compositeFRCQ27JGadget44TVector_pointer<PQ27JStudio14TFunctionValue>RCQ37JStudio24TFunctionValue_composite5TDatad */
f64 TFunctionValue_composite::composite_add(const JGadget::TVector_pointer<TFunctionValue*>& param_1, const TFunctionValue_composite::TData& param_2, f64 param_3) {
f64 dVar4 = param_2.get_value();
TContainerEnumerator_const_TVector<TFunctionValue*> aTStack_18(param_1);
JGadget::TContainerEnumerator_const<JGadget::TVector_pointer<TFunctionValue*> > aTStack_18(param_1);
while (aTStack_18) {
TFunctionValue* const* ppiVar3 = *aTStack_18;
TFunctionValue* piVar3 = *ppiVar3;
@@ -369,7 +362,7 @@ f64 TFunctionValue_composite::composite_subtract(const JGadget::TVector_pointer<
if (size == 0) {
return 0.0;
}
TContainerEnumerator_const_TVector<TFunctionValue*> aTStack_18(param_1);
JGadget::TContainerEnumerator_const<JGadget::TVector_pointer<TFunctionValue*> > aTStack_18(param_1);
TFunctionValue* const* local_148 = *aTStack_18;
TFunctionValue* pFront = *local_148;
// JUT_ASSERT(688, pFront!=0);
@@ -386,7 +379,7 @@ f64 TFunctionValue_composite::composite_subtract(const JGadget::TVector_pointer<
/* 80271BE8-80271C70 .text composite_multiply__Q27JStudio24TFunctionValue_compositeFRCQ27JGadget44TVector_pointer<PQ27JStudio14TFunctionValue>RCQ37JStudio24TFunctionValue_composite5TDatad */
f64 TFunctionValue_composite::composite_multiply(const JGadget::TVector_pointer<TFunctionValue*>& param_1, const TFunctionValue_composite::TData& param_2, f64 param_3) {
f64 dVar4 = param_2.get_value();
TContainerEnumerator_const_TVector<TFunctionValue*> aTStack_18(param_1);
JGadget::TContainerEnumerator_const<JGadget::TVector_pointer<TFunctionValue*> > aTStack_18(param_1);
while (aTStack_18) {
TFunctionValue* const* ppiVar3 = *aTStack_18;
TFunctionValue* piVar3 = *ppiVar3;
@@ -401,7 +394,7 @@ f64 TFunctionValue_composite::composite_divide(const JGadget::TVector_pointer<TF
if (size == 0) {
return 0.0;
}
TContainerEnumerator_const_TVector<TFunctionValue*> aTStack_18(param_1);
JGadget::TContainerEnumerator_const<JGadget::TVector_pointer<TFunctionValue*> > aTStack_18(param_1);
TFunctionValue* const* local_148 = *aTStack_18;
TFunctionValue* pFront = *local_148;
// JUT_ASSERT(724, pFront!=0);
@@ -52,7 +52,7 @@ void JStudio::TFactory::appendCreateObject(JStudio::TCreateObject* param_0) {
/* 8026E360-8026E438 .text create__Q27JStudio8TFactoryFRCQ47JStudio3stb4data20TParse_TBlock_object */
JStudio::TObject* JStudio::TFactory::create(const JStudio::stb::data::TParse_TBlock_object& param_0) {
JGadget::TContainerEnumerator<TCreateObject, -4> aTStack_368(&mList);
JGadget::TContainerEnumerator<JGadget::TLinkList<TCreateObject, -4> > aTStack_368(mList);
while(aTStack_368) {
TCreateObject& piVar1 = *aTStack_368;
JStudio::TObject* obj = NULL;
+1 -1
View File
@@ -299,7 +299,7 @@ bool TControl::forward(u32 param_0) {
bool rv = mObject_control.forward(param_0);
int uVar7 = 0xf;
int uVar6 = 0;
JGadget::TContainerEnumerator<JStudio::stb::TObject, -12> enumerator(&mObjectContainer);
JGadget::TContainerEnumerator<JGadget::TLinkList<JStudio::stb::TObject, -12> > enumerator(mObjectContainer);
while (enumerator) {
JStudio::stb::TObject& object = *enumerator;
rv = object.forward(param_0) || rv;