/*
 * ************************************************************************************************************
 * 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_STRING_LIST_H__
#define __MZSTD_STRING_LIST_H__

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

class DECLSPEC_MZSTD CStringList : public CObject {
public:
    WINAPI CStringList(ULONG capacity = 50);
    virtual WINAPI ~CStringList();

    VOID WINAPI append(CString data);
    VOID WINAPI append(CStringList *lst);
    inline VOID WINAPI push(CString data) { this->append(data); };
    VOID WINAPI addAsFirst(CString data);
    VOID WINAPI addAsFirst(WCHAR* data);
    VOID WINAPI insert(ULONG pos, CString data);
    ULONG WINAPI del(CString data);
    BOOL WINAPI delFirst(CString data);
    BOOL WINAPI delAt(ULONG pos);
    LONG WINAPI pos(CString data);
    BOOL WINAPI contains(CString data);
    inline CString& WINAPI getAt(ULONG pos) { if (pos < this->_size) return *(CString*)this->_items[pos]; return this->_emptyStr; };
    VOID WINAPI setAt(ULONG pos, CString data);
	inline CString& WINAPI getLast() { if (this->_size > 0) return *(CString*)this->_items[this->_size - 1]; return this->_emptyStr; };
    inline CString WINAPI pop() {
        CString retval;
        if (this->_size < 1) { return ""; }
        retval = this->getAt(this->_size - 1);
        this->delAt(this->_size - 1);
        return retval;
    }
    inline ULONG WINAPI size() { return this->_size; };
    inline LONG* WINAPI getItemsBuf() { return this->_items; }
    VOID WINAPI clear();
	VOID WINAPI writeToFile(CString fname);
	VOID WINAPI readFromFile(CString fname);

    virtual CString WINAPI join(WCHAR* glue = L" ");
    // Returns CString object (passed in first argument) containing substring separated by glue characters
    // and ended with double NULL. If arraysize argument is not NULL then it is set to total string size
    // including trailing double NULL chars.
    virtual VOID WINAPI joinIntoStringArray(CString* result, WCHAR glue = NULL);
    virtual CString WINAPI toString();
    WINAPI operator WCHAR*();

private:
    LONG* _items;
	CString _emptyStr;
    ULONG _size;
    ULONG _capacity;
	ULONG _growBy;

    LONG* WINAPI createNullArray(ULONG capacity);
};
typedef CStringList* PStringList;


#endif
