diff options
author | Eugene Sandulenko | 2016-05-22 20:47:24 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2016-05-22 22:12:59 +0200 |
commit | cc54c7723cbfb7caaf770fce338c75c13a27d4b9 (patch) | |
tree | ab1f310a492f06ddedd1fd546a917b5d90873cfb | |
parent | 0ff9e79127839c6bda8709c735cda23121d9b5a8 (diff) | |
download | scummvm-rg350-cc54c7723cbfb7caaf770fce338c75c13a27d4b9.tar.gz scummvm-rg350-cc54c7723cbfb7caaf770fce338c75c13a27d4b9.tar.bz2 scummvm-rg350-cc54c7723cbfb7caaf770fce338c75c13a27d4b9.zip |
COMMON: Implement SortedArray
-rw-r--r-- | common/array.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/common/array.h b/common/array.h index db1a62ba34..320b367809 100644 --- a/common/array.h +++ b/common/array.h @@ -361,6 +361,57 @@ protected: }; +/** + * Double linked list with sorted nodes. + */ +template<class T> +class SortedArray : public Array<T> { +public: + typedef T *iterator; + typedef uint size_type; + + SortedArray(int (*comparator)(const void *, const void *)) { + _comparator = comparator; + } + + /** + * Inserts element at the sorted position. + */ + void insert(const T &element) { + T *where = (T *)bsearch(element, this->front(), this->_size, sizeof(T), _comparator); + insert(where, element); + } + + T &operator[](size_type idx) { + error("Operation not allowed with SortedArray"); + } + + void insert_at(size_type idx, const T &element) { + error("Operation not allowed with SortedArray"); + } + + void insert_at(size_type idx, const Array<T> &array) { + error("Operation not allowed with SortedArray"); + } + + void insert(iterator pos, const T &element) { + error("Operation not allowed with SortedArray"); + } + + void push_back(const T &element) { + error("Operation not allowed with SortedArray"); + } + + void push_back(const Array<T> &array) { + error("Operation not allowed with SortedArray"); + } + + + +private: + int (*_comparator)(const void *, const void *); +}; + } // End of namespace Common #endif |