/*******************************************************************************
 * Copyright (c) 2015-2016 ONERA.
 * Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab).
 * 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).
 * 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
 *
 *******************************************************************************/

#ifndef ALTARICA_GENERATOR_HH
#define ALTARICA_GENERATOR_HH

#include <boost/functional/hash.hpp>
#include <iostream>
#include <memory>

#include "AltaricaState.hh"
#include "AltaricaModel.hh"
#include "MetaEvent.hh"
#include "grammars/parsingdriverbase.hh"

namespace epoch {
	namespace altarica {
		struct AltaricaGenerator {

			epoch::altarica::AltaricaModel *amodel_;

			struct State {
			    epoch::altarica::AltaricaState *as_;
			    inline State(epoch::altarica::AltaricaState *s) : as_(s) {}
			    inline State() : as_(NULL) {}			    
			    inline State(const epoch::altarica::AltaricaGenerator::State& s)   {
				as_ = s.as_->clone();
			    }
			~State() {delete as_;}

			    std::size_t hash() const;
			    bool operator==(const State&o) const;
			    bool operator<(const State& o) const;
			    
			    std::ostream& print(std::ostream& o) const;
			    std::ostream& printDot(std::ostream& o, std::string& att) const;
			};
		    
			struct Transition {
			double m_Probability;
			double m_Reward;
	
			Transition(double probability, double reward) : m_Probability(probability), m_Reward(reward) {}
			Transition() {}
			Transition(const Transition& other) : m_Probability(other.m_Probability), m_Reward(other.m_Reward) {}
			
			inline const double& getProbability() const {return m_Probability;}
			inline const double& getReward() const {return m_Reward;}
			
			std::ostream& print(std::ostream& o) const;
			std::ostream& printDot(std::ostream& o, std::string& att) const;
			};

			template <typename Tfunctor>
			void generateTransitions(const State& s, const Tfunctor& functor);

			AltaricaGenerator(std::string altaricaFile,epoch::ParsingDriverReporter & reporter );
			~AltaricaGenerator();

			void setDiscrete() {amodel_->setDiscrete();}
			void setContinuous() {amodel_->setContinuous();}
		};
		
	    std::ostream& operator<< (std::ostream& o, const AltaricaGenerator::State& s);

	    std::ostream& operator<< (std::ostream& o, const AltaricaGenerator::Transition& t);
		
	} // namespace altarica
} // namespace epoch

#include "details/AltaricaGeneratorImpl.hh"

#endif // ALTARICA_GENERATOR_HH

