newspeoplefor developersdocumentationdownloads

nnode.h

Go to the documentation of this file.
00001 #ifndef N_NODE_H
00002 #define N_NODE_H
00003 //------------------------------------------------------------------------------
00012 #include "kernel/ntypes.h"
00013 #include "kernel/ndebug.h"
00014 
00015 //------------------------------------------------------------------------------
00016 class nNode
00017 {
00018 public:
00020     nNode();
00022     nNode(void* ptr);
00024     ~nNode();
00026     nNode* GetSucc() const;
00028     nNode* GetPred() const;
00030     void InsertBefore(nNode* succ);
00032     void InsertAfter(nNode* pred);
00034     void Remove();
00036     void SetPtr(void* p);
00038     void* GetPtr() const;
00040     bool IsLinked() const;
00041 
00042 private:
00043     friend class nList;
00044     nNode* succ;
00045     nNode* pred;
00046     void* ptr;
00047 };
00048 
00049 //-----------------------------------------------------------------------------
00052 inline
00053 nNode::nNode(void)
00054 : succ(0),
00055   pred(0),
00056   ptr(0)
00057 {
00058     // empty
00059 }
00060 
00061 //-----------------------------------------------------------------------------
00064 inline
00065 nNode::nNode(void *_ptr)
00066 : succ(0),
00067   pred(0),
00068   ptr(_ptr)
00069 {
00070     // empty
00071 }
00072 
00073 //-----------------------------------------------------------------------------
00078 inline
00079 nNode::~nNode(void)
00080 {
00081     n_assert(!this->succ);
00082 }
00083 
00084 //-----------------------------------------------------------------------------
00091 inline
00092 nNode*
00093 nNode::GetSucc(void) const
00094 {
00095     n_assert(this->succ);
00096     if (this->succ->succ)
00097         return this->succ;
00098     else
00099         return 0;
00100 }
00101 
00102 //-----------------------------------------------------------------------------
00109 inline
00110 nNode*
00111 nNode::GetPred(void) const
00112 {
00113     n_assert(this->pred);
00114     if (this->pred->pred)
00115         return this->pred;
00116     else
00117         return NULL;
00118 }
00119 
00120 //-----------------------------------------------------------------------------
00124 inline
00125 void
00126 nNode::InsertBefore(nNode* succ)
00127 {
00128     n_assert(succ->pred);
00129     n_assert(!this->succ);
00130     this->pred = succ->pred;
00131     this->succ = succ;
00132     this->pred->succ = this;
00133     succ->pred = this;
00134 }
00135 
00136 //-----------------------------------------------------------------------------
00140 inline
00141 void
00142 nNode::InsertAfter(nNode* pred)
00143 {
00144     n_assert(pred->succ);
00145     n_assert(!this->succ);
00146     this->pred = pred;
00147     this->succ = pred->succ;
00148     pred->succ = this;
00149     this->succ->pred = this;
00150 }
00151 
00152 //-----------------------------------------------------------------------------
00155 inline
00156 void
00157 nNode::Remove(void)
00158 {
00159     n_assert(this->succ);
00160     this->succ->pred = this->pred;
00161     this->pred->succ = this->succ;
00162     this->succ = NULL;
00163     this->pred = NULL;
00164 }
00165 
00166 //-----------------------------------------------------------------------------
00170 inline
00171 void
00172 nNode::SetPtr(void* p)
00173 {
00174     this->ptr = p;
00175 }
00176 
00177 //-----------------------------------------------------------------------------
00181 inline
00182 void*
00183 nNode::GetPtr() const
00184 {
00185     return this->ptr;
00186 }
00187 
00188 //-----------------------------------------------------------------------------
00192 inline
00193 bool
00194 nNode::IsLinked(void) const
00195 {
00196     return this->succ != 0;
00197 }
00198 
00199 //--------------------------------------------------------------------
00200 #endif

Copyright © 1999-2005 by the contributing authors. Ideas, requests, problems: Send feedback.