/*
 * This file is part of DesktopBSD, see the README file.
 *
 * Author: Pieringer Johannes <jpieringer@desktopbsd.net>
 *         (C) 2006
 *
 * Copyright: BSD, see the COPYING file included in this distribution
 *
 */

#ifndef __GRUBCOMMAND_H
#define __GRUBCOMMAND_H

#include <qstring.h>
#include <qvariant.h>

template <class T>
class GrubCommand
{
protected:
	QString command;
	T value;
	QString comment;
	QString commentAfterCommand;

public:
	GrubCommand();
	GrubCommand(T value, const QString& comment, const QString& commentAfterCommand);
	GrubCommand(const QString& command, T value, const QString& comment, const QString& commentAfterCommand);

	void setCommand(QString command);
	void setValue(T value);
	void setComment(QString comment);
	void setCommentAfterCommand(QString commentActerCommand);

	QString getCommand();
	T getValue();
	QString getComment();
	QString getCommentAfterCommand();

	QString toString();
};

/** Constructor without parameters
	*/
template <class T>
GrubCommand<T>::GrubCommand()
{
	this->comment = QString();
	this->commentAfterCommand = QString();
}

/** Constructor with parameters
 */
template <class T>
GrubCommand<T>::GrubCommand(T value, const QString& comment, const QString& commentAfterCommand)
{
	this->value = value;
	this->comment = comment;
	this->commentAfterCommand = commentAfterCommand;
}

/** Constructor with parameters
 */
template <class T>
GrubCommand<T>::GrubCommand(const QString& command, T value, const QString& comment, const QString& commentAfterCommand)
{
	this->command = command;
	this->value = value;
	this->comment = comment;
	this->commentAfterCommand = commentAfterCommand;
}

/**
 * Sets the command.
 */
template <class T>
void GrubCommand<T>::setCommand(QString command)
{
	this->command = command;
}

/**
 * Sets the value of the command.
 */
template <class T>
void GrubCommand<T>::setValue(T value)
{
	this->value = value;
}

/**
 * Sets the comment before the command.
 */
template <class T>
void GrubCommand<T>::setComment(QString comment)
{
	this->comment = comment;
}

/**
 * Sets the comment in the line after the command
 */
template <class T>
void GrubCommand<T>::setCommentAfterCommand(QString commentAfterCommand)
{
	this->commentAfterCommand = commentAfterCommand;
}


/**
 * Returns the command.
 */
template <class T>
QString GrubCommand<T>::getCommand()
{
	return this->command;
}

/**
 * Returs the value of the command.
 */
template <class T>
T GrubCommand<T>::getValue()
{
	return this->value;
}

/**
 * Returns the comment before the command.
 */
template <class T>
QString GrubCommand<T>::getComment()
{
	return this->comment;
}

/**
 * Returns the comment which is in the line after the command
 */
template <class T>
QString GrubCommand<T>::getCommentAfterCommand()
{
	return this->commentAfterCommand;
}

/**
 * Returns the command in a string
 */
template <class T>
QString GrubCommand<T>::toString()
{
	QString toString = "";

	//The comment before the command
	if (!(comment.isEmpty() || comment.isNull()))
	{
		toString += comment;
	}

	//The command and the value
	if (!(command.isEmpty() || command.isNull()))
		toString += command + " ";

	//The command and the value
	toString += QVariant(value).toString() + " ";

	//The comment after the command
	if (!(commentAfterCommand.isEmpty() || commentAfterCommand.isNull()))
		toString += commentAfterCommand;

	toString += "\n";
	return toString;
}

#endif /* __GRUBCOMMAND_H */
