/*
 * ************************************************************************************************************
 * Author: Marcin Załęczny
 * Copyright (C)2010 Marcin Załęczny <mzaleczny@hotmail.com>
 * License: The GNU Lesser General Public License, version 3.0 (LGPLv3)
 * Library Name: mzstd
 * Version: 1.07
 * First release date:   2010-11-08
 * Current release date: 2011-03-04
 *
 *
 * This file is part of mzstd library
 * 
 * mzstd library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * mzstd library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************************************************
 */

#ifndef __MZSTD_OBJECT_LIST_H__
#define __MZSTD_OBJECT_LIST_H__

#include "mzstdCommon.h"
#include "mzObject.h"
#include "mzArrayList.h"

class DECLSPEC_MZSTD CObjectList : public CArrayList {
public:
    WINAPI CObjectList(ULONG capacity = 50, BOOL deleteObjects = TRUE);
    virtual WINAPI ~CObjectList();

    VOID WINAPI append(CObject* data);
    VOID WINAPI append(CObjectList* lst);
    inline VOID WINAPI push(CObject* data) { this->append(data); };
    VOID WINAPI addAsFirst(CObject* data);
    VOID WINAPI insert(ULONG pos, CObject* data);
    // Removes objects from array and deletes it.
    ULONG WINAPI del(CObject* data);
    // Removes first object from array and deletes it.
    BOOL WINAPI delFirst(CObject* data);
    // Removes object from array and deletes it.
    BOOL WINAPI delAt(ULONG pos);
    // Removes objects from array.
    ULONG WINAPI remove(CObject* data);
    // Removes first object from array. Returns the object.
    BOOL WINAPI removeFirst(CObject* data);
    // Removes object from array. Returns the object.
    CObject* WINAPI removeAt(ULONG pos);
    LONG WINAPI pos(CObject* data);
    BOOL WINAPI contains(CObject* data);
    inline CObject* WINAPI getAt(ULONG pos) { if (pos < this->_size) return (CObject*)this->_items[pos]; return NULL; };
    VOID WINAPI setAt(ULONG pos, CObject* data);
	inline CObject* WINAPI getLast() { if (this->_size > 0) return (CObject*)this->_items[this->_size - 1]; return NULL; };
    CObject* WINAPI pop();
    // removes all object in the list and delete them
    virtual VOID WINAPI clear();
    // removes all object in the list but do not delete them
    virtual VOID WINAPI empty();

    virtual CString WINAPI toString();
    
protected:
    // Sometimes we hold the same objects (pointers to them) in a few arrays and do not want release them
    // when the array is deleted.
    BOOL _deleteObjectsInDestructor;
};
typedef CObjectList* PObjectList;


#endif
