





#include "xpathdata.h"

XPathData::XPathData()
    : XAsset() {
}

void XPathData::ParseData(QDataStream *aStream) {
    // Parse the PathData structure
    if (GetPtr() == -1) {
        aStream->read((char*)&mNodeCount, sizeof(unsigned int));

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

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

        // Parse base nodes count and array
        unsigned int baseNodeCount;
        aStream->read((char*)&baseNodeCount, sizeof(unsigned int));
        for (unsigned int i = 0; i < baseNodeCount; ++i) {
            XPathBaseNode baseNode;
            baseNode.ParseData(aStream);
            mBaseNodes.append(baseNode);
        }

        // Parse chain node count and arrays
        aStream->read((char*)&mChainNodeCount, sizeof(unsigned int));

        if (mChainNodeCount > 0) {
            mChainNodeForNode.resize(mChainNodeCount);
            mNodeForChainNode.resize(mChainNodeCount);

            aStream->read((char*)mChainNodeForNode.data(), mChainNodeCount * sizeof(unsigned short));
            aStream->read((char*)mNodeForChainNode.data(), mChainNodeCount * sizeof(unsigned short));
        }

        // Parse visBytes and pathVis
        aStream->read((char*)&mVisBytes, sizeof(int));
        if (mVisBytes > 0) {
            mPathVis.resize(mVisBytes);
            aStream->read(mPathVis.data(), mVisBytes);
        }

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

unsigned int XPathData::GetNodeCount() const {
    return mNodeCount;
}

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




