comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1 /*
2 * AnaGram, A System for Syntax Directed Programming
3 * Copyright 1997-2002 Parsifal Software. All Rights Reserved.
4 * See the file COPYING for license and usage terms.
5 *
6 * agnotify.cpp
7 */
8
9 #include "agnotify.h"
10 #include "myalloc.h"
11
12 //#define INCLUDE_LOGGING
13 #include "log.h"
14
15
16 AgNotificationActionBase::~AgNotificationActionBase() {
17 LOGSECTION("AgNotificationActionBase::~AgNotificationActionBase");
18 LOGV(notifierStack.size());
19 int n = notifierStack.size();
20 while (n--) {
21 LOGV(n);
22 notifierStack[n]->remove(this);
23 }
24 }
25
26 AgNotificationActionBase &
27 AgNotificationActionBase::attach(AgNotifierBase *notifier) {
28 LOGSECTION("AgNotificationActionBase::attach");
29 notifierStack.push(notifier);
30 notifier->attach(this);
31 return *this;
32 }
33
34 void AgNotificationActionBase::remove(AgNotifierBase *notifier) {
35 LOGSECTION("AgNotificationActionBase::remove");
36 int i, n = notifierStack.size();
37 ok_ptr(this);
38 ok_ptr(notifier);
39 for (i = 0; i < n; i++) {
40 if (notifierStack[i] == notifier) {
41 n--;
42 if (i < n) {
43 notifierStack[i] = notifierStack.pop();
44 }
45 else {
46 notifierStack.pop();
47 }
48 return;
49 }
50 }
51 }
52
53 AgNotifierBase::~AgNotifierBase() {
54 LOGSECTION("AgNotifierBase::~AgNotifierBase");
55 int n = notifyStack.size();
56 while (n--) {
57 notifyStack[n]->remove(this);
58 }
59 }
60
61 void AgNotifierBase::notify() {
62 LOGSECTION("AgNotifierBase::notify");
63 int n = notifyStack.size();
64 int i;
65 for (i = 0; i < n; i++) {
66 notifyStack[i]->perform();
67 }
68 }
69
70 void AgNotifierBase::remove(AgNotificationActionBase *action) {
71 LOGSECTION("AgNotifierBase::remove");
72 int i, n = notifyStack.size();
73 for (i = 0; i < n; i++) {
74 if (notifyStack[i] == action) {
75 n--;
76 LOGV(i);
77 LOGV(n);
78 LOGV(notifyStack.size());
79 if (i < n) {
80 notifyStack[i] = notifyStack.pop();
81 }
82 else {
83 notifyStack.pop();
84 }
85 return;
86 }
87 }
88 }
89