/*******************************************************************************
 *
 * File:     System.cpp
 *
 * Contents: Implementation of System base-class.
 *
 * Copyright 2017
 *
 * Author: David Juhasz (david.juhasz@tuwien.ac.at)
 *
 ******************************************************************************/

#include "rosa/core/System.hpp"

#include "SystemImpl.hpp"

#include "rosa/core/Unit.h"

namespace rosa {

std::unique_ptr<System> System::createSystem(const std::string &Name) noexcept {
  return std::unique_ptr<System>(new SystemImpl(Name));
}

System::System(const std::string &Name) noexcept : Name(Name),
                                                   CountUnits(0),
                                                   SystemCleaned(false) {
  LOG_TRACE("Creating System (" + Name + ")");
}

System::~System(void) {
  LOG_TRACE("Destroying System (" + Name + ")");
  if (!SystemCleaned) {
    ROSA_CRITICAL("Trying to destroy a uncleaned System (" + Name + ")");
  }
}

void System::markCleaned(void) noexcept {
  if (SystemCleaned) {
    ROSA_CRITICAL("System (" + Name + ") has been already mark cleaned");
  } else if (!empty()) {
    ROSA_CRITICAL("Trying to mark a non-empty System (" + Name + ")");
  } else {
    SystemCleaned = true;
    LOG_TRACE("System (" + Name + ") is marked clean");
  }
}

size_t System::numberOfConstructedUnits(void) const noexcept {
  return CountUnits;
}

} // End namespace rosa

