#ifndef __MZSTD_TREE_H__
#define __MZSTD_TREE_H__

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

namespace mzstd {

class DECLSPEC_MZSTD CmzTreeNode {
public:
    WINAPI CmzTreeNode();
    WINAPI CmzTreeNode(const WCHAR* id, const WCHAR* sdata, LONG data);
    virtual WINAPI ~CmzTreeNode();
    
    CmzString id;
    CmzString sdata;
    LONG data;
    CmzPointerList *nodes;
};
typedef CmzTreeNode* PTreeNode;


class DECLSPEC_MZSTD CmzTree : public CmzObject {
public:
    WINAPI CmzTree();
    virtual WINAPI ~CmzTree();

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

}

#endif
