Click here to Skip to main content
11,575,882 members (53,555 online)
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads
Add your own
alternative version

StL Data File Viewer

, 5 Mar 2003 CPOL 244.6K 8.9K 49
A simple StereoLithography data file viewer.
// ListOfCGLObject.cpp: implementation of the CListOfCGLObject class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ListOfCGLObject.h"
#include "ListIteratorOfListOfCGLObject.h"
#include "ListException.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CListOfCGLObject::CListOfCGLObject() : firstPtr(0), lastPtr(0)
{
}


CListOfCGLObject::~CListOfCGLObject()
{
	CListNodeOfCGLObject* curPtr = firstPtr, *tmp;
	if(!IsEmpty())
	{
		while(curPtr != 0)
		{
			tmp = curPtr;
			if(tmp->data)
			{
				delete tmp->data;
				tmp->data = 0;
			}
			curPtr = curPtr->nextPtr;
			delete tmp;
		}
	}
}


void CListOfCGLObject::Append( CGLObject* data)
{
	CListNodeOfCGLObject* newPtr = new CListNodeOfCGLObject(data);
	if(IsEmpty())
		firstPtr = lastPtr = newPtr;
	else
	{
		lastPtr->nextPtr = newPtr;
		lastPtr = newPtr;
	}
}


void CListOfCGLObject::Prepend( CGLObject* data)
{
	CListNodeOfCGLObject* newPtr = new CListNodeOfCGLObject(data);
	if(IsEmpty())
		firstPtr = lastPtr = newPtr;
	else
	{
		newPtr->nextPtr = firstPtr;
		firstPtr = newPtr;
	}
}

CGLObject* CListOfCGLObject::First() const
{
	if(IsEmpty())
		throw CListException(LIST_EMPTY);
	return firstPtr->GetData();
}

CGLObject* CListOfCGLObject::Last() const
{
	if(IsEmpty())
		throw CListException(LIST_EMPTY);
	return lastPtr->GetData();
}

CListNodeOfCGLObject* CListOfCGLObject::Previous(const CGLObject* O)
{
	CListIteratorOfListOfCGLObject it(this);
	for(it.Init(); it.More(); it.Next())
	{
		if(O == it.CurrentPtr()->nextPtr->data)
			break;
	}
	return it.CurrentPtr();
}

CGLObject* CListOfCGLObject::Remove(const CGLObject* O)
{
	if(IsEmpty())
		return 0;
	CGLObject* rO = 0;
	CListNodeOfCGLObject* tmp;
	if(O == First())
	{
		tmp = firstPtr;
		firstPtr = firstPtr->nextPtr;
		rO = tmp->data;
	}
	else
	{
		CListNodeOfCGLObject* p = Previous(O);
		if(p->nextPtr != NULL)
		{
			tmp = p->nextPtr;
			p->nextPtr = p->nextPtr->nextPtr;
			rO = tmp->data;
		}
	}
	tmp->data = 0;
	delete tmp->data;
	delete tmp;
	return rO;
}

bool CListOfCGLObject::IsEmpty() const
{
	return (firstPtr==0);
}		


void CListOfCGLObject::Clear()
{
	CListNodeOfCGLObject* curPtr = firstPtr, *tmp;
	if(!IsEmpty())
	{
		while(curPtr != 0)
		{
			tmp = curPtr;
			if(tmp->data)
			{
				delete tmp->data;
				tmp->data = 0;
			}
			curPtr = curPtr->nextPtr;
			delete tmp;
		}
		
		firstPtr = lastPtr = 0;
	}
}

CListNodeOfCGLObject* CListOfCGLObject::NewNode(CGLObject* P)
{
	CListNodeOfCGLObject* newPtr= new CListNodeOfCGLObject(P);
	if(!newPtr)
		throw CListException(LIST_OUT_OF_MEMORY);
	newPtr->nextPtr = 0;
	return newPtr;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sharjith
Engineer Tata Technologies Ltd
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150624.2 | Last Updated 6 Mar 2003
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid