/*******************************************************************************
 * Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
 * Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
 * l'IRT AESE (IRT Saint Exupéry).
 * Tous droits réservés.
 *
 * Ce programme et les éléments qui l'accompagnent sont mis à disposition
 * aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
 * au droit français et respectant les principes de diffusion des logiciels libres.
 * Vous pouvez utiliser, modifier et/ou redistribuer ce programme
 * sous les conditions de la licence CeCILL-C (http://www.cecill.info).

 * This software is property of ONERA (the French Aerospace Lab) and of
 * the IRT AESE (IRT Saint Exupéry).
 * All rights reserved.
 *
 * This program and the accompanying materials are made available under
 * the terms of the CeCILL-C license under French law and
 * abiding by the rules of distribution of free software.
 * You can  use, modify and/ or redistribute the software under the terms of
 * the CeCILL-C license (http://www.cecill.info).
 *
 * Contributeurs/contributors:
 *     Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
 *     Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
 *
 *******************************************************************************/

#include "MetaEvent.hh"
#include "AltaricaGenerator.hh"
#include "altarica_driver.hh"


using namespace epoch::altarica;

AltaricaGenerator::AltaricaGenerator(std::string altaricaFile,epoch::ParsingDriverReporter & reporter) {
    altarica_driver * driver = new altarica_driver(reporter, altaricaFile, false, false); 
    driver->Parse();
    amodel_ = driver->amodel;
    amodel_->finalize("main", false);
    delete driver;
}

AltaricaGenerator::~AltaricaGenerator() {
    delete amodel_;
}

std::size_t AltaricaGenerator::State::hash() const {
    // AltaricaState: as_
    return as_->hash();
}

bool AltaricaGenerator::State::operator==(const State&o) const {
    return as_->equals(o.as_);
}

bool AltaricaGenerator::State::operator<(const State&o) const {
    return as_<o.as_;
}

std::ostream& AltaricaGenerator::State::print(std::ostream& o) const {
	o << (as_->toString(true, false,false,false));
    return o;
}

std::ostream& AltaricaGenerator::State::printDot(std::ostream& o, std::string& att) const {
    return print(o);
}

std::ostream& AltaricaGenerator::Transition::print(std::ostream& o) const {
    o << "{ probability = " << m_Probability << " , reward = " << m_Reward << " }";
    return o;
}

std::ostream& AltaricaGenerator::Transition::printDot(std::ostream& o, std::string& att) const {
    o << "{p=" << m_Probability << ", r=" << m_Reward << "}";
    return o;
}

namespace epoch {
namespace altarica {
std::ostream& operator<< (std::ostream& o, const AltaricaGenerator::State& s) {
    return s.print(o);
}

std::ostream& operator<< (std::ostream& o, const AltaricaGenerator::Transition& t) {
    return t.print(o);
}
}
}
