/**
 * Callback when a before-replace notification is received
 * Replaces a member if it was replaced in the ADS and checks
 * for duplicate members within the group
 * @param notice :: A pointer to a workspace before-replace notification object
 */
void WorkspaceGroup::workspaceBeforeReplaceHandle(
    Mantid::API::WorkspaceBeforeReplaceNotification_ptr notice) {
  std::lock_guard<std::recursive_mutex> _lock(m_mutex);

  const auto oldObject = notice->oldObject();
  const auto newObject = notice->newObject();

  bool foundOld(false);
  bool foundDuplicate(false);

  auto duplicateIter = m_workspaces.end();

  for (auto it = m_workspaces.begin(); it != m_workspaces.end(); ++it) {
    auto &workspace = *it;
    if (workspace == oldObject) {
      workspace = newObject;
      foundOld = true;

    } else if (workspace == newObject) {
      duplicateIter = it;
      foundDuplicate = true;
    }

    if (foundOld && foundDuplicate) {
      break;
    }
  }

  if (foundOld && duplicateIter != m_workspaces.end()) {
    m_workspaces.erase(duplicateIter);
  }
}
Exemple #2
0
/**
 * Callback when a after-replace notification is received
 * Replaces a member if it was replaced in the ADS.
 * @param notice :: A pointer to a workspace after-replace notificiation object
 */
void WorkspaceGroup::workspaceReplaceHandle(
    Mantid::API::WorkspaceBeforeReplaceNotification_ptr notice) {
  std::lock_guard<std::recursive_mutex> _lock(m_mutex);

  const std::string replacedName = notice->objectName();
  for (auto &workspace : m_workspaces) {
    if ((*workspace).name() == replacedName) {
      workspace = notice->newObject();
      break;
    }
  }
}