//
// Generated by dtk
// Translation Unit: c_node.cpp
//

#include "SSystem/SComponent/c_node.h"
#include "dolphin/types.h"

/* 80244C60-80244C6C       .text cNd_Join__FP10node_classP10node_class */
void cNd_Join(node_class* pA, node_class* pB) {
    pA->mpNextNode = pB;
    pB->mpPrevNode = pA;
}

/* 80244C6C-80244C9C       .text cNd_LengthOf__FP10node_class */
int cNd_LengthOf(node_class* pNode) {
    int count = 0;
    while (pNode) {
        count++;
        pNode = NODE_GET_NEXT(pNode);
    }
    return count;
}

/* 80244C9C-80244CCC       .text cNd_First__FP10node_class */
node_class* cNd_First(node_class* pNode) {
    node_class* pRet = NULL;
    while (pNode) {
        pRet = pNode;
        pNode = NODE_GET_PREV(pNode);
    }
    return pRet;
}

/* 80244CCC-80244CFC       .text cNd_Last__FP10node_class */
node_class* cNd_Last(node_class* pNode) {
    node_class* pRet = NULL;
    while (pNode) {
        pRet = pNode;
        pNode = NODE_GET_NEXT(pNode);
    }
    return pRet;
}

/* 80244CFC-80244D4C       .text cNd_Order__FP10node_classi */
node_class* cNd_Order(node_class* pNode, int idx) {
    node_class* pRet = NULL;
    int i = 0;
    while (i < idx && pNode) {
        pRet = pNode;
        i++;
        pNode = NODE_GET_NEXT(pNode);
    }
    if (i < idx)
        return pRet;
    return NULL;
}

/* 80244D4C-80244D80       .text cNd_SingleCut__FP10node_class */
void cNd_SingleCut(node_class* pNode) {
    node_class* pPrev = pNode->mpPrevNode;
    node_class* pNext = pNode->mpNextNode;

    if (pPrev)
        pPrev->mpNextNode = pNode->mpNextNode;
    if (pNext)
        pNext->mpPrevNode = pNode->mpPrevNode;
    pNode->mpPrevNode = NULL;
    pNode->mpNextNode = NULL;
}

/* 80244D80-80244DA0       .text cNd_Cut__FP10node_class */
void cNd_Cut(node_class* pNode) {
    if (pNode->mpPrevNode)
        pNode->mpPrevNode->mpNextNode = NULL;
    pNode->mpPrevNode = NULL;
}

/* 80244DA0-80244DD4       .text cNd_Addition__FP10node_classP10node_class */
void cNd_Addition(node_class* pA, node_class* pB) {
    node_class* pLast = cNd_Last(pA);
    cNd_Join(pLast, pB);
}

/* 80244DD4-80244E40       .text cNd_Insert__FP10node_classP10node_class */
void cNd_Insert(node_class* pA, node_class* pB) {
    node_class* pPrev = pA->mpPrevNode;
    if (pPrev == NULL) {
        cNd_Addition(pB, pA);
    } else {
        cNd_Cut(pA);
        cNd_Addition(pPrev, pB);
        cNd_Addition(pB, pA);
    }
}

/* 80244E40-80244E68       .text cNd_SetObject__FP10node_classPv */
void cNd_SetObject(node_class* pNode, void* pData) {
    while (pNode) {
        pNode->mpData = pData;
        pNode = NODE_GET_NEXT(pNode);
    }
}

/* 80244E68-80244E8C       .text cNd_ClearObject__FP10node_class */
void cNd_ClearObject(node_class* pNode) {
    cNd_SetObject(pNode, NULL);
}

/* 80244E8C-80244EA0       .text cNd_ForcedClear__FP10node_class */
void cNd_ForcedClear(node_class* pNode) {
    pNode->mpPrevNode = NULL;
    pNode->mpNextNode = NULL;
    pNode->mpData = NULL;
}

/* 80244EA0-80244EB4       .text cNd_Create__FP10node_classPv */
void cNd_Create(node_class* pNode, void* pData) {
    pNode->mpPrevNode = NULL;
    pNode->mpNextNode = NULL;
    pNode->mpData = pData;
}
