diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-07-05 19:04:06 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-07-05 19:04:06 +0100 |
commit | 5e61c1280c15ab9969b94cd360cafd4a11b2dd30 (patch) | |
tree | 1fdb60d771c4351b5aa5dcf1a43376c0558625a4 /src/T2HUnknown.cpp | |
parent | c2efba6907fab934a04959b9bb644cf7141cc955 (diff) | |
download | t2win-5e61c1280c15ab9969b94cd360cafd4a11b2dd30.tar.gz t2win-5e61c1280c15ab9969b94cd360cafd4a11b2dd30.zip |
matched T2.exe
Diffstat (limited to 'src/T2HUnknown.cpp')
-rw-r--r-- | src/T2HUnknown.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/T2HUnknown.cpp b/src/T2HUnknown.cpp new file mode 100644 index 0000000..2ca8ab6 --- /dev/null +++ b/src/T2HUnknown.cpp @@ -0,0 +1,49 @@ +#include "T2HUnknown.h" + +T2HUnknown::T2HUnknown(int capacity) { + mData = (int *) malloc(sizeof(int) * capacity); + mLength = 0; + mCapacity = capacity; +} + +T2HUnknown::~T2HUnknown() { + free(mData); +} + +int T2HUnknown::GetLength() const { + return mLength; +} + +void T2HUnknown::AddValue(int value) { + if (mLength == mCapacity) { + mLength--; + memmove(mData, mData + 1, (mCapacity - 1) * sizeof(int)); + } + + mData[mLength] = value; + mLength++; +} + +int T2HUnknown::GetFirst() const { + if (mLength == 0) + return -1; + return 0; +} + +int T2HUnknown::GetNext(int &position) const { + if (position == -1 || position == mLength) { + position = -1; + return 0; + } + + int value = mData[position]; + position++; + if (position == mLength) + position = -1; + return value; +} + +void T2HUnknown::SetAll(int value) { + for (int i = 0; i < mCapacity; i++) + mData[i] = value; +} |