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

#include "ExpressionCONSTSTRUCT.hh"

using namespace epoch::altarica;

ExpressionCONSTSTRUCT::ExpressionCONSTSTRUCT()
    : ExpressionATOMIC() {
    ids_ = new std::vector<std::string>();
    cexprs_ = new std::vector<Expression*>();
}

void ExpressionCONSTSTRUCT::mergeAssigns(ExpressionCONSTSTRUCT * o) {
    std::vector<Expression*>::iterator i2 = o->getExprs()->begin();
    for ( std::vector<std::string>::iterator i = o->getIDs()->begin();
	  i != o->getIDs()->end(); ++i) {
	addAssign(*i, *i2);
	i2++;
    }
	  
}

ExpressionCONSTSTRUCT::~ExpressionCONSTSTRUCT() {
    ids_->clear();
    delete(ids_);
    cexprs_->clear();
    delete(cexprs_);
}

ExpressionCONSTSTRUCT * ExpressionCONSTSTRUCT::clone() const {
    ExpressionCONSTSTRUCT * necs = new ExpressionCONSTSTRUCT();
    std::vector<std::string>::iterator si = ids_->begin();
    std::vector<Expression*>::iterator cei = cexprs_->begin();
    for (; si != ids_->end(); ++si, ++cei)
	necs->addAssign(*si, (*cei)->clone());
    return necs;
}


std::string  ExpressionCONSTSTRUCT::toString() const {
    std::string s;
    s+= "[";
    std::vector<std::string>::const_iterator ii = ids_->begin();
    std::vector<Expression*>::const_iterator ei = cexprs_->begin();
    for (; ii!= ids_->end(); ++ii, ++ei) 
	s+= *ii + ":" + (*ei)->toString() + ",";
    s+= "]";
    return s;
}

std::string  ExpressionCONSTSTRUCT::toString(const Node *n, const AltaricaModel& am) const {
    std::string s;
    s+= "[";
    std::vector<std::string>::const_iterator ii = ids_->begin();
    std::vector<Expression*>::const_iterator ei = cexprs_->begin();
    for (; ii!= ids_->end(); ++ii, ++ei)
	s+= *ii + ":" + n->toFiacre() + (*ei)->toString() + ",";
    s+= "]";
    return s;
}

std::string  ExpressionCONSTSTRUCT::toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const {
    std::string s;
    s+= "[";
    std::vector<std::string>::const_iterator ii = ids_->begin();
    std::vector<Expression*>::const_iterator ei = cexprs_->begin();
    for (; ii!= ids_->end(); ++ii, ++ei)
f->first + "&" + n->toFiacre() + (*ei)->toString() + ",";
    s+= "]";
    return s;
}
