/*******************************************************************************
 * 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
 *
 *******************************************************************************/

#ifndef ALTA_EXPRESSION_MEMBER_H_
#define ALTA_EXPRESSION_MEMBER_H_


#include "ExpressionATOMIC.hh"
#include "../MemberAccess.hh"
#include "../Values.hh"


namespace epoch {
    namespace altarica {

	class ExpressionAND;

	class ExpressionMEMBER : public ExpressionATOMIC {
	
	private:
	    MemberAccess * ma_;
	    std::string s_;
	    mutable short symbol_; // -1: do not know, 0: symbol, 1: stateVar, 2: flowvar, 3: const
	    //	    OpenSymbol * osCache_;
	    mutable ValueSymbol *fs;
	    mutable std::vector<Variable*> varsCache_;

	public:
	    ExpressionMEMBER(MemberAccess *ma);
	    virtual ~ExpressionMEMBER();

	    const MemberAccess * getMA() const {return ma_;}
	    std::string getSymbol() const {return s_;}
	    bool isConst() const {return (symbol_ == 3);}
	    int getIsSymbol() const {return symbol_;}
	    void setIsSymbol(short i) const {symbol_ = i;}
	    Variable * getVariable(const Node*n, const AltaricaModel *am) const;
	    void setSymbol() const;
	    void initSymbol(const Node *node_, const AltaricaModel &amodel_)  const;

	    virtual ExpressionMEMBER * clone() const;
	    virtual void accept(Visitor* v) const {v->visitMEMBER(this);}
	    virtual std::string toString() const;
	    virtual std::string toString(const Node *n, const AltaricaModel& am) const;
	    virtual std::string toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const;

	    ValueSymbol * getSymbolValue() const {return fs;}

	    void resizeCache(unsigned int i) const;
	    void setCache(unsigned int i, Variable *v) const;
	    Variable * getVarFromCache(unsigned int i) const {return varsCache_[i];}
	    void initCache(const Node *n, const AltaricaModel *am) const;

	};
    }
}


#endif
