diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-06-14 00:50:34 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-06-14 00:50:34 +0100 |
commit | 37e364b2c6cc7487a1c888d256a73e5337bb7189 (patch) | |
tree | eaf6e857382eef16c2dd940eb4125536fbe068bd /src/T2DLL/LArray.h | |
download | t2win-37e364b2c6cc7487a1c888d256a73e5337bb7189.tar.gz t2win-37e364b2c6cc7487a1c888d256a73e5337bb7189.zip |
initial commit
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/LArray.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/T2DLL/LArray.h b/src/T2DLL/LArray.h new file mode 100644 index 0000000..110e3bc --- /dev/null +++ b/src/T2DLL/LArray.h @@ -0,0 +1,60 @@ +#pragma once +#include "common.h" +#include "LComparator.h" + +class DLL_EXPORT LArray { +public: + LArray(); + LArray(int size, LComparator* comparator = NULL, BOOL keepSorted = false); + void init(int size, LComparator* comparator, BOOL keepSorted); + ~LArray(); + virtual int GetCount() const; +protected: + void Expand(int amount); +public: + void AdjustAllocation(int amount); + void SetKeepSorted(BOOL keepSorted); + virtual void InsertItemsAt(int count, int where, const void* data); + virtual void RemoveItemsAt(int count, int where); + virtual void Remove(const void* item); + virtual int FetchIndexOf(const void* item) const; + virtual int FetchItemAt(int index, void* outItem) const; + virtual void AssignItemsAt(int count, int where, void* data); + virtual void Add(const void* item); + void SetComparator(LComparator* comparator); + virtual void ReadAsWord(T2Archive& archive); + virtual void WriteAsWord(T2Archive& archive); + virtual void ReadAsDWord(T2Archive& archive); + virtual void ReadAsChar(T2Archive& archive); + virtual void WriteAsDWord(T2Archive& archive); + virtual void WriteAsChar(T2Archive& archive); + +protected: + BOOL mOwnsComparator; + int mItemSize; + int mItemCount; + void *mBuffer; + int mExpandSize; + LComparator *mComparator; + BOOL mKeepSorted; +}; + +class DLL_EXPORT LArrayIterator { +public: + LArrayIterator(const LArray& array, int index = 1); + LArrayIterator(const LArrayIterator& iter); + ~LArrayIterator(); + void ResetTo(int index); + void Rewind(); + void Seek(const LArrayIterator& iter); + BOOL Next(void* item); + BOOL Previous(void* item); + + void Reset() { ResetTo(1); } + int GetCurrentIndex() { return mCurrentIndex; } + +private: + const LArray *mArray; + int mNextIndex; + int mCurrentIndex; +}; |