void IteratorStack::operator++(int) { for(;;) { StackableIterator* top = Top(); if (top == 0) break; if ((traversalOrder == PreOrder) || (traversalOrder == PreAndPostOrder)) { void* current = top->CurrentUpCall(); (*top)++; // advance iterator at the top of stack if (current) { Push(IteratorToPushIfAny(current)); top = Top(); } } else (*top)++; // advance iterator at the top of stack if (top->IsValid() == false) { bool popped = false; while ((Top()->IsValid() == false) && (iteratorStackRepr->pstack.Depth() > 1)) { FreeTop(); popped = true; } if (popped && (enumType == ITER_STACK_ENUM_LEAVES_ONLY)) continue; } else if (traversalOrder == PostOrder) { void* current = top->CurrentUpCall(); if (current) { Push(IteratorToPushIfAny(current)); } } break; } }
//----------------------------------------------------------------------------------------------- void MemoryManager::FreeMemory( void* addressOfMemoryToFree ) { const byte_t* MAX_ADDRESS = m_memoryPool + POOL_SIZE; byte_t* addressAsByte_t = static_cast< byte_t* >( addressOfMemoryToFree ) - sizeof( MetaData ); MetaData* blockToFree = reinterpret_cast< MetaData* >( addressAsByte_t ); m_currentTotalBytesAllocated -= blockToFree->m_blockDataSegmentSize; if( addressAsByte_t == m_memoryPool ) { FreeTop( addressAsByte_t, blockToFree ); } else if( ( addressAsByte_t + blockToFree->m_blockDataSegmentSize + sizeof( MetaData ) ) >= MAX_ADDRESS ) { FreeBottom( addressAsByte_t, blockToFree ); } else { FreeGeneral( addressAsByte_t, blockToFree ); } }
// free the top (depth - maxDepth) elements on the stack, leaving at // most maxDepth elements on the stack: FreeStack(1) leaves at most one // element on the stack void IteratorStack::FreeStack(int maxDepth) { int depth = iteratorStackRepr->pstack.Depth(); while (depth-- > maxDepth) FreeTop(); }