/*
 * ************************************************************************************************************
 * 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_TREE_H__
#define __MZSTD_TREE_H__

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

class CArrayList;

class DECLSPEC_MZSTD CTreeNode {
public:
    WINAPI CTreeNode();
    WINAPI CTreeNode(WCHAR* id, WCHAR* sdata, LONG data);
    virtual WINAPI ~CTreeNode();
    
    CString id;
    CString sdata;
    LONG data;
    CArrayList *nodes;
};
typedef CTreeNode* PTreeNode;


class DECLSPEC_MZSTD CTree : public CObject {
public:
    WINAPI CTree();
    virtual WINAPI ~CTree();

    CTreeNode* WINAPI getNode(CString path);
    CTreeNode* WINAPI getParentNode(CString path);
    CTreeNode* WINAPI appendNode(CString path, LONG data, WCHAR* id = L"", WCHAR* sdata = L"");
    CTreeNode* WINAPI addAsFirst(CString path, LONG data, WCHAR* id = L"", WCHAR* sdata = L"");
    CTreeNode* WINAPI insertNode(CString path, ULONG pos, LONG data, WCHAR* id = L"", WCHAR* sdata = L"");
    CTreeNode* WINAPI appendNode(CTreeNode* parent, LONG data, WCHAR* id = L"", WCHAR* sdata = L"");
    CTreeNode* WINAPI addAsFirst(CTreeNode* parent, LONG data, WCHAR* id = L"", WCHAR* sdata = L"");
    CTreeNode* WINAPI insertNode(CTreeNode* parent, ULONG pos, LONG data, WCHAR* id = L"", WCHAR* sdata = L"");
    VOID WINAPI delNode(CString path);
    LONG WINAPI delSubNodeWithData(CString path, LONG data);
    LONG WINAPI delSubNodeWithId(CString path, CString id);
    BOOL WINAPI delFirstNode(CString path, LONG data);
    BOOL WINAPI delFirstNodeWithId(CString path, CString id);
    BOOL WINAPI delNodeAt(CString path, ULONG pos);
    LONG WINAPI pos(CString path, LONG data);
    LONG WINAPI posWithId(CString path, CString id);
    CString WINAPI getNodePath(LONG data, CTreeNode *startAtNode = NULL);
    CString WINAPI getNodeWithIdPath(CString id, CTreeNode *startAtNode = NULL);
    BOOL WINAPI contains(LONG data);
    BOOL WINAPI contains(CString id);
    BOOL WINAPI contains(CString path, LONG data);
    BOOL WINAPI containsNodeWithId(CString path, CString id);
    VOID WINAPI clear();
    CString WINAPI simplePrintTree();
private:
    CTreeNode* _root;
    CString WINAPI simplePrintNode(CTreeNode *node, CString indent);
};
typedef CTree* PTree;

#endif
