diff --git a/include/JSystem/JGadget/linklist.h b/include/JSystem/JGadget/linklist.h index 3c1207885..d6db2c55b 100644 --- a/include/JSystem/JGadget/linklist.h +++ b/include/JSystem/JGadget/linklist.h @@ -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::~TLinkList_factory() { JGADGET_ASSERTWARN(934, empty()); } -template +template struct TEnumerator { - inline TEnumerator(T _current, T _end) + typedef typename std::iterator_traits::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 not work. See -// JStudio::TAdaptor::adaptor_setVariableValue_n -// Perhaps template specialization? -template -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 -struct TContainerEnumerator : public TEnumerator2::iterator, T> { - inline TContainerEnumerator(TLinkList* param_0) - : TEnumerator2::iterator, T>(param_0->begin(), param_0->end()) {} +template +struct TEnumerator { + 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 +struct TContainerEnumerator : public TEnumerator { + inline TContainerEnumerator(T& param_0) + : TEnumerator(param_0.begin(), param_0.end()) {} }; -template -struct TContainerEnumerator_const : public TEnumerator2::const_iterator, const T> { - inline TContainerEnumerator_const(const TLinkList* param_0) - : TEnumerator2::const_iterator, const T>(param_0->begin(), param_0->end()) {} +template +struct TContainerEnumerator_const : public TEnumerator { + inline TContainerEnumerator_const(const T& param_0) + : TEnumerator(param_0.begin(), param_0.end()) {} }; namespace { diff --git a/include/JSystem/JGadget/vector.h b/include/JSystem/JGadget/vector.h index 2e69b6b8e..3a840ecac 100644 --- a/include/JSystem/JGadget/vector.h +++ b/include/JSystem/JGadget/vector.h @@ -15,6 +15,9 @@ typedef u32 (*ExtendFunc)(u32, u32, u32); template /***/> struct TVector { + typedef T* iterator; + typedef const T* const_iterator; + struct TDestructed_deallocate_ { TDestructed_deallocate_(JGadget::TAllocator& alloc, T* pointer) { @@ -244,6 +247,9 @@ struct TVector_pointer_void : public TVector > { template struct TVector_pointer : public TVector_pointer_void { + typedef T* iterator; + typedef const T* const_iterator; + TVector_pointer(const TAllocator& allocator) : TVector_pointer_void(allocator) { diff --git a/src/JSystem/JMessage/resource.cpp b/src/JSystem/JMessage/resource.cpp index 9670e3879..1beef8ec8 100644 --- a/src/JSystem/JMessage/resource.cpp +++ b/src/JSystem/JMessage/resource.cpp @@ -18,7 +18,7 @@ JMessage::TResourceContainer::TResourceContainer() { /* 8029FD04-8029FD90 .text Get_groupID__Q28JMessage18TResourceContainerFUs */ JMessage::TResource* JMessage::TResourceContainer::Get_groupID(u16 groupID) { - JGadget::TContainerEnumerator enumerator(this); + JGadget::TContainerEnumerator enumerator(*this); while (enumerator) { const TResource* res = &(*enumerator); if (res->mInfo.get_groupID() == groupID) diff --git a/src/JSystem/JStudio/JStudio/functionvalue.cpp b/src/JSystem/JStudio/JStudio/functionvalue.cpp index e12849bc4..35da90869 100644 --- a/src/JSystem/JStudio/JStudio/functionvalue.cpp +++ b/src/JSystem/JStudio/JStudio/functionvalue.cpp @@ -332,17 +332,10 @@ f64 TFunctionValue_composite::composite_index(const JGadget::TVector_pointergetValue(param_3); } -// TODO: remove when TContainerEnumerator_const is generic enough -template -struct TContainerEnumerator_const_TVector : public JGadget::TEnumerator { - inline TContainerEnumerator_const_TVector(JGadget::TVector_pointer const& param_1) - : JGadget::TEnumerator(param_1.begin(), param_1.end()) {} -}; - /* 80271A04-80271A70 .text composite_parameter__Q27JStudio24TFunctionValue_compositeFRCQ27JGadget44TVector_pointerRCQ37JStudio24TFunctionValue_composite5TDatad */ f64 TFunctionValue_composite::composite_parameter(const JGadget::TVector_pointer& param_1, const TFunctionValue_composite::TData& param_2, f64 param_3) { f64 dVar4 = param_3 - param_2.get_value(); - TContainerEnumerator_const_TVector aTStack_18(param_1); + JGadget::TContainerEnumerator_const > 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_pointerRCQ37JStudio24TFunctionValue_composite5TDatad */ f64 TFunctionValue_composite::composite_add(const JGadget::TVector_pointer& param_1, const TFunctionValue_composite::TData& param_2, f64 param_3) { f64 dVar4 = param_2.get_value(); - TContainerEnumerator_const_TVector aTStack_18(param_1); + JGadget::TContainerEnumerator_const > 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 aTStack_18(param_1); + JGadget::TContainerEnumerator_const > 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_pointerRCQ37JStudio24TFunctionValue_composite5TDatad */ f64 TFunctionValue_composite::composite_multiply(const JGadget::TVector_pointer& param_1, const TFunctionValue_composite::TData& param_2, f64 param_3) { f64 dVar4 = param_2.get_value(); - TContainerEnumerator_const_TVector aTStack_18(param_1); + JGadget::TContainerEnumerator_const > 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 aTStack_18(param_1); + JGadget::TContainerEnumerator_const > aTStack_18(param_1); TFunctionValue* const* local_148 = *aTStack_18; TFunctionValue* pFront = *local_148; // JUT_ASSERT(724, pFront!=0); diff --git a/src/JSystem/JStudio/JStudio/jstudio-control.cpp b/src/JSystem/JStudio/JStudio/jstudio-control.cpp index 33779ecc0..c0846230d 100644 --- a/src/JSystem/JStudio/JStudio/jstudio-control.cpp +++ b/src/JSystem/JStudio/JStudio/jstudio-control.cpp @@ -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 aTStack_368(&mList); + JGadget::TContainerEnumerator > aTStack_368(mList); while(aTStack_368) { TCreateObject& piVar1 = *aTStack_368; JStudio::TObject* obj = NULL; diff --git a/src/JSystem/JStudio/JStudio/stb.cpp b/src/JSystem/JStudio/JStudio/stb.cpp index 405be35df..bed228fa7 100644 --- a/src/JSystem/JStudio/JStudio/stb.cpp +++ b/src/JSystem/JStudio/JStudio/stb.cpp @@ -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 enumerator(&mObjectContainer); + JGadget::TContainerEnumerator > enumerator(mObjectContainer); while (enumerator) { JStudio::stb::TObject& object = *enumerator; rv = object.forward(param_0) || rv;