#include "xpathdata.h"

XPathData::XPathData()
    : XAsset()
{
    SetName("Path Data");
}

void XPathData::ParseData(XDataStream *aStream) {
    // Parse the PathData structure
    if (GetPtr() == -1) {
        *aStream >> mNodeCount;

        // Clear existing data before parsing new data
        mNodes.clear();
        mBaseNodes.clear();
        mChainNodeForNode.clear();
        mNodeForChainNode.clear();
        mPathVis.clear();
        mNodeTrees.clear();

        // Parse nodes
        for (quint32 i = 0; i < mNodeCount; ++i) {
            XPathNode node;
            node.ParseData(aStream);
            mNodes.append(node);
        }

        // Parse base nodes count and array
        quint32 baseNodeCount;
        *aStream >> baseNodeCount;
        for (quint32 i = 0; i < baseNodeCount; ++i) {
            XPathBaseNode baseNode;
            baseNode.ParseData(aStream);
            mBaseNodes.append(baseNode);
        }

        // Parse chain node count and arrays
        *aStream >> mChainNodeCount;
        for (quint32 i = 0; i < mChainNodeCount; i++)
        {
            unsigned short chainNode;
            *aStream >> chainNode;
            mChainNodeForNode << chainNode;

            unsigned short node;
            *aStream >> node;
            mNodeForChainNode << node;
        }

        // Parse visBytes and pathVis
        *aStream >> mVisBytes;
        if (mVisBytes > 0) {
            mPathVis.resize(mVisBytes);
            aStream->readRawData(mPathVis.data(), mVisBytes);
        }

        // Parse nodeTreeCount and nodeTrees
        aStream->readRawData((char*)&mNodeTreeCount, sizeof(int));
        for (int i = 0; i < mNodeTreeCount; ++i) {
            XPathNodeTree nodeTree;
            nodeTree.ParseData(aStream);
            mNodeTrees.append(nodeTree);
        }
    }
}

quint32 XPathData::GetNodeCount() const {
    return mNodeCount;
}

void XPathData::SetNodeCount(quint32 count) {
    mNodeCount = count;
}




