/*******************************************************************************
 * 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 "PredefinedDomain.hh"

#include <stdlib.h>

#include "Variable.hh"
#include "Values.hh"

namespace epoch {
  namespace altarica {

    PredefinedDomain::PredefinedDomain(bool type) {
	    if (type) {
        bool_ = true;
        arity_ = 2;
	    } else {
        bool_ = false;
        arity_ = UINT32_MAX;
	    }
    }

    unsigned int PredefinedDomain::index(std::string arg) const {
	    if (bool_) {
        if (arg == "TRUE" || arg == "true")
          return 1;
        else 
          return 0;
	    } else {
        return (atoi(arg.c_str()));
	    }
    }

    std::string  PredefinedDomain::text(unsigned int index) const {
	    std::string s;
	    if (bool_) {
        if (index == 1)
          s+="true";
        else
          s+="false";
	    } else {
        std::string *s = new std::string();
        s +=index;
	    }
	    return s;
    }


    Value * PredefinedDomain::toValue() const {
	    if (bool_) 
        return new ValueBool();
	    else
        return new ValueInt();
    }


    int PredefinedDomain::getMin() const {
	    if (bool_)
        return 0;
	    else 
        return INT32_MIN;
    }

    int PredefinedDomain::getMax() const {
	    if (bool_)
        return 1;
	    else
        return INT32_MAX;
    }

    int PredefinedDomain::min(bool b) {
	    if (b)
        return 0;
	    else
        return INT32_MIN;
    }
    int PredefinedDomain::max(bool b) {
	    if (b)
        return 1;
	    else
        return INT32_MAX;
    }

	
    // Value * PredefinedDomain::getFixedValue(int i) {
    //     if (bool_) {
    // 	if (i == 0)
    // 	    return new FixedBool(true);
    // 	else 
    // 	    return new FixedBool(false);
    //     } else {
    // 	return new FixedInt(i);
    //     }
    // }

    Value * PredefinedDomain::getValue(int i) {
	    if (bool_) {
        if (i == 1)
          return new ValueBool(true,false);
        else 
          return new ValueBool(false,true);
	    } else {
        return new ValueInt(i);
	    }
    }

    std::string PredefinedDomain::toString() const {
	    if (bool_)
        return "BOOL";
	    else 
        return "INTEGER";
    }

    PredefinedDomain::~PredefinedDomain() {}


  }
}


