#ifndef __MZSTD_POINTER_LIST_H__
#define __MZSTD_POINTER_LIST_H__

#include "mzstdCommon.h"
#include "mzObject.h"
#include "mzString.h"

namespace mzstd {

class DECLSPEC_MZSTD CmzPointerList : public CmzObject {
public:
    WINAPI CmzPointerList(ULONG capacity = 100);
    virtual WINAPI ~CmzPointerList();

    VOID WINAPI append(LPVOID data);
    inline VOID WINAPI push(LPVOID data) { this->append(data); };
    VOID WINAPI addAsFirst(LPVOID data);
    VOID WINAPI insert(ULONG pos, LPVOID data);
    ULONG WINAPI del(LPVOID data);
    BOOL WINAPI delFirst(LPVOID data);
    BOOL WINAPI delAt(ULONG pos);
    LONG WINAPI pos(LPVOID data);
    BOOL WINAPI contains(LPVOID data);
    LPVOID WINAPI getMinValue();
    LPVOID WINAPI getMaxValue();
    // Bubble-sort (default in ascending order)
    VOID WINAPI sort(BOOL asc = TRUE);
    inline LPVOID WINAPI getAt(ULONG pos) { if (pos < this->_size) return this->_items[pos]; return 0; };
    VOID WINAPI setAt(ULONG pos, LPVOID data);
    inline LPVOID WINAPI getFirst() { if (this->_size > 0) return this->_items[0]; return 0; };
    inline LPVOID WINAPI getLast() { if (this->_size > 0) return this->_items[this->_size - 1]; return 0; };
    inline LPVOID WINAPI pop() {
        LPVOID retval;
        if (this->_size < 1) { return 0; }
        retval = this->getAt(this->_size - 1);
        this->delAt(this->_size - 1);
        return retval;
    }
    inline ULONG WINAPI size() { return this->_size; };
    inline LONG WINAPI capacity() { return this->_capacity; };
    virtual VOID WINAPI clear();
    inline LPVOID* WINAPI getItemsBuf() { return this->_items; }

    CmzPointerList* WINAPI clone();
    virtual CmzString WINAPI toString();

protected:
    LPVOID* _items;
    ULONG _size;
    LONG _capacity;

    LPVOID* WINAPI _createNullArray(ULONG capacity);
};

}

#endif
