AI_List.h
Go to the documentation of this file.00001 #ifndef AI_LIST_H 00002 #define AI_LIST_H 00003 //------------------------------------------------------------------------------ 00016 //#include "kernel/ntypes.h" 00017 //#include "kernel/ndebug.h" 00018 #include "AI_Node.h" 00019 00020 //------------------------------------------------------------------------------ 00021 class AI_List 00022 { 00023 public: 00025 AI_List(); 00027 ~AI_List(); 00029 bool IsEmpty() const; 00031 AI_Node* GetHead() const; 00033 AI_Node* GetTail() const; 00035 void AddHead(AI_Node* n); 00037 void AddTail(AI_Node* n); 00039 AI_Node* RemHead(); 00041 AI_Node* RemTail(); 00042 00043 private: 00044 AI_Node* head; 00045 AI_Node* tail; 00046 AI_Node* tailpred; 00047 }; 00048 00049 //----------------------------------------------------------------------------- 00052 inline 00053 AI_List::AI_List() 00054 { 00055 this->head = (AI_Node *) &(this->tail); 00056 this->tail = 0; 00057 this->tailpred = (AI_Node *) &(this->head); 00058 } 00059 00060 //----------------------------------------------------------------------------- 00065 inline AI_List::~AI_List() 00066 { 00067 ai_assert(0 == this->head->succ); 00068 } 00069 00070 //----------------------------------------------------------------------------- 00074 inline 00075 bool 00076 AI_List::IsEmpty() const 00077 { 00078 return (this->head->succ == 0); 00079 } 00080 00081 //----------------------------------------------------------------------------- 00085 inline 00086 AI_Node* 00087 AI_List::GetHead() const 00088 { 00089 if (this->head->succ) 00090 { 00091 return this->head; 00092 } 00093 else 00094 { 00095 return 0; 00096 } 00097 } 00098 00099 //----------------------------------------------------------------------------- 00103 inline 00104 AI_Node* 00105 AI_List::GetTail() const 00106 { 00107 if (this->tailpred->pred) 00108 { 00109 return this->tailpred; 00110 } 00111 else 00112 { 00113 return NULL; 00114 } 00115 } 00116 00117 //----------------------------------------------------------------------------- 00121 inline 00122 void 00123 AI_List::AddHead(AI_Node *n) 00124 { 00125 n->InsertAfter((AI_Node *) &(this->head)); 00126 } 00127 00128 //----------------------------------------------------------------------------- 00132 inline 00133 void 00134 AI_List::AddTail(AI_Node *n) 00135 { 00136 n->InsertBefore((AI_Node *) &(this->tail)); 00137 } 00138 00139 //----------------------------------------------------------------------------- 00146 inline AI_Node *AI_List::RemHead() 00147 { 00148 AI_Node *n = this->head; 00149 if (n->succ) 00150 { 00151 n->Remove(); 00152 return n; 00153 } 00154 else 00155 { 00156 return 0; 00157 } 00158 } 00159 00160 //----------------------------------------------------------------------------- 00167 inline AI_Node *AI_List::RemTail() 00168 { 00169 AI_Node *n = this->tailpred; 00170 if (n->pred) 00171 { 00172 n->Remove(); 00173 return n; 00174 } 00175 else 00176 { 00177 return 0; 00178 } 00179 } 00180 //-------------------------------------------------------------------- 00181 #endif