ICT290 / src / ShaysWorld / PlaneLinkedList.cpp
PlaneLinkedList.cpp
Raw
//  PlaneLinkedList.cpp
//
//  Implementation file for PlaneLinkedList Class
//  Defines all the methods declared, but not defined, in PlaneLinkedList.h
//
//  Shay Leary, April 2005
//--------------------------------------------------------------------------------------

#include "PlaneLinkedList.h"

//--------------------------------------------------------------------------------------

void PlaneLinkedList::Clear() {
    PlaneNode* ptr = m_first;

    while (ptr->GetNext() != NULL)

        // clear memory
        Delete(ptr);
}

//--------------------------------------------------------------------------------------

void PlaneLinkedList::Delete(PlaneNode* before) {
    PlaneNode* temp = before->GetNext();

    before->SetNext(temp->GetNext());

    delete temp;
}

//--------------------------------------------------------------------------------------

bool PlaneLinkedList::AddToStart(const int tempType,
                                 const GLdouble tempXs,
                                 const GLdouble tempXe,
                                 const GLdouble tempYs,
                                 const GLdouble tempYe,
                                 const GLdouble tempZs,
                                 const GLdouble tempZe) {
    PlaneNode* newNode;

    try {
        newNode = new PlaneNode;
    } catch (...) {
        return false;
    }

    // add the value to the node
    newNode->SetData(tempType, tempXs, tempXe, tempYs, tempYe, tempZs, tempZe);
    // set the address of the net node
    newNode->SetNext(m_first->GetNext());
    // reset the address of the first node
    m_first->SetNext(newNode);

    return true;
}

//--------------------------------------------------------------------------------------

GLdouble PlaneLinkedList::GetType(int ptrCount) {
    PlaneNode* ptr = (m_first);
    for (int count = 0; count < ptrCount; count++) {
        ptr = ptr->GetNext();
    }

    if (ptr->GetNext() != nullptr)
        return ptr->GetNext()->GetType();
    else
        return 0.0;
}

//--------------------------------------------------------------------------------------

GLdouble PlaneLinkedList::GetXstart(int ptrCount) {
    PlaneNode* ptr = (m_first);
    for (int count = 0; count < ptrCount; count++) {
        ptr = ptr->GetNext();
    }

    if (ptr->GetNext() != nullptr)
        return ptr->GetNext()->GetXstart();
    else
        return 0.0;
}

//--------------------------------------------------------------------------------------

GLdouble PlaneLinkedList::GetXend(int ptrCount) {
    PlaneNode* ptr = (m_first);
    for (int count = 0; count < ptrCount; count++) {
        ptr = ptr->GetNext();
    }

    if (ptr->GetNext() != nullptr)
        return ptr->GetNext()->GetXend();
    else
        return 0.0;
}

//--------------------------------------------------------------------------------------

GLdouble PlaneLinkedList::GetYstart(int ptrCount) {
    PlaneNode* ptr = (m_first);
    for (int count = 0; count < ptrCount; count++) {
        ptr = ptr->GetNext();
    }

    if (ptr->GetNext() != nullptr)
        return ptr->GetNext()->GetYstart();
    else
        return 0.0;
}

//--------------------------------------------------------------------------------------

GLdouble PlaneLinkedList::GetYend(int ptrCount) {
    PlaneNode* ptr = (m_first);
    for (int count = 0; count < ptrCount; count++) {
        ptr = ptr->GetNext();
    }

    if (ptr->GetNext() != nullptr)
        return ptr->GetNext()->GetYend();
    else
        return 0.0;
}

//--------------------------------------------------------------------------------------

GLdouble PlaneLinkedList::GetZstart(int ptrCount) {
    PlaneNode* ptr = (m_first);
    for (int count = 0; count < ptrCount; count++) {
        ptr = ptr->GetNext();
    }

    if (ptr->GetNext() != nullptr)
        return ptr->GetNext()->GetZstart();
    else
        return 0.0;
}

//--------------------------------------------------------------------------------------

GLdouble PlaneLinkedList::GetZend(int ptrCount) {
    PlaneNode* ptr = (m_first);
    for (int count = 0; count < ptrCount; count++) {
        ptr = ptr->GetNext();
    }

    if (ptr->GetNext() != nullptr)
        return ptr->GetNext()->GetZend();
    else
        return 0.0;
}

//--------------------------------------------------------------------------------------

void PlaneLinkedList::SetData(const int& ptrCount,
                              const int tempType,
                              const GLdouble tempXs,
                              const GLdouble tempXe,
                              const GLdouble tempYs,
                              const GLdouble tempYe,
                              const GLdouble tempZs,
                              const GLdouble tempZe) {
    PlaneNode* ptr = (m_first);

    for (int count = 0; count < ptrCount; count++) {
        ptr = ptr->GetNext();
    }
    ptr->GetNext()
        ->SetData(tempType, tempXs, tempXe, tempYs, tempYe, tempZs, tempZe);
}

//--------------------------------------------------------------------------------------

int PlaneLinkedList::GetListSize() {
    int tmpSize = 0;
    // count size of list
    for (PlaneNode* ptr = (m_first); ptr->GetNext() != NULL;
         ptr = ptr->GetNext()) {
        tmpSize++;
    }
    return tmpSize;
}

//--------------------------------------------------------------------------------------