AI_Node.h

Go to the documentation of this file.
00001 #ifndef AI_NODE_H
00002 #define AI_NODE_H
00003 
00004 #include "../AI_Global.h"
00005 
00006 //------------------------------------------------------------------------------
00019 //#include "kernel/ntypes.h"
00020 //#include "kernel/ndebug.h"
00021 
00022 //------------------------------------------------------------------------------
00023 class AI_Node 
00024 {
00025 public:
00027     AI_Node();
00029     AI_Node(void *ptr);
00031     ~AI_Node();
00033     AI_Node *GetSucc() const;
00035     AI_Node *GetPred() const;
00037     void InsertBefore(AI_Node *succ);
00039     void InsertAfter(AI_Node *pred);
00041     void Remove();
00043     void SetPtr(void *p);
00045     void *GetPtr() const;
00047     bool IsLinked() const;
00048 
00049 private:
00050     friend class AI_List;
00051     AI_Node *succ;
00052     AI_Node *pred;
00053     void *ptr;
00054 };
00055 
00056 //-----------------------------------------------------------------------------
00059 inline 
00060 AI_Node::AI_Node(void)
00061 : succ(0),
00062   pred(0),
00063   ptr(0)
00064 {
00065     // empty
00066 }
00067 
00068 //-----------------------------------------------------------------------------
00071 inline 
00072 AI_Node::AI_Node(void *_ptr)
00073 : succ(0),
00074   pred(0),
00075   ptr(_ptr)
00076 {
00077     // empty
00078 }
00079 
00080 //-----------------------------------------------------------------------------
00085 inline 
00086 AI_Node::~AI_Node(void)
00087 {
00088     ai_assert(!this->succ);
00089 }
00090 
00091 //-----------------------------------------------------------------------------
00098 inline
00099 AI_Node*
00100 AI_Node::GetSucc(void) const
00101 {
00102     ai_assert(this->succ);
00103     if (this->succ->succ) 
00104         return this->succ;
00105     else                  
00106         return 0;
00107 }
00108 
00109 //-----------------------------------------------------------------------------
00116 inline
00117 AI_Node*
00118 AI_Node::GetPred(void) const
00119 {
00120     ai_assert(this->pred);
00121     if (this->pred->pred) 
00122         return this->pred;
00123     else                  
00124         return NULL;
00125 }
00126 
00127 //-----------------------------------------------------------------------------
00131 inline 
00132 void 
00133 AI_Node::InsertBefore(AI_Node *succ)
00134 {
00135     ai_assert(succ->pred);
00136     ai_assert(!this->succ);
00137     AI_Node *pred = succ->pred;
00138     this->pred = pred;
00139     this->succ = succ;
00140     pred->succ = this;
00141     succ->pred = this;
00142 }
00143 
00144 //-----------------------------------------------------------------------------
00148 inline 
00149 void 
00150 AI_Node::InsertAfter(AI_Node *pred)
00151 {
00152     ai_assert(pred->succ);
00153     ai_assert(!this->succ);
00154     AI_Node *succ = pred->succ;
00155     this->pred = pred;
00156     this->succ = succ;
00157     pred->succ = this;
00158     succ->pred = this;
00159 }
00160 
00161 //-----------------------------------------------------------------------------
00164 inline 
00165 void 
00166 AI_Node::Remove(void)
00167 {
00168     ai_assert(this->succ);
00169     AI_Node *succ = this->succ;
00170     AI_Node *pred = this->pred;
00171     succ->pred = pred;
00172     pred->succ = succ;
00173     this->succ = NULL;
00174     this->pred = NULL;
00175 }
00176 
00177 //-----------------------------------------------------------------------------
00181 inline 
00182 void 
00183 AI_Node::SetPtr(void *p)
00184 {
00185     this->ptr = p;
00186 }
00187 
00188 //-----------------------------------------------------------------------------
00192 inline
00193 void*
00194 AI_Node::GetPtr() const
00195 {
00196     return this->ptr;
00197 }
00198 
00199 //-----------------------------------------------------------------------------
00203 inline 
00204 bool 
00205 AI_Node::IsLinked(void) const
00206 {
00207     if (this->succ) 
00208     {
00209         return true;
00210     }
00211     else
00212     {
00213         return false;
00214     }
00215 };
00216 
00217 //--------------------------------------------------------------------
00218 #endif