Changeset 32445 in vbox
- Timestamp:
- Sep 13, 2010 12:22:30 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 65813
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/list.h
r28800 r32445 228 228 229 229 /** 230 * Enumerate the list in head to tail order, safe against removal of the 231 * current node. 232 * 233 * @param pList List to enumerate. 234 * @param pIterator The iterator variable name. 235 * @param pIterNext The name of the variable saving the pointer to 236 * the next element. 237 * @param Type Structure the list node is a member of. 238 * @param Member The list node member name. 239 */ 240 #define RTListForEachSafe(pList, pIterator, pIterNext, Type, Member) \ 241 for (pIterator = RTListNodeGetNext(pList, Type, Member), \ 242 pIterNext = RT_FROM_MEMBER((pIterator)->Member.pNext, Type, Member); \ 243 !RTListNodeIsDummy(pList, pIterator, Type, Member); \ 244 pIterator = pIterNext, \ 245 pIterNext = RT_FROM_MEMBER((pIterator)->Member.pNext, Type, Member) ) 246 247 248 /** 230 249 * Enumerate the list in reverse order (tail to head). 231 250 * … … 242 261 243 262 /** 263 * Enumerate the list in reverse order (tail to head). 264 * 265 * @param pList List to enumerate. 266 * @param pIterator The iterator variable name. 267 * @param pIterPrev The name of the variable saving the pointer to 268 * the previous element. 269 * @param Type Structure the list node is a member of. 270 * @param Member The list node member name. 271 */ 272 #define RTListForEachReverseSafe(pList, pIterator, pIterPrev, Type, Member) \ 273 for (pIterator = RTListNodeGetPrev(pList, Type, Member), \ 274 pIterPrev = RT_FROM_MEMBER((pIterator)->Member.pPrev, Type, Member); \ 275 !RTListNodeIsDummy(pList, pIterator, Type, Member); \ 276 pIterator = pIterPrev, \ 277 pIterPrev = RT_FROM_MEMBER((pIterator)->Member.pPrev, Type, Member) ) 278 279 280 /** 244 281 * Move the given list to a new list header. 245 282 * -
trunk/src/VBox/Runtime/testcase/tstRTList.cpp
r28800 r32445 106 106 static void tstRTListCreate(RTTEST hTest, unsigned cElements) 107 107 { 108 RTTestISubF(" RTList - Test with%u elements", cElements);108 RTTestISubF("Creating and moving - %u elements", cElements); 109 109 110 110 RTLISTNODE ListHead; … … 140 140 tstRTListOrder(hTest, &ListHeadNew, cElements, 0, cElements-1, 1); 141 141 142 /* Remove elements now */ 142 /* 143 * Safe iteration w/ removal. 144 */ 145 RTTestISubF("Safe iteration w/ removal - %u elements", cElements); 146 147 /* Move it element by element. */ 148 PLISTELEM pNode, pSafe; 149 RTListForEachSafe(&ListHeadNew, pNode, pSafe, LISTELEM, Node) 150 { 151 RTListNodeRemove(&pNode->Node); 152 RTListAppend(&ListHead, &pNode->Node); 153 } 154 tstRTListOrder(hTest, &ListHead, cElements, 0, cElements-1, 1); 155 156 /* And the other way. */ 157 RTListForEachReverseSafe(&ListHead, pNode, pSafe, LISTELEM, Node) 158 { 159 RTListNodeRemove(&pNode->Node); 160 RTListPrepend(&ListHeadNew, &pNode->Node); 161 } 162 tstRTListOrder(hTest, &ListHeadNew, cElements, 0, cElements-1, 1); 163 164 /* 165 * Remove elements now. 166 */ 143 167 if (cElements > 1) 144 168 { 145 169 /* Remove every second */ 146 RTTestISub ("Remove every second node");147 148 PLISTELEMpNode = RTListNodeGetFirst(&ListHeadNew, LISTELEM, Node);170 RTTestISubF("Remove every second node - %u elements", cElements); 171 172 pNode = RTListNodeGetFirst(&ListHeadNew, LISTELEM, Node); 149 173 for (unsigned i = 0; i < cElements; i++) 150 174 { … … 168 192 169 193 /* Remove the rest now. */ 170 RTTestISub ("Remove all nodes");171 PLISTELEMpNode = RTListNodeGetFirst(&ListHeadNew, LISTELEM, Node);194 RTTestISubF("Remove all nodes - %u elements", cElements); 195 pNode = RTListNodeGetFirst(&ListHeadNew, LISTELEM, Node); 172 196 for (unsigned i = 0; i < cElements; i++) 173 197 {
Note:
See TracChangeset
for help on using the changeset viewer.