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


#include <map>
#include <boost/shared_ptr.hpp>
#include <vector>

namespace epoch {
    namespace altarica {
	
	class AltaricaModel;
	class Variable;
	class Value;
	class AltaricaInitInfo;

	class AltaricaState {

	private:
	    std::vector<Value*> stateVars_;
	    mutable std::vector<Value*> flowVars_;
	    const AltaricaModel * amodel_;
	    std::size_t hash_;
	    // bool macro_;

	    Value *cache;
	public:
	    //	    AltaricaState(const AltaricaModel* amodel);
	    AltaricaState(bool initial, const AltaricaModel* amodel, AltaricaInitInfo *initInfo);
	    AltaricaState(const std::vector<Value*> &mstate,  const AltaricaModel* amodel);

	    //	    bool isMacro() {return macro_;}

    void setValue(const Variable* var, Value*v);
	    void setStateValue(unsigned int i, Value*val);	    
	    void setFlowValue(unsigned int i, Value*val);

	    // macro state specifics 
	    void addValue(const Variable* var, Value*v);
	    void addStateValue(unsigned int i, Value*val);
	    void addFlowValue(unsigned int i, Value*val);

	    Value * getValue(const Variable *v) const;
	    Value * getStateValue(unsigned int i) const;
	    Value * getFlowValue(unsigned int i) const;
	    
	    void mergeToState(AltaricaState *s) const;
	    void intersectState(const AltaricaState *s);
	    void mergeIntersectState(const AltaricaState *s);

	    bool isEmpty() const;

	    ~AltaricaState();
	    AltaricaState *clone()const;
	    //	    AltaricaState * getMacroState() const;

	    bool equals(AltaricaState*s);
	    //	    unsigned int size();
	    bool hasValue( const Variable *  v) const;
	    bool hasStateValue(unsigned int i) const;
	    std::string toString(bool printStateVar, bool printFlowVar, bool printNULL = true, bool printDomain = true);
	    void removeValue(const Variable *v);
	    void removeValue(const Variable *v, const Value*vv);
	    void removeValue(unsigned int i, const Value*vv);
	    
	    std::size_t hash();
	    bool operator<(const AltaricaState&o) const;

	    void rehash_();
	    void setHash(size_t h);

	    inline const AltaricaModel * getAModel() const {return amodel_;}
	    void releaseFlowVars() const;
	    void deleteFlowValues() ;
	    
	    Value * getCachedValue() {return cache;}
	    void setCachedValue(Value *vv) {cache = vv;}


	};
    }
}

#endif
