Mercurial > ~dholland > hg > ag > index.cgi
diff anagram/support/agnotify.cpp @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/anagram/support/agnotify.cpp Sat Dec 22 17:52:45 2007 -0500 @@ -0,0 +1,89 @@ +/* + * AnaGram, A System for Syntax Directed Programming + * Copyright 1997-2002 Parsifal Software. All Rights Reserved. + * See the file COPYING for license and usage terms. + * + * agnotify.cpp + */ + +#include "agnotify.h" +#include "myalloc.h" + +//#define INCLUDE_LOGGING +#include "log.h" + + +AgNotificationActionBase::~AgNotificationActionBase() { + LOGSECTION("AgNotificationActionBase::~AgNotificationActionBase"); + LOGV(notifierStack.size()); + int n = notifierStack.size(); + while (n--) { + LOGV(n); + notifierStack[n]->remove(this); + } +} + +AgNotificationActionBase & +AgNotificationActionBase::attach(AgNotifierBase *notifier) { + LOGSECTION("AgNotificationActionBase::attach"); + notifierStack.push(notifier); + notifier->attach(this); + return *this; +} + +void AgNotificationActionBase::remove(AgNotifierBase *notifier) { + LOGSECTION("AgNotificationActionBase::remove"); + int i, n = notifierStack.size(); + ok_ptr(this); + ok_ptr(notifier); + for (i = 0; i < n; i++) { + if (notifierStack[i] == notifier) { + n--; + if (i < n) { + notifierStack[i] = notifierStack.pop(); + } + else { + notifierStack.pop(); + } + return; + } + } +} + +AgNotifierBase::~AgNotifierBase() { + LOGSECTION("AgNotifierBase::~AgNotifierBase"); + int n = notifyStack.size(); + while (n--) { + notifyStack[n]->remove(this); + } +} + +void AgNotifierBase::notify() { + LOGSECTION("AgNotifierBase::notify"); + int n = notifyStack.size(); + int i; + for (i = 0; i < n; i++) { + notifyStack[i]->perform(); + } +} + +void AgNotifierBase::remove(AgNotificationActionBase *action) { + LOGSECTION("AgNotifierBase::remove"); + int i, n = notifyStack.size(); + for (i = 0; i < n; i++) { + if (notifyStack[i] == action) { + n--; + LOGV(i); + LOGV(n); + LOGV(notifyStack.size()); + if (i < n) { + notifyStack[i] = notifyStack.pop(); + } + else { + notifyStack.pop(); + } + return; + } + } +} +