You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
3.5 KiB
C++

///////////////////////////////////////////////////////////////////////////////
//
// ## ######
// ###### ### Based on:
// ## ###############
// ########## # # # Shark 3D Engine (www.shark3d.com)
// ########
// ######### # # # Copyright (c) 1996-2001 Spinor GmbH.
// ## ##########
// ##
//
///////////////////////////////////////////////////////////////////////////////////
//
// G A M E.O.N.E - LOW LEVEL LIB V1.0
// Copyright (C) 2001 LEVEL ONE ENTERTAINMENT,
// Licensed under the terms of LGPL.
//:---------------------------------------------------------------------------
//:Description
//
// LOW LEVEL QUEUE_LIST HEADERFILE
//
#ifndef _LLQUEUE_LIST_H
#define _LLQUEUE_LIST_H
#include "lib_base.h"
class queue_listhead;
class queue_listnode;
/*
* Double Linked List Node
*/
class queue_listnode {
public:
queue_listnode();
~queue_listnode();
queue_listnode *GetPrev() const;
queue_listnode *GetNext() const;
queue_listhead *GetBase() const;
bool IsInserted() const;
void Extract();
private:
queue_listnode *m_Prev;
queue_listnode *m_Next;
queue_listhead *m_Base;
friend class queue_listhead;
};
/*
* Double Linked List Header
*/
class queue_listhead {
public:
typedef queue_listnode CNode;
queue_listhead();
~queue_listhead();
// retrieve elements and information
queue_listnode *GetFirst() const;
queue_listnode *GetLast() const;
bool IsEmpty() const;
bool Contains(queue_listnode *Node);
int GetCount() const;
// inserting elements
void InsertFront(queue_listnode *Node);
void InsertBack(queue_listnode *Node);
void InsertAfter(queue_listnode *Node, queue_listnode *Pos); //if Pos==0 then InsertFront()
void InsertBefore(queue_listnode *Node, queue_listnode *Pos); //if Pos==0 then InstertBack()
// delete all
void ExtractAll();
private:
queue_listnode *m_First;
queue_listnode *m_Last;
int m_Count;
friend class queue_listnode;
// copy und copyconstructor are private
queue_listhead(const queue_listhead &List);
queue_listhead &operator=(const queue_listhead &List);
};
/*
* Implementation queue_listnode
*/
inline queue_listnode::queue_listnode()
{
m_Prev = m_Next = 0;
m_Base = 0;
}
inline queue_listnode::~queue_listnode()
{
Extract();
}
inline queue_listnode *queue_listnode::GetPrev() const
{
SYS_ASSERT_PTR(this);
return m_Prev;
}
inline queue_listnode *queue_listnode::GetNext() const
{
SYS_ASSERT_PTR(this);
return m_Next;
}
inline queue_listhead *queue_listnode::GetBase() const
{
SYS_ASSERT_PTR(this);
return m_Base;
}
inline bool queue_listnode::IsInserted() const
{
SYS_ASSERT_PTR(this);
return m_Base != 0;
}
/*
* Implementation listheader
*/
inline queue_listhead::queue_listhead()
{
SYS_ASSERT_PTR(this);
m_First = m_Last = 0;
m_Count = 0;
}
inline queue_listhead::~queue_listhead()
{
SYS_ASSERT_PTR(this);
ExtractAll();
}
inline queue_listnode *queue_listhead::GetFirst() const
{
SYS_ASSERT_PTR(this);
return m_First;
}
inline queue_listnode *queue_listhead::GetLast() const
{
SYS_ASSERT_PTR(this);
return m_Last;
}
inline bool queue_listhead::IsEmpty() const
{
SYS_ASSERT_PTR(this);
return !m_First;
}
inline bool queue_listhead::Contains(queue_listnode *Node)
{
SYS_ASSERT_PTR(this);
return Node && Node->m_Base == this;
}
inline int queue_listhead::GetCount() const
{
SYS_ASSERT_PTR(this);
return m_Count;
}
#endif