void MarkedStack::Release(void) { // Find the mark to stop at ListItemPtrItem* MarkRec = (ListItemPtrItem*)MarkStack.Pop(); ListItem* Mark; if (MarkRec == NULL) // There are no marks to find { Mark = NULL; } else { Mark = MarkRec->pListItem; } ListItem* TopOfStack = GetTail(); ListItem* AsGoodAsDead; while (TopOfStack != Mark) // Loop until we find Mark { ENSURE(TopOfStack != NULL, "A Mark could not be found in the Marked stack"); TopOfStack = GetPrev(TopOfStack); AsGoodAsDead = RemoveTail(); delete AsGoodAsDead; } if (MarkRec != NULL) { delete (MarkRec); // Restored State to that pointed to by Mark, so delete it } }
///////////////////////////////////////////////////////////////////////////// // Note: The undo list must be maintained as a string of undos // You cannot, for example, log an undo event and then decide to // to skip a few. To skip, the entire log must be deleted. // The invoking routines typically accept a NULL undo description // to indicate continuation; to stop undo, destroy the chain and // call with a NULL, thus not creating an undo event. ///////////////////////////////////////////////////////////////////////////// POSITION CUndLst::CreUndEvt (CString csDesStr, CUndSta *pNewSta) { ///////////////////////////////////////////////////////////////////////// // Delete tail of undo chain ///////////////////////////////////////////////////////////////////////// while (!IsEmpty() && (m_vpUndPos != m_olUndLst.GetTailPosition())) RemoveTail(); ///////////////////////////////////////////////////////////////////////// // Return NULL if undo has been inhibited ///////////////////////////////////////////////////////////////////////// if (!m_usUndMax) return (NULL); ///////////////////////////////////////////////////////////////////////// // Delete head to enforce maximum undo count; leave room for next ///////////////////////////////////////////////////////////////////////// while ((WORD) m_olUndLst.GetCount() >= m_usUndMax) RemoveHead(); ///////////////////////////////////////////////////////////////////////// // Find previous files 3 digit extension and increment ///////////////////////////////////////////////////////////////////////// WORD usNxtExt = IsEmpty() ? 0 : GetTail()->GetSeqNum() + 1; ///////////////////////////////////////////////////////////////////////// // Add new undo file ///////////////////////////////////////////////////////////////////////// m_vpUndPos = m_olUndLst.AddTail (new CUndEvt (usNxtExt, m_csTmpPfx, csDesStr, pNewSta)); return (m_vpUndPos); }
void CUndLst::ClrUndLst () { ///////////////////////////////////////////////////////////////////////// // Remove tail until NULL ///////////////////////////////////////////////////////////////////////// while (!IsEmpty() && (m_vpUndPos = m_olUndLst.GetTailPosition())) RemoveTail(); }
void CXTPSyntaxEditUndoRedoManager::SetGroupInsertMode(BOOL bInsertInGroup) { if (m_bGroupInsertMode == bInsertInGroup) return; m_bGroupInsertMode = bInsertInGroup; if (m_bGroupInsertMode) { // add empty batch command RemoveTail(); m_CommandList.AddTail(new CXTPSyntaxEditBatchCommand()); m_posFirstUndo = m_CommandList.GetTailPosition(); } else { // delete empty batch command if necessary CXTPSyntaxEditCommand* pCmd = m_CommandList.GetTailPosition() ? (CXTPSyntaxEditCommand*)m_CommandList.GetTail() : NULL; CXTPSyntaxEditBatchCommand* pBatchCmd = DYNAMIC_DOWNCAST(CXTPSyntaxEditBatchCommand, pCmd); if (pBatchCmd && pBatchCmd->GetCommandsCount() < 1) { m_CommandList.RemoveTail(); delete pBatchCmd; m_posFirstUndo = m_CommandList.GetTailPosition(); } } }
void CXTPSyntaxEditUndoRedoManager::AddCommand(CXTPSyntaxEditCommand* pCommand) { RemoveTail(); LimitDataSize(pCommand->GetDataSize(), m_nDataSizeLimit); // insert undo command if (!m_bGroupInsertMode) { m_CommandList.AddTail(pCommand); } else { CXTPSyntaxEditCommand* pCmd = m_CommandList.GetTailPosition() ? (CXTPSyntaxEditCommand*)m_CommandList.GetTail() : NULL; CXTPSyntaxEditBatchCommand* pBatchCmd = DYNAMIC_DOWNCAST(CXTPSyntaxEditBatchCommand, pCmd); if (!pBatchCmd) { pBatchCmd = new CXTPSyntaxEditBatchCommand(); m_CommandList.AddTail(pBatchCmd); } pBatchCmd->AddCommand(pCommand); } m_posFirstUndo = m_CommandList.GetTailPosition(); }
void CRecentFuncList::AddFunc(CFunc func) { POSITION rPos = GetHeadPosition(); while (rPos) { POSITION pos = rPos; if (GetNext(rPos) == func) RemoveAt(pos); } AddHead(func); if (GetCount() > m_MaxSize) RemoveTail(); }
bool DLList::RemoveFirstOccurence(int remove_node) { DLNode *temp = NULL; //creates a temp pointer to hold the node to be deleted DLNode *iterator = head_; //creates an iterator and makes it point to head_ DLNode *iterator2 = NULL; //second iterator to trail behind the first iterator while(iterator != NULL) { if((iterator -> contents()) == remove_node) { if(iterator2 == NULL) { RemoveHead(); return true; } else if((iterator -> next_node()) == NULL) { RemoveTail(); return true; } else { temp = iterator; //points to the node that will be deleted iterator = iterator -> next_node(); //iterator points to the node after the one to be deleted iterator2 -> set_next_node(iterator); //iterator2's node sets the next node to iterator's node, skipping over the soon to be deleted node iterator -> set_previous_node(iterator2); //iterator's node sets the previous node to iterator2's node delete temp; //deletes the node temp = NULL; //sets temp to NULL size_--; //size of linked list decreases return true; } } else { iterator2 = iterator; iterator = iterator -> next_node(); } } return false; }
bool SLList::RemoveFirstOccurence(int contents) { //returns false for empty list if (head_ == NULL) { return false; // uses RemoveTail() if tail == contents } else if (tail_->contents() == contents) { RemoveTail(); return true; } else { //creating pointers SLNode* iterator = head_, *temp = head_->next_node(); //traverses to find match for contents while (contents != temp->contents() && temp->next_node() != NULL) { temp = temp->next_node(); iterator = iterator->next_node(); } //returns false if contents are not in list if (temp == tail_ && temp->contents() != contents) { return false; } else //checks if temp is the node to delete then executes if(temp->contents() == contents) { iterator->set_next_node(temp->next_node()); delete temp; size_ = size_ - 1; temp = NULL; return true; } } }
bool SLList::RemoveFirstOccurence(int contents) { SLNode* node = new SLNode(contents); if (contents == GetHead()) { RemoveHead(); return true; } else if(contents == GetTail()) { RemoveTail(); return true; } else if(head_ == NULL) { return false; } else if (node == NULL) { return false; } else if (contents != GetHead() && contents != GetTail()) { SLNode* i = head_; SLNode* j = NULL; while (i->contents() != contents && i->next_node() != NULL) { j = i; i = i->next_node(); } if(i->next_node() == NULL && i->contents() != contents) { return false; } else { SLNode* temp = i->next_node(); SLNode* temp2 = i; delete temp2; j->set_next_node(temp); size_--; return true; } } else return false; }
bool CDVDPositionList::AddEntry(ULONGLONG llDVDGuid) { // Look for the file position POSITION pos = GetHeadPosition(); while (pos) { DVD_POSITION& dvdPosition = GetAt(pos); // If we find it, we move it at the top of the list if (dvdPosition.llDVDGuid == llDVDGuid) { if (pos != GetHeadPosition()) { AddHead(dvdPosition); RemoveAt(pos); // Save asynchronously the list SaveAsync(); } return false; } GetNext(pos); } // Add the new position DVD_POSITION dvdPosition = { llDVDGuid, 0, 0 }; AddHead(dvdPosition); // Ensure the list doesn't grow indefinitely if (GetCount() > m_nMaxSize) { RemoveTail(); } // Save asynchronously the list SaveAsync(); return true; }
bool CFilePositionList::AddEntry(LPCTSTR lpszFileName) { // Look for the file position POSITION pos = GetHeadPosition(); while (pos) { FILE_POSITION& filePosition = GetAt(pos); // If we find it, we move it at the top of the list if (filePosition.strFile == lpszFileName) { if (pos != GetHeadPosition()) { AddHead(filePosition); RemoveAt(pos); // Save asynchronously the list SaveAsync(); } return false; } GetNext(pos); } // Add the new position FILE_POSITION filePosition = { lpszFileName, 0 }; AddHead(filePosition); // Ensure the list doesn't grow indefinitely if (GetCount() > m_nMaxSize) { RemoveTail(); } // Save asynchronously the list SaveAsync(); return true; }
ListItem* MarkedStack::Pop(void) { return (RemoveTail()); }
//蛇移动一次,返回舍弃的尾部数据 UnitPosition Snake::Move() { UnitPosition pos = UnitPosition(head->Data.ColIndex, head->Data.RowIndex); pos.Move(moveDirection); InsertAsHead(pos); return RemoveTail(); }
void DocPrintMarkList::RemoveAllMarks() { DocPrintMark* pItem; while ((pItem=((DocPrintMark*)RemoveTail()))!=NULL) delete pItem; }