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


#include "rosa/core/Unit.h"

#include "rosa/core/System.hpp"

#include "rosa/support/debug.hpp"
#include "rosa/support/log.h"

namespace rosa {

// Ctor. Initializing member fields.
Unit::Unit(const AtomValue Kind, const id_t Id, const std::string &Name,
           System &S) noexcept : Kind(Kind),
                                 Id(Id),
                                 Name(Name),
                                 S(S),
                                 FullName(Name + "@" + S.name()) {
  ASSERT(!Name.empty());
  LOG_TRACE("Constructing Unit (" + FullName + " of kind '" + to_string(Kind) +
            "')");
}

// Dtor.
Unit::~Unit(void) { LOG_TRACE("Destroying Unit (" + FullName + ")"); }

// Default dump function, emitting the Name of the Unit.
std::string Unit::dump(void) const noexcept {
  LOG_TRACE("Dumping Unit (" + FullName + ")");
  return "[Unit] " + FullName;
}

System &Unit::system(void) const noexcept {
  return S;
}

std::ostream &operator<<(std::ostream &OS, const Unit &U) {
  OS << U.dump();
  return OS;
}

} // End namespace rosa

