/*******************************************************************************
***  This file is part of Dux Rei Nummariae.                                 ***
***                                                                          ***
***  Copyright (C) 2017, 2018, 2019, 2020, 2021                              ***
***  John Schneiderman <Licensing _AT_ Schneiderman _DOT_ me>                ***
***                                                                          ***
***  This program is free software: you can redistribute it and/or modify it ***
***  under the terms of the GNU Affero General Public License as published   ***
***  by the Free Software Foundation, either version 3 of the License, or    ***
***  (at your option) any later version.                                     ***
***                                                                          ***
***  This program is distributed in the hope that it will be useful, but     ***
***  WITHOUT ANY WARRANTY; without even the implied warranty of              ***
***  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                    ***
***  See the GNU Affero General Public License for more details.             ***
***                                                                          ***
***  You should have received a copy of the GNU Affero General Public License***
***  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
*******************************************************************************/
#ifndef DRN_FOUNDATION_SWITCH_H
#define DRN_FOUNDATION_SWITCH_H

#include <iosfwd>

#include "foundation_export.h"


namespace drn
{
namespace foundation
{

enum class DRN_FOUNDATION_EXPORT SwitchStates
{
	Off,
	On,
};
/**
 * @brief Provides a simple switch object.
 */
class DRN_FOUNDATION_EXPORT Switch
{
	SwitchStates state_;

public:
	/**
	 * @brief Full initialisation constructor to set the initial state of the switch object.
	 *
	 * @param state The initial state of the switch.
	 */
	Switch(const SwitchStates state = SwitchStates::Off);
 	explicit Switch(const bool state);
	~Switch() = default;
	Switch(const Switch&) = default;
	Switch(Switch&&) = default;
	Switch& operator=(const Switch&) = default;
	Switch& operator=(Switch&&) = default;
	/**
	 * @brief An accessor for the switch state.
	 *
	 * @return The current switch state.
	 */
	const SwitchStates& state() const;
	/**
	 * @brief Conversion operator to determine the state of the switch.
	 *
	 * @return When the object is on gives true, false else-wise.
	 */
	operator bool() const;
	/**
	 * @brief Determines the state of the switch.
	 *
	 * @return When the object is on gives true, false else-wise.
	 */
	bool isOn() const;
	/**
	 * @brief Changes the state of the switch to off.
	 */
	void flipOff();
	/**
	 * @brief Changes the state of the switch to its opposite state, i.e. off to on and on to off.
	 */
	void toggle();
	/**
	 * @brief Changes the state of the switch to on.
	 */
	void flipOn();
};

DRN_FOUNDATION_EXPORT std::ostream& operator<<(std::ostream& o, const SwitchStates& ss);
DRN_FOUNDATION_EXPORT std::ostream& operator<<(std::ostream& o, const Switch& s);

}}

#endif
