/*********************************************************************
 * This file is part of the cpplibs suite.
 *
 * Copyright (C) 2001 Topi Mäenpää
 * All rights reserved.
 *
 * This program is free software. You can redistribute and/or modify
 * it under the terms of the free software licence found in the
 * accompanying file "COPYING". The licence terms must always be
 * redistributed with this source file. The above copyright notice
 * must be reproduced in all modified and unmodified copies of this
 * source file.
 *
 * $Revision: 1.4 $
 *********************************************************************/

#ifndef _BOOLEAN_H
#define _BOOLEAN_H

#include "PrimitiveType.h"

namespace util
{
	/**
	 * Boolean is a wrapper class for the primitive type bool. It can be
	 * used as a class replacement for boolean values.
	 **/
	class Boolean : virtual public PrimitiveType
	{
	public:
		/**
		 * Create a new boolean with the given truth value.
		 **/
		Boolean(bool b = false) : _bValue(b) {}

		/**
		 * Cast to a primitive value.
		 **/
		operator bool() const throw (ComputationException&) { return _bValue; }

		/**
		 * Return a Boolean object that represents the complement of this
		 * value.
		 **/
		SmartPtr<Computable> complement() const throw (ComputationException&)
		{ return SmartPtr<Computable>(new Boolean(!_bValue)); }
		
		/**
		 * Get the truth value.
		 **/
		bool boolValue() const { return _bValue; }

		/**
		 * Convert to string.
		 *
		 * @return "true" or "false"
		 **/
		std::string toString() const { return _bValue ? "true" : "false"; }

		/**
		 * Clone a Boolean object.
		 **/
		Object* clone() const throw (NotCloneableException&) { return new Boolean(_bValue); }

	private:
		bool _bValue;
	};
}

#endif
