diff --git a/qse/include/qse/cmn/Array.hpp b/qse/include/qse/cmn/Array.hpp index 125f5941..8f56232c 100644 --- a/qse/include/qse/cmn/Array.hpp +++ b/qse/include/qse/cmn/Array.hpp @@ -161,6 +161,19 @@ protected: } } + void clear_all_items () + { + QSE_ASSERT (this->count <= 0 || (this->count >= 1 && this->buffer)); + + for (qse_size_t i = this->count; i > 0; ) + { + --i; + this->buffer[i].~T (); + } + + this->count = 0; + } + public: bool isEmpty () const { @@ -327,20 +340,24 @@ public: this->count -= to_index - from_index + 1; } -protected: - void clear_all_items () +#if 0 + /// \return the number of items deleted. + int removeByValue (const T& value) { - QSE_ASSERT (this->count <= 0 || (this->count >= 1 && this->buffer)); - - for (qse_size_t i = this->count; i > 0; ) - { - --i; - this->buffer[i].~T (); - } - - this->count = 0; + qse_size_t index = this->findFirstIndex (value); + if (index == INVALID_INDEX) return 0; + this->remove (index); + return 1; } + qse_size_t removeAllByValue (const T& value) + { + qse_size_t cnt = 0; + while (this->removeByValue(value) > 0) cnt++; + return cnt; + } +#endif + public: void clear (bool purge_buffer = false) {