00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Mark Alexander 00008 * Side Effects Software Inc 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: TIL_HoldingQueue.C (TIL Library, C++) 00015 * 00016 * COMMENTS: 00017 * Queue with constant time head addition, tail removal and 00018 * internal removal. 00019 */ 00020 #ifndef TIL_HOLDING_QUEUE_H 00021 #define TIL_HOLDING_QUEUE_H 00022 00023 #include "TIL_API.h" 00024 class TIL_HoldingQueue; 00025 00026 class TIL_API TIL_HoldingNode 00027 { 00028 public: 00029 TIL_HoldingNode() : myPrev(0), myNext(0), myQueue(0) { } 00030 00031 TIL_HoldingNode *&prev() { return myPrev; } 00032 TIL_HoldingNode *&next() { return myNext; } 00033 00034 TIL_HoldingNode *prev() const { return myPrev; } 00035 TIL_HoldingNode *next() const { return myNext; } 00036 00037 void setQueue(TIL_HoldingQueue *q, bool update_queues=true); 00038 TIL_HoldingQueue *queue() const { return myQueue; } 00039 00040 private: 00041 TIL_HoldingNode *myPrev; 00042 TIL_HoldingNode *myNext; 00043 TIL_HoldingQueue *myQueue; 00044 }; 00045 00046 00047 class TIL_API TIL_HoldingQueue 00048 { 00049 public: 00050 TIL_HoldingQueue() : myHead(0), myTail(0), myEntries(0) {} 00051 ~TIL_HoldingQueue(); 00052 00053 // adds to head. 00054 void add(TIL_HoldingNode *newtile); 00055 00056 // removes an arbitrary tile. 00057 void remove(TIL_HoldingNode *tile); 00058 00059 // returns the last node off at the tail & removes it from the queue. 00060 TIL_HoldingNode * pop(); 00061 00062 // queries. 00063 TIL_HoldingNode * head() { return myHead; } 00064 bool isEmpty() const { return myHead == 0; } 00065 unsigned int entries() const { return myEntries; } 00066 00067 // clears out the queue and deletes the holding nodes if delete_nodes is 00068 // true. 00069 void empty(bool delete_nodes = true); 00070 00071 int traverse(int (*tfunc)(TIL_HoldingNode *, void *), 00072 void *data); 00073 private: 00074 TIL_HoldingNode *myHead; 00075 TIL_HoldingNode *myTail; 00076 unsigned int myEntries; 00077 }; 00078 00079 00080 #endif 00081
1.5.9