From 37e364b2c6cc7487a1c888d256a73e5337bb7189 Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Wed, 14 Jun 2023 00:50:34 +0100 Subject: initial commit --- src/T2DLL/LArray.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/T2DLL/LArray.h (limited to 'src/T2DLL/LArray.h') 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; +}; -- cgit v1.2.3