1 // File: NCollection_Queue.hxx
2 // Created: 17.04.02 10:12:48
3 // Author: Alexander Kartomin (akm)
4 // <a-kartomin@opencascade.com>
5 // Copyright: Open Cascade 2002
7 #ifndef NCollection_Queue_HeaderFile
8 #define NCollection_Queue_HeaderFile
10 #include <NCollection_TListIterator.hxx>
12 #if !defined No_Exception && !defined No_Standard_NoSuchObject
13 #include <Standard_NoSuchObject.hxx>
17 * Purpose: A queue is a structure where Items are added at
18 * the end and removed from the front. The first
19 * entered Item will be the first removed. This is
20 * called a FIFO (First In First Out).
21 * Inherits BaseList, adds the data item to each node.
23 template <class TheItemType> class NCollection_Queue
24 : public NCollection_BaseCollection<TheItemType>,
25 public NCollection_BaseList
28 typedef NCollection_TListNode<TheItemType> QueueNode;
29 typedef NCollection_TListIterator<TheItemType> Iterator;
32 // ---------- PUBLIC METHODS ------------
35 NCollection_Queue(const Handle(NCollection_BaseAllocator)& theAllocator=0L) :
36 NCollection_BaseCollection<TheItemType>(theAllocator),
37 NCollection_BaseList() {}
40 NCollection_Queue (const NCollection_Queue& theOther) :
41 NCollection_BaseCollection<TheItemType>(theOther.myAllocator),
42 NCollection_BaseList()
45 //! Size - Number of items
46 virtual Standard_Integer Size (void) const
49 //! Length - number of items
50 Standard_Integer Length (void) const
53 //! Replace this list by the items of theOther collection
54 virtual void Assign (const NCollection_BaseCollection<TheItemType>& theOther)
56 if (this == &theOther)
59 TYPENAME NCollection_BaseCollection<TheItemType>::Iterator& anIter =
60 theOther.CreateIterator();
61 for (; anIter.More(); anIter.Next())
63 QueueNode* pNew = new (this->myAllocator) QueueNode(anIter.Value());
68 //! Replace this list by the items of theOther queue
69 NCollection_Queue& operator= (const NCollection_Queue& theOther)
71 if (this == &theOther)
74 QueueNode * pCur = (QueueNode *) theOther.PFirst();
77 QueueNode* pNew = new (this->myAllocator) QueueNode(pCur->Value());
79 pCur = (QueueNode *) pCur->Next();
86 { PClear (QueueNode::delNode, this->myAllocator); }
88 //! Frontal item - constant
89 const TheItemType& Front (void) const
91 #if !defined No_Exception && !defined No_Standard_NoSuchObject
93 Standard_NoSuchObject::Raise ("NCollection_Queue::Front");
95 return ((const QueueNode *) PFirst())->Value();
98 //! Frontal item - variable
99 TheItemType& ChangeFront (void)
101 #if !defined No_Exception && !defined No_Standard_NoSuchObject
103 Standard_NoSuchObject::Raise ("NCollection_Queue::ChangeFront");
105 return ((QueueNode *) PFirst())->ChangeValue();
109 void Push (const TheItemType& theItem)
111 QueueNode * pNew = new (this->myAllocator) QueueNode(theItem);
117 { PRemoveFirst (QueueNode::delNode, this->myAllocator); }
119 //! Destructor - clears the List
120 ~NCollection_Queue (void)
124 // ----------- PRIVATE METHODS -----------
126 //! Creates Iterator for use on BaseCollection
127 virtual TYPENAME NCollection_BaseCollection<TheItemType>::Iterator&
128 CreateIterator(void) const
129 { return *(new (this->IterAllocator()) Iterator(*this)); }