📄 delmon.cpp
字号:
/* Copyright (C) 2004-2005 Darrell Karbott (djk2005@users.sf.net)
** This code is free software; you can redistribute it and/or
** modify it under the terms of GNU Lesser General Public License.
** See http://www.gnu.org/ for further details of the LGPL.
**/
#include "delmon.h"
CNotifyOnDelete::CNotifyOnDelete() : iDeleted( NULL ) {}
void CNotifyOnDelete::MarkDeleted() {
if (iDeleted) {
*iDeleted = true;
iDeleted = NULL;
}
}
CNotifyOnDelete::~CNotifyOnDelete()
{
if (iDeleted) {
*iDeleted = true;
}
}
TBool* CNotifyOnDelete::SetObserver(TBool* flagToSet)
{
TBool* old = iDeleted;
iDeleted = flagToSet;
return old;
}
TDeletionMonitor::TDeletionMonitor(CNotifyOnDelete* pNotifier) : iNotifier( pNotifier), iWasDeleted(false)
{
iOldFlag = pNotifier->SetObserver(&iWasDeleted);
}
TDeletionMonitor::~TDeletionMonitor()
{
if (iOldFlag) {
// i.e. Propagate the flag value up the stack as the stack unwinds.
// Cool huh.
*iOldFlag = iWasDeleted;
}
if (!iWasDeleted) {
// Restore the flag hook for the stack frame above us.
iNotifier->SetObserver(iOldFlag);
}
}
TBool TDeletionMonitor::WasDeleted() const { return iWasDeleted; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -