00001 /* 00002 // $Id: //open/dev/fennel/common/RawIntrusiveList.h#10 $ 00003 // Fennel is a library of data storage and processing components. 00004 // Copyright (C) 2005-2009 The Eigenbase Project 00005 // Copyright (C) 2005-2009 SQLstream, Inc. 00006 // Copyright (C) 2005-2009 LucidEra, Inc. 00007 // Portions Copyright (C) 1999-2009 John V. Sichi 00008 // 00009 // This program is free software; you can redistribute it and/or modify it 00010 // under the terms of the GNU General Public License as published by the Free 00011 // Software Foundation; either version 2 of the License, or (at your option) 00012 // any later version approved by The Eigenbase Project. 00013 // 00014 // This program is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with this program; if not, write to the Free Software 00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 */ 00023 00024 #ifndef Fennel_RawIntrusiveList_Included 00025 #define Fennel_RawIntrusiveList_Included 00026 00027 FENNEL_BEGIN_NAMESPACE 00028 00029 class RawIntrusiveList; 00030 class RawIntrusiveListIter; 00031 class RawIntrusiveListMutator; 00032 00037 class FENNEL_COMMON_EXPORT RawIntrusiveList 00038 { 00039 friend class RawIntrusiveListIter; 00040 friend class RawIntrusiveListMutator; 00041 00042 protected: 00046 uint nNodes; 00047 00051 IntrusiveListNode *pFront; 00052 00056 IntrusiveListNode *pBack; 00057 00058 explicit RawIntrusiveList() 00059 { 00060 pFront = NULL; 00061 pBack = NULL; 00062 nNodes = 0; 00063 } 00064 00065 IntrusiveListNode &front() const 00066 { 00067 return *pFront; 00068 } 00069 00070 IntrusiveListNode &back() const 00071 { 00072 return *pBack; 00073 } 00074 00075 void push_front(IntrusiveListNode &t); 00076 00077 void push_back(IntrusiveListNode &t); 00078 00079 bool remove(IntrusiveListNode &); 00080 00081 public: 00085 uint size() const 00086 { 00087 return nNodes; 00088 } 00089 00093 bool empty() const 00094 { 00095 return nNodes ? false : true; 00096 } 00097 00104 void clear(bool debugClear = true); 00105 }; 00106 00111 class FENNEL_COMMON_EXPORT RawIntrusiveListIter { 00112 protected: 00113 IntrusiveListNode *pCurr; 00114 00115 explicit RawIntrusiveListIter() 00116 : pCurr(NULL) 00117 { 00118 } 00119 00120 explicit RawIntrusiveListIter(RawIntrusiveList const &l) 00121 : pCurr(l.pFront) 00122 { 00123 } 00124 00125 IntrusiveListNode *getCurrent() const 00126 { 00127 return pCurr; 00128 } 00129 00130 void repositionToFront(RawIntrusiveList const &l) 00131 { 00132 pCurr = l.pFront; 00133 } 00134 00135 public: 00139 void operator ++ () 00140 { 00141 if (pCurr) { 00142 pCurr = pCurr->pNext; 00143 } 00144 } 00145 }; 00146 00151 class FENNEL_COMMON_EXPORT RawIntrusiveListMutator 00152 { 00153 friend class RawIntrusiveList; 00154 00155 protected: 00156 IntrusiveListNode *pCurr,*pPrev; 00157 RawIntrusiveList *pList; 00158 bool bJustDeleted; 00159 00160 explicit RawIntrusiveListMutator() 00161 { 00162 pList = NULL; 00163 pCurr = pPrev = NULL; 00164 bJustDeleted = 0; 00165 } 00166 00167 explicit RawIntrusiveListMutator(RawIntrusiveList &l) 00168 : pCurr(l.pFront), pPrev(NULL), pList(&l) 00169 { 00170 bJustDeleted = 0; 00171 } 00172 00173 IntrusiveListNode *getCurrent() const 00174 { 00175 return pCurr; 00176 } 00177 00178 void repositionToFront(RawIntrusiveList &l) 00179 { 00180 pList = &l; 00181 bJustDeleted = 0; 00182 pCurr = pList->pFront; 00183 pPrev = NULL; 00184 } 00185 00186 IntrusiveListNode *detach(); 00187 00188 public: 00192 void operator ++ () 00193 { 00194 if (bJustDeleted) { 00195 bJustDeleted = 0; 00196 } else { 00197 pPrev = pCurr; 00198 if (pCurr) { 00199 pCurr = pCurr->pNext; 00200 } 00201 } 00202 } 00203 00208 void promoteCurrToFront(); 00209 00214 void demoteCurrToBack(); 00215 00220 void demoteFrontBeforeCurr(); 00221 00225 void repositionToFront() 00226 { 00227 bJustDeleted = 0; 00228 pCurr = pList->pFront; 00229 pPrev = NULL; 00230 } 00231 }; 00232 00233 FENNEL_END_NAMESPACE 00234 00235 #endif 00236 00237 // End RawIntrusiveList.h