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

#include <vector>
#include <string>

namespace epoch {
    namespace altarica {

	class Ident {
	public : 
	    std::string  id;
	    std::vector<int>  indexes;
	    ~Ident();
	} ;

	class MemberAccess {
	protected:
	    std::vector<Ident*>  path_;
	    bool isGlobal_ ;
	    std::string s_;
	    std::string h_;
	    const std::vector<Ident*> * getAccesses() const;


	    void addSimpleCombinationsRec(std::vector<int>* idx, std::vector<int>* maxidxs, 
					   std::vector<std::vector<int>*>* iidx);
	    std::vector<std::vector<int>*>* buildSimpleCombinations(std::vector<int>* idxs);
	    void toString_();
	    void headToString_();


	private:
	    void addIdBackNoString(std::string id, std::vector<int> &iv);
	    void removeIdFrontNoString();
	    bool removeIdFrontNoString(std::string id, std::vector<int> *iv);
	public:
	    

	    //! empty constructor
	    MemberAccess();
	    ~MemberAccess();

	    //! empty constructor with reservation
	    MemberAccess(int n);

	    MemberAccess(std::string id, std::vector<int> *v);
	    MemberAccess(std::string id);


	    void addIdBack(std::string id);
	    //	    void addIdBack(std::string id, std::vector<int> *iv);
	    void addIdBack(std::string id, std::vector<int> &iv);

	    void addIdBack(std::string id, int i);

	    void addIdFront(std::string id);
	    void addIdFront(std::string id, std::vector<int> &iv);
	    void addIdFront(std::string id, int i);
	    void removeIdFront();

	    bool removeIdFront(std::string id);
	    bool removeIdFront(std::string id, std::vector<int> *iv);

	    


	    void addIndexBack(int i);
	    void addIndexesBack(std::vector<int> *iv);

	    void addIndexFront(int i);
	    void addIndexesFront(std::vector<int> *iv);

	    void addIndexSecond(int i);
	    void addIdSecond(std::string s);
	    
	    void addIndex(std::string id, int i);
	    void addIndexes(std::string id, std::vector<int> *iv);
	    
	    void setGlobal(bool b);
	    bool isGlobal() const;

	    	   	    //! join two memberAcesses
	    void addMemberAccessBack(MemberAccess *ma);
	    void addMemberAccessFront(MemberAccess *ma);

	    MemberAccess * buildSuffix(const MemberAccess *ma) const;

	    bool equals(const MemberAccess* ma) const;

	    MemberAccess* clone() const;

	    static bool sameIndexes(const std::vector<int> * ind1, const std::vector<int> * ind2);

	    std::vector<MemberAccess*> * buildCombinations();

	    inline std::string toString() const {return s_;}

	    inline std::string headToString() const {return h_;}
	    const std::string  getSymbol() const;

	    void doString();
	};
    }
}

#endif
