/*******************************************************************************
 * 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 LANDMARK_STATE_HH
#define LANDMARK_STATE_HH


#include <map>
#include <vector>
#include <string>
#include "Values.hh"

namespace epoch {
    namespace altarica {
	
	class AltaricaModel;
	class AltaricaState;
	class Variable;
	class LandmarkMetaEvent;
	class Value;

	typedef Value* labelsKeyType;


	class ValueComparator {
	public:
	    bool operator() (const labelsKeyType& a, const labelsKeyType& b) const {
		return a->less(b);
	    }
	};

	typedef std::map<Value*, AltaricaState*, ValueComparator> landmarkType;

	typedef  std::vector<landmarkType*> labelsType;


	// for each variable (vector) a map between a value and corresponding labels

	class LandmarkState {
	 

	private:
	    AltaricaState *as_;
	    labelsType  *labels_;
	    labelsType  *flowLabels_;

	public:
	    LandmarkState(AltaricaState *as);
	    AltaricaState * getState() const {return as_;}
	    void addSelfAsLabel();
	    void removeSelfAsLabel();
	    // void addLabel(labelsType *l);
	    void addLabel(unsigned int i, Value* v, const AltaricaState* label);
	    void addNoopLabels(LandmarkState *ps);

	    // return NULL if no label
	    AltaricaState* getLabel(Variable* v, Value *fv) const ;
	    AltaricaState* getLabel(unsigned int i, Value *fv) const ;
	    AltaricaState* getFlowLabel(unsigned int i, Value *fv) const ;
	    labelsType * getLabels() const {return labels_;}
	    labelsType * getFlowLabels()  const {return flowLabels_;}
	    
	    void computeLabels(const AltaricaModel*am, const AltaricaState *ps, LandmarkMetaEvent *la);
	    void computeFlowLabels(const AltaricaModel*am);
	    void mergeIntersectLabels(const LandmarkState *os);

	    std::string toString() const;
	};
    }
}


#endif
