/**
 *  Copyright (c) 1999-2011, Ecole des Mines de Nantes
 *  All rights reserved.
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *      * Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above copyright
 *        notice, this list of conditions and the following disclaimer in the
 *        documentation and/or other materials provided with the distribution.
 *      * Neither the name of the Ecole des Mines de Nantes nor the
 *        names of its contributors may be used to endorse or promote products
 *        derived from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
 *  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package parser.flatzinc.ast;

import gnu.trove.map.hash.THashMap;
import gnu.trove.set.hash.THashSet;
import parser.flatzinc.FZNLayout;
import parser.flatzinc.ast.declaration.Declaration;
import parser.flatzinc.ast.expression.Expression;
import solver.Solver;
import solver.variables.IntVar;
import solver.variables.Variable;

import java.util.Arrays;
import java.util.List;

/**
 * @author Charles Prud'homme
 * @since 17/05/13
 */
public class Datas {

    final GoalConf gc;

    // the layout dedicated to pretty print message wrt to fzn recommendations
    FZNLayout mLayout;

    final THashMap<String, Object> map;

    final THashSet<Variable> searchVariables;

    public Datas(GoalConf gc) {
        this.gc = gc;
        this.map = new THashMap<String, Object>();
        searchVariables = new THashSet<Variable>();
    }

    public Datas() {
        this(new GoalConf());
    }

    public void setmLayout(FZNLayout mLayout) {
        this.mLayout = mLayout;
    }

    public void register(String name, Object o) {
        map.put(name, o);
    }


    public Object get(String id) {
        return map.get(id);
    }

    public GoalConf goals() {
        return gc;
    }

    public void addSearchVars(IntVar... vars) {
        searchVariables.addAll(Arrays.asList(vars));
    }

    public IntVar[] getSearchVars() {
        return searchVariables.toArray(new IntVar[0]);
    }

    public void declareOutput(String name, Variable variable, Declaration type) {
        mLayout.addOutputVar(name, variable, type);
    }

    public void declareOutput(String name, Variable[] variables, List<Expression> indices, Declaration type) {
        mLayout.addOutputArrays(name, variables, indices, type);
    }

    public void declareOutput(String name, IntVar variable, Declaration type) {
        mLayout.addOutputVar(name, variable, type);
    }

    public void declareOutput(String name, IntVar[] variables, List<Expression> indices, Declaration type) {
        mLayout.addOutputArrays(name, variables, indices, type);
    }

    public void plugLayout(Solver aSolver) {
        mLayout.setSearchLoop(aSolver.getSearchLoop());
    }

    public void clear(){
        map.clear();
        searchVariables.clear();
    }
}

@@ -2446,24 +2446,59 @@
 ariable%3E();%0A
+        mLayout = new FZNLayout();%0A
     %7D%0A%0A    p

Set a default mLayout in Datas (mzn)