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

#include "RealDomain.hh"
#include "DiscreteDomain.hh"
#include "values/ValueReal.hh"

namespace epoch {
    namespace altarica {

	RealDomain::RealDomain(const DiscreteDomain *d) :Domain(){
    if (d != NULL)
	    di = boost::icl::continuous_interval<double>(d->getMin(), d->getMax(), boost::icl::interval_bounds::closed());
    else
      di = boost::icl::continuous_interval<double>(std::numeric_limits<double>::min(), std::numeric_limits<double>::max(), boost::icl::interval_bounds::closed());
	}


	RealDomain::RealDomain() :Domain(){
	    di = boost::icl::continuous_interval<double>(std::numeric_limits<double>::min(), std::numeric_limits<double>::max(), boost::icl::interval_bounds::closed());
	}

	RealDomain::RealDomain(double inf, double sup, bool openleft, bool openright) {
	    if (openright)
		if (openleft)
		    di = boost::icl::continuous_interval<double>(inf, sup, boost::icl::interval_bounds::open());
		else
		    di = boost::icl::continuous_interval<double>(inf, sup, boost::icl::interval_bounds::right_open());		    
	    else
		if (openleft)
		    di = boost::icl::continuous_interval<double>(inf, sup, boost::icl::interval_bounds::left_open());		    
		else
		    di = boost::icl::continuous_interval<double>(inf, sup, boost::icl::interval_bounds::closed());		    
	}


	Value * RealDomain::toValue()  const {
	    return new ValueReal(this);
	}

	std::string RealDomain::toString() const {
	    std::stringstream ss;
	    ss << di;
	    return ss.str();
	}

	unsigned int RealDomain::getArity() const {
	    if (di.upper() == di.lower() &&
          di.bounds() == boost::icl::interval_bounds::closed())
        return 1;
	    return std::numeric_limits<unsigned int>::infinity();
	}

    }
}


