<commit_before>/**
@file System/Context.hpp
@brief Context class.

@author <NAME>
@copyright 2013-2014 <NAME> under the MIT license;
see @ref index or the accompanying LICENSE file for full text.
*/

#ifndef HORD_SYSTEM_CONTEXT_HPP_
#define HORD_SYSTEM_CONTEXT_HPP_

#include <Hord/config.hpp>
#include <Hord/aux.hpp>
#include <Hord/Hive/Defs.hpp>
#include <Hord/Hive/Unit.hpp>
#include <Hord/IO/Datastore.hpp>
#include <Hord/Cmd/Defs.hpp>
#include <Hord/Cmd/Unit.hpp>
#include <Hord/Cmd/Stage.hpp>
#include <Hord/System/Driver.hpp>

#include <utility>

namespace Hord {
namespace System {

// Forward declarations
class Context;

/**
	@addtogroup system
	@{
*/

/**
	%Context.

	@warning The context requires the attached datastore and hive
	exist as long as the context exists.

	@remarks This class mediates the behavior of commands one layer
	above the command transmission protocol for a server or client.
*/
class Context final {
public:
	/**
		%Context type.
	*/
	enum class Type : unsigned {
		/**
			Host view.
		*/
		host,

		/**
			Client view.
		*/
		client
	};

	/** Command map. */
	using command_map_type = aux::unordered_map<
		Cmd::IDValue,
		Cmd::UnitUPtr
	>;

	/** Command input deque. */
	using input_deque_type = aux::deque<
		Cmd::StageUPtr
	>;

	/**
		%Stage output destinations.
	*/
	enum class Dest : unsigned {
		/** %Output to remote endpoint. */
		remote = 1u,
		/** %Output to all other endpoints (local initiation). */
		broadcast_local,
		/** %Output to all other endpoints (remote initiation). */
		broadcast_remote,
	};

	/**
		Command output.
	*/
	struct Output {
		/** Destination of stage. */
		Context::Dest dest;
		/** %Stage. */
		Cmd::StageUPtr stage;

		/**
			Constructor with destination and stage.
		*/
		Output(
			Context::Dest const dest,
			Cmd::StageUPtr&& stage
		) noexcept
			: dest(dest)
			, stage(std::move(stage))
		{}
	};

	/** Command output deque. */
	using output_deque_type = aux::deque<
		Context::Output
	>;

	/**
		%Stage execution result.
	*/
	struct Result {
		/** Canonical stage %ID. */
		Cmd::ID id;
		/** Command status. */
		Cmd::Status status;
		/** Command unit. */
		Cmd::UnitUPtr command;
	};

private:
	Type const m_type;
	System::Driver& m_driver;<commit_msg>System::Context::Output: added is_broadcast() and doc group names.<commit_after>/**
@file System/Context.hpp
@brief Context class.

@author <NAME>
@copyright 2013-2014 <NAME> under the MIT license;
see @ref index or the accompanying LICENSE file for full text.
*/

#ifndef HORD_SYSTEM_CONTEXT_HPP_
#define HORD_SYSTEM_CONTEXT_HPP_

#include <Hord/config.hpp>
#include <Hord/aux.hpp>
#include <Hord/Hive/Defs.hpp>
#include <Hord/Hive/Unit.hpp>
#include <Hord/IO/Datastore.hpp>
#include <Hord/Cmd/Defs.hpp>
#include <Hord/Cmd/Unit.hpp>
#include <Hord/Cmd/Stage.hpp>
#include <Hord/System/Driver.hpp>

#include <utility>

namespace Hord {
namespace System {

// Forward declarations
class Context;

/**
	@addtogroup system
	@{
*/

/**
	%Context.

	@warning The context requires the attached datastore and hive
	exist as long as the context exists.

	@remarks This class mediates the behavior of commands one layer
	above the command transmission protocol for a server or client.
*/
class Context final {
public:
	/**
		%Context type.
	*/
	enum class Type : unsigned {
		/**
			Host view.
		*/
		host,

		/**
			Client view.
		*/
		client
	};

	/** Command map. */
	using command_map_type = aux::unordered_map<
		Cmd::IDValue,
		Cmd::UnitUPtr
	>;

	/** Command input deque. */
	using input_deque_type = aux::deque<
		Cmd::StageUPtr
	>;

	/**
		%Stage output destinations.
	*/
	enum class Dest : unsigned {
		/** %Output to remote endpoint. */
		remote = 1u,
		/** %Output to all other endpoints (local initiation). */
		broadcast_local,
		/** %Output to all other endpoints (remote initiation). */
		broadcast_remote,
	};

	/**
		Command output.
	*/
	struct Output {
	/** @name Properties */ /// @{
		/** Destination of stage. */
		Context::Dest dest;
		/** %Stage. */
		Cmd::StageUPtr stage;
	/// @}

	/** @name Special member functions */ /// @{
		/**
			Constructor with destination and stage.
		*/
		Output(
			Context::Dest const dest,
			Cmd::StageUPtr&& stage
		) noexcept
			: dest(dest)
			, stage(std::move(stage))
		{}
	/// @}

	/** @name Properties */ /// @{
		/**
			Check if output is a broadcast.
		*/
		bool
		is_broadcast() const noexcept {
			return
				Dest::broadcast_local == dest ||
				Dest::broadcast_remote == dest
			;
		}
	/// @}
	};

	/** Command output deque. */
	using output_deque_type = aux::deque<
		Context::Output
	>;

	/**
		%Stage execution result.
	*/
	struct Result {
		/** Canonical stage %ID. */
		Cmd::ID id;
		/** Command status. */
		Cmd::Status status;
		/** Command unit. */
		Cmd::UnitUPtr command;
	};

private:
	Type const m_type;
	System::Driver& m_driver;
{'fraction_non_alphanumeric': 0.14572137246796196, 'fraction_numerical': 0.0037205456800330715, 'mean_word_length': 3.1932409012131715, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6864259', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1646, 'n_words': 454}