diff options
Diffstat (limited to 'src/lockedarray.h')
-rw-r--r-- | src/lockedarray.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/lockedarray.h b/src/lockedarray.h index 2b4b099d..c4c83ea9 100644 --- a/src/lockedarray.h +++ b/src/lockedarray.h @@ -44,7 +44,7 @@ class LockedArray bool isLocked() const { return mLocked; }; T getEntry() const { return mData[mCurEntry]; }; - void setEntry(T entry) { mData[mCurEntry] = entry; }; + void setEntry(T entry) { mData[mCurEntry] = entry; mFilled = true; }; void next(); void prev(); @@ -53,6 +53,11 @@ class LockedArray unsigned int getSize() const { return mSize; }; + /** + * Clears the array without changing size or data type + */ + void clear(); + protected: unsigned int mSize; @@ -60,11 +65,14 @@ class LockedArray unsigned int mCurEntry; bool mLocked; + + bool mFilled; }; template<class T> LockedArray<T>::LockedArray(unsigned int size): - mSize(size), mData(new T[size]), mCurEntry(0), mLocked(false) + mSize(size), mData(new T[size]), mCurEntry(0), mLocked(false), + mFilled(false) { std::fill_n(mData, mSize, (T)0); } @@ -105,4 +113,19 @@ void LockedArray<T>::select(unsigned int pos) mCurEntry = 0; } +template<class T> +void LockedArray<T>::clear() +{ + if (!mFilled) return; + + delete [] mData; + + mData = new T[mSize]; + + std::fill_n(mData, mSize, (T)0); + + mCurEntry = 0; + + mLocked = false; +} #endif |