/*
 * This file is part of DesktopBSD, see the README file.
 *
 * Author: Peter Hofer <ph@desktopbsd.net>
 *			(C) 2004, 2005
 *
 * Copyright: BSD, see the COPYING file included in this distribution
 *
 */

#include <variables.h>

QMap<QString, QString>  Variables::variables;

/** Sets a value.
  *
  * @param  name		 Variable identifier.
  * @param  value		New value.
  * @param  overwrite  Overwrite value if variable already exists.
  *
  * @return  TRUE when value was set, FALSE if not.
  */
bool  Variables::setValue(const QString&  name,
								  const QString&  value,
								  bool overwrite)
{
	if(overwrite)
		variables.replace(name, value);
	else {
		if(variables.contains(name))
			return false;

		variables.insert(name, value, true);
	}

	return true;
}

void  Variables::unsetVar(const QString&  name) {
	variables.erase(name);
}

/** @return The value of a variable. */
QString  Variables::getValue(const QString& name) {
	return variables[name];
}
