view anagram/support/agnotify.cpp @ 6:607e3be6bad8

Adjust to the moving target called the C++ standard. Apparently nowadays it's not allowed to define an explicit copy constructor but not an assignment operator. Consequently, defining the explicit copy constructor in terms of the implicit/automatic assignment operator for general convenience no longer works. Add assignment operators. Caution: not tested with the IBM compiler, but there's no particular reason it shouldn't work.
author David A. Holland
date Mon, 30 May 2022 23:46:22 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
 * 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;
    }
  }
}