Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
std-vector.h
Go to the documentation of this file.
1#ifndef STD_VECTOR_H
2#define STD_VECTOR_H
3
5#include <algorithm.h>
6#include <msl_memory.h>
7
8namespace JGadget {
9namespace vector {
10/* 802DCCC8 */ u32 extend_default(u32, u32, u32);
11};
12
13typedef u32 (*extendFunc)(u32, u32, u32);
14
15template <typename T, typename Allocator = JGadget::TAllocator<T> >
16struct TVector {
19 mAllocator = &allocator;
20 mPtr = ptr;
21 }
22
24
25 void set(T* ptr) { mPtr = ptr; }
26
27 Allocator* mAllocator;
28 T* mPtr;
29 };
30
31 TVector(Allocator const& allocator) {
32 mAllocator = allocator;
33 pBegin_ = NULL;
34 pEnd_ = pBegin_;
35 mCapacity = 0;
37 }
38
40 clear();
41 mAllocator.deallocate(pBegin_, 0);
42 }
43
44 void insert(T* pos, u32 count, const T& val) {
45 if (count != 0) {
46 T* ptr = Insert_raw(pos, count);
47 if (ptr == end()) {
48 /* JGadget_outMessage sp120(JGadget_outMessage::warning, __FILE__, 0x141);
49 sp120 << "can't allocate memory"; */
50 } else {
51 std::uninitialized_fill_n(ptr, count, val);
52 }
53 }
54 }
55
56 T* Insert_raw(T* pIt, u32 pCount) {
57 JUT_ASSERT(446, (pBegin_ <= pIt) && (pIt <= pEnd_));
58
59 T* const pFirst = pIt;
60
61 if (pCount == 0) {
62 return pIt;
63 }
64
65 if (pCount + size() <= mCapacity) {
66 void** newEnd = pFirst + pCount;
67
68 if (newEnd < pEnd_) {
69 void** pOverwrittenValues = pEnd_ - pCount;
70 std::uninitialized_copy(pOverwrittenValues, pEnd_, pEnd_);
71 std::copy_backward(pFirst, pOverwrittenValues, pEnd_);
72 DestroyElement_(pFirst, newEnd);
73
74 pEnd_ += pCount;
75 return pIt;
76 } else {
77 std::uninitialized_copy(pFirst, pEnd_, newEnd);
78 DestroyElement_(pFirst, pEnd_);
79
80 pEnd_ += pCount;
81 return pIt;
82 }
83 }
84
85 u32 newSize = GetSize_extend_(pCount);
86
87 void** newDataPointer = mAllocator.allocate(newSize, 0);
88 if (!newDataPointer) {
89 return end();
90 }
91
92 TDestructed_deallocate_ destructionDeallocator(mAllocator, newDataPointer);
93
94 void** const endOfCopy = std::uninitialized_copy(pBegin_, pFirst, newDataPointer);
95 std::uninitialized_copy(pFirst, pEnd_, endOfCopy + pCount);
96
98 destructionDeallocator.set(pBegin_);
99
100 pEnd_ = newDataPointer + (pEnd_ - pBegin_ + pCount);
101 pBegin_ = newDataPointer;
102 mCapacity = newSize;
103
104 return endOfCopy;
105 }
106
107 T* insert(T* pos, const T& val) {
108 u32 diff = (int)((u32)pos - (u32)begin()) / 4;
109 insert(pos, 1, val);
110 return pBegin_ + diff;
111 }
112
113 T* begin() const { return pBegin_; }
114
115 T* end() const { return pEnd_; }
116
117 u32 size() const {
118 if (pBegin_ == 0) {
119 return 0;
120 }
121 return (int)((u32)pEnd_ - (u32)pBegin_) / 4;
122 }
123
124 u32 capacity() { return mCapacity; }
125
127 JUT_ASSERT(0x22B, pfnExtend_!=0);
128
129 u32 oldSize = size();
130 u32 neededNewSpace = oldSize + count;
131 u32 extendedSize = pfnExtend_(capacity(), oldSize, count);
132
133 return neededNewSpace > extendedSize ? neededNewSpace : extendedSize;
134 }
135
136 void DestroyElement_(T* start, T* end) {
137 for (; start != end; start++) {
138 mAllocator.destroy(start);
139 }
140 }
141
143
144 T* erase(T* start, T* end) {
145 T* vectorEnd = pEnd_;
146 T* ppvVar3 = std::copy(end, vectorEnd, start);
147 DestroyElement_(ppvVar3, pEnd_);
148 pEnd_ = ppvVar3;
149 return start;
150 }
151
152 void clear() { erase(begin(), end()); }
153
154 /* 0x00 */ Allocator mAllocator;
155 /* 0x04 */ T* pBegin_;
156 /* 0x08 */ T* pEnd_;
157 /* 0x0C */ u32 mCapacity;
159};
160
161struct TVector_pointer_void : public TVector<void*, TAllocator<void*> > {
164 const JGadget::TAllocator<void*>& allocator);
165
167
168 void insert(void**, void* const&);
169 void** erase(void**, void**);
170
171 void clear() { erase(begin(), end()); }
172 void push_back(const void*& value) { insert(end(), (void* const&)value); }
173};
174
175template <typename T>
176struct TVector_pointer : TVector_pointer_void {
179
180 const T* begin() const { return (const T*)TVector_pointer_void::begin(); }
181 T* begin() { return (T*)TVector_pointer_void::begin(); }
182
183 const T* end() const { return (const T*)TVector_pointer_void::end(); }
184 T* end() { return (T*)TVector_pointer_void::end(); }
185
186 void push_back(const T& ref) {
187 static_cast<TVector_pointer_void*>(this)->push_back((const void*&)ref);
188 }
189};
190
191} // namespace JGadget
192
193#endif /* STD_VECTOR_H */
static u8 pos[12]
Definition d_a_obj_kago.cpp:839
u32 extend_default(u32, u32, u32)
Definition std-vector.cpp:9
Definition binary.h:6
u32(* extendFunc)(u32, u32, u32)
Definition std-vector.h:13
T * uninitialized_copy(T *first, T *last, T *result)
Definition msl_memory.h:45
OutputIt copy(InputIt first, InputIt last, OutputIt d_first)
Definition algorithm.h:126
BidirectionalIterator2 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result)
Definition algorithm.h:135
ForwardIt uninitialized_fill_n(ForwardIt first, Size count, const T &value)
Definition msl_memory.h:7
@ start
Definition strtoul.c:8
Definition std-memory.h:8
Allocator * mAllocator
Definition std-vector.h:27
T * mPtr
Definition std-vector.h:28
TDestructed_deallocate_(JGadget::TAllocator< T > &allocator, T *ptr)
Definition std-vector.h:18
void set(T *ptr)
Definition std-vector.h:25
~TDestructed_deallocate_()
Definition std-vector.h:23
Definition vector.h:47
void insert(void **, void *const &)
Definition std-vector.cpp:28
void ** erase(void **, void **)
Definition std-vector.cpp:34
void push_back(const void *&value)
Definition std-vector.h:172
void clear()
Definition std-vector.h:171
TVector_pointer_void(u32, void *const &, const JGadget::TAllocator< void * > &allocator)
TVector_pointer_void(const JGadget::TAllocator< void * > &allocator)
Definition std-vector.cpp:15
~TVector_pointer_void()
Definition std-vector.cpp:19
T * begin()
Definition std-vector.h:181
const T * begin() const
Definition std-vector.h:180
T * end()
Definition std-vector.h:184
~TVector_pointer()
Definition std-vector.h:178
const T * end() const
Definition std-vector.h:183
void push_back(const T &ref)
Definition std-vector.h:186
TVector_pointer(const TAllocator< void * > &allocator)
Definition std-vector.h:177
Definition vector.h:18
u32 GetSize_extend_(u32 count)
Definition std-vector.h:126
void insert(T *pos, u32 count, const T &val)
Definition std-vector.h:44
TVector(Allocator const &allocator)
Definition std-vector.h:31
T * Insert_raw(T *pIt, u32 pCount)
Definition std-vector.h:56
void DestroyElement_(T *start, T *end)
Definition std-vector.h:136
Allocator mAllocator
Definition std-vector.h:154
T * insert(T *pos, const T &val)
Definition std-vector.h:107
u32 capacity()
Definition std-vector.h:124
T * pEnd_
Definition std-vector.h:156
u32 mCapacity
Definition std-vector.h:157
void DestroyElement_all_()
Definition std-vector.h:142
void clear()
Definition std-vector.h:152
u32 size() const
Definition std-vector.h:117
T * begin() const
Definition std-vector.h:113
T * end() const
Definition std-vector.h:115
T * pBegin_
Definition std-vector.h:155
T * erase(T *start, T *end)
Definition std-vector.h:144
~TVector()
Definition std-vector.h:39
extendFunc pfnExtend_
Definition std-vector.h:158
unsigned long u32
Definition types.h:9