/*
 * \file parameters.c
 *
 * \date Jun 24, 2009
 * \author Alexander Pimenov
 */

#include "global.h"
#include <stdio.h>

#include "parameters.h"


void printParameter(Parameter *in, char* buffer, int length)
{
	if (in->type == TYPE_BOOLEAN)
	{
		snprintf(buffer, length, "%s is %s", in->name, in->range.irange.value ? "TRUE" : "FALSE");
		return;
	}
	if (in->type == TYPE_INTEGER)
	{
		snprintf(buffer, length, "%s = %d", in->name, in->range.irange.value);
		return;
	}
	if (in->type == TYPE_DOUBLE)
	{
		snprintf(buffer, length, "%s = %g", in->name, in->range.drange.value);
		return;
	}
}

void addToParamter (Parameter *in, int steps)
{
	if (in->type == TYPE_BOOLEAN || in->type == TYPE_INTEGER)
	{
		int newparam = in->range.irange.value + in->range.irange.step * steps;
		if (newparam <= in->range.irange.max && newparam >= in->range.irange.min)
			in->range.irange.value = newparam;
		return;
	}
	if (in->type == TYPE_DOUBLE)
	{
		double newparam = in->range.drange.value + in->range.drange.step * steps;
		if (newparam <= in->range.drange.max && newparam >= in->range.drange.min)
			in->range.drange.value = newparam;
		return;
	}
}
