00001 #ifndef __FBX_FBXINTRUSIVELIST_H__
00002 #define __FBX_FBXINTRUSIVELIST_H__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00042
00043 #include <kaydaradef.h>
00044 #ifndef KFBX_DLL
00045 #define KFBX_DLL K_DLLIMPORT
00046 #endif
00047
00048
00049
00050
00051
00052 #include <fbxfilesdk_nsbegin.h>
00053
00054 #define LISTNODE(classT, NodeCount)\
00055 public: inline KListNode<classT>& GetListNode(int index = 0){ return this->mNode[index]; }\
00056 private: KListNode<classT> mNode[NodeCount];
00057
00058
00059 template <typename T>
00060 class KListNode
00061 {
00062 typedef KListNode<T> NodeT;
00063
00064 public:
00065 explicit KListNode(T* pData = 0):mNext(0),mPrev(0),mData(pData){}
00066 ~KListNode()
00067 {
00068 Disconnect();
00069 }
00070
00071 void Disconnect()
00072 {
00073 if ( mPrev != 0 )
00074 mPrev->mNext = mNext;
00075
00076 if ( mNext != 0 )
00077 mNext->mPrev = mPrev;
00078
00079 mPrev = mNext = 0;
00080 }
00081
00082 NodeT* mNext;
00083 NodeT* mPrev;
00084
00085 T* mData;
00086 };
00087
00088
00089
00090
00091
00092 template <typename T, int NodeIndex=0>
00093 class KIntrusiveList
00094 {
00095 public:
00096 typedef T allocator_type;
00097 typedef T value_type;
00098 typedef T& reference;
00099 typedef const T& const_reference;
00100 typedef T* pointer;
00101 typedef const T* const_pointer;
00102
00103
00104 typedef KListNode<T> NodeT;
00105
00106
00107 KIntrusiveList():mHead(0)
00108 {
00109 mHead.mNext = mHead.mPrev = &mHead;
00110 }
00111 ~KIntrusiveList()
00112 {
00113 while(!Empty())
00114 Begin().Get()->Disconnect();
00115 };
00116
00117
00118 bool Empty() const
00119 {
00120 return ((mHead.mNext==&mHead)&&(mHead.mPrev==&mHead));
00121 }
00122
00123
00124 void PushBack(T& pElement)
00125 {
00126 NodeT* pNode = &pElement.GetListNode(NodeIndex);
00127 pNode->mData = &pElement;
00128
00129 if (Empty())
00130 {
00131 pNode->mNext = &mHead;
00132 pNode->mPrev = &mHead;
00133 mHead.mNext = pNode;
00134 mHead.mPrev = pNode;
00135 }
00136 else
00137 {
00138 pNode->mNext = &mHead;
00139 pNode->mPrev = mHead.mPrev;
00140
00141 pNode->mPrev->mNext = pNode;
00142 mHead.mPrev = pNode;
00143 }
00144 }
00145
00146 void PushFront(T& pElement)
00147 {
00148 NodeT* pNode = &pElement.GetListNode(NodeIndex);
00149 pNode->mData = &pElement;
00150
00151 if (Empty())
00152 {
00153 pNode->mNext = &mHead;
00154 pNode->mPrev = &mHead;
00155 mHead.mNext = pNode;
00156 mHead.mPrev = pNode;
00157 }
00158 else
00159 {
00160 pNode->mNext = mHead.mNext;
00161 pNode->mPrev = &mHead;
00162
00163 pNode->mNext->mPrev = pNode;
00164 mHead.mNext = pNode;
00165 }
00166 }
00167
00168 void PopFront()
00169 {
00170 Erase(Begin());
00171 }
00172
00173 void PopBack()
00174 {
00175 Erase(--(End()));
00176 }
00177
00178 public:
00179 class IntrusiveListIterator
00180 {
00181 public:
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 explicit IntrusiveListIterator(NodeT* ptr=0):mPtr(ptr){}
00192
00193
00194 IntrusiveListIterator& operator++()
00195 {
00196 mPtr = mPtr->mNext;return (*this);
00197 }
00198
00199 IntrusiveListIterator operator++(int)
00200 {
00201 IntrusiveListIterator temp = *this;
00202 ++*this;
00203 return (temp);
00204 }
00205
00206 IntrusiveListIterator& operator--()
00207 {
00208 mPtr = mPtr->mPrev;return *this;
00209 }
00210
00211 IntrusiveListIterator operator--(int)
00212 {
00213 IntrusiveListIterator temp = *this;
00214 --*this;
00215 return (temp);
00216 }
00217 IntrusiveListIterator& operator=(const IntrusiveListIterator &other){mPtr = other.mPtr; return *this;}
00218
00219 reference operator*() const { return *(mPtr->mData); }
00220 pointer operator->() const { return (&**this); }
00221 bool operator==(const IntrusiveListIterator& other)const{ return mPtr==other.mPtr; }
00222 bool operator!=(const IntrusiveListIterator& other)const{ return !(*this == other); }
00223
00224 inline NodeT* Get()const { return mPtr; }
00225
00226 private:
00227 NodeT* mPtr;
00228 };
00229
00230 class IntrusiveListConstIterator
00231 {
00232 public:
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 explicit IntrusiveListConstIterator(const NodeT* ptr=0):mPtr(ptr){}
00243
00244
00245 IntrusiveListConstIterator& operator++()
00246 {
00247 mPtr = mPtr->mNext;return (*this);
00248 }
00249
00250 IntrusiveListConstIterator& operator++(int)
00251 {
00252 IntrusiveListConstIterator temp = *this;
00253 ++*this;
00254 return (temp);
00255 }
00256
00257 IntrusiveListConstIterator& operator--()
00258 {
00259 mPtr = mPtr->mPrev;return *this;
00260 }
00261
00262 IntrusiveListConstIterator& operator--(int)
00263 {
00264 IntrusiveListConstIterator temp = *this;
00265 --*this;
00266 return (temp);
00267 }
00268 IntrusiveListConstIterator& operator=(const IntrusiveListConstIterator &other){mPtr = other.mPtr; return *this;}
00269
00270 const_reference operator*() const { return *(mPtr->mData); }
00271 const_pointer operator->() const { return (&**this); }
00272 bool operator==(const IntrusiveListConstIterator& other)const{ return mPtr==other.mPtr; }
00273 bool operator!=(const IntrusiveListConstIterator& other)const{ return !(*this == other); }
00274
00275 inline const NodeT* Get()const { return mPtr; }
00276
00277 private:
00278 mutable const NodeT* mPtr;
00279 };
00280
00281
00282 typedef IntrusiveListIterator iterator;
00283 typedef IntrusiveListConstIterator const_iterator;
00284
00285
00286 inline iterator Begin() { return iterator(mHead.mNext); }
00287 inline const_iterator Begin() const { return const_iterator(mHead.mNext); }
00288 inline iterator End() { return iterator(&mHead); }
00289 inline const_iterator End() const { return const_iterator(&mHead); }
00290
00291
00292
00293
00294
00295
00296
00297 reference Front(){return (*Begin());}
00298 const_reference Front() const { return (*Begin()); }
00299 reference Back(){ return (*(--End())); }
00300 const_reference Back() const{ return (*(--End())); }
00301
00302 iterator& Erase(iterator& it)
00303 {
00304 it.Get()->Disconnect();
00305 return (++it);
00306 }
00307 private:
00308 NodeT mHead;
00309
00310
00311 KIntrusiveList(const KIntrusiveList&);
00312 KIntrusiveList& operator=(const KIntrusiveList& Right){return (*this);}
00313 };
00314
00315
00316 #include <fbxfilesdk_nsend.h>
00317
00318
00319
00320
00321 #endif