<commit_before>/**
 * \file
 * \brief SignalSet class header
 *
 * \author Copyright (C) 2015 <NAME> http://www.distortec.com http://www.freddiechopin.info
 *
 * \par License
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
 * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * \date 2015-02-08
 */

#ifndef INCLUDE_DISTORTOS_SIGNALSET_HPP_
#define INCLUDE_DISTORTOS_SIGNALSET_HPP_

#include <bitset>

namespace distortos
{

/**
 * \brief SignalSet class is used as a set of signals.
 *
 * Similar to POSIX sigset_t - http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html
 */

class SignalSet
{
public:

	/// tag struct to construct empty SignalSet
	struct Empty
	{

	};

	/// tag struct to construct full SignalSet
	struct Full
	{

	};

	/// tag object to construct empty SignalSet
	constexpr static Empty empty = {};

	/// tag object to construct full SignalSet
	constexpr static Full full = {};

	/**
	 * \brief SignalSet's constructor
	 *
	 * \param [in] bitmask is the bit mask used to initialize internal bitset
	 */

	constexpr explicit SignalSet(uint32_t bitmask) :
			bitset_{bitmask}
	{

	}

	/**
	 * \brief SignalSet's constructor
	 *
	 * Constructs empty SignalSet.
	 *
	 * Similar to sigemptyset() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigemptyset.html#
	 */

	constexpr explicit SignalSet(const Empty&) :
			SignalSet{uint32_t{}}
	{

	}

	/**
	 * \brief SignalSet's constructor
	 *
	 * Constructs full SignalSet.
	 *
	 * Similar to sigfillset() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigfillset.html#
	 */

	constexpr explicit SignalSet(const Full&) :
			SignalSet{~uint32_t{}}
	{

	}

	/**
	 * \brief Sets single bit.
	 *
	 * Similar to sigaddset() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaddset.html#
	 *
	 * \param [in] signalNumber is the bit position that will be set, [0; 31]
	 *
	 * \return 0 on success, error code otherwise:
	 * - EINVAL - \a signalNumber value is invalid;
	 */

	int add(const uint8_t signalNumber)
	{
		return set(signalNumber, true);
	}

	/**
	 * \brief Clears single bit.
	 *
	 * Similar to sigdelset() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigdelset.html#
	 *
	 * \param [in] signalNumber is the bit position that will be cleared, [0; 31]
	 *
	 * \return 0 on success, error code otherwise:
	 * - EINVAL - \a signalNumber value is invalid;
	 */

	int remove(const uint8_t signalNumber)
	{
		return set(signalNumber, false);
	}

	/**
	 * \brief Tests whether the bit is set.
	 *
	 * Similar to sigismember() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigismember.html#
	 *
	 * \param [in] signalNumber is the bit position that will be tested, [0; 31]
	 *
	 * \return pair with return code (0 on success, error code otherwise) and value of selected bit; error codes:
	 * - EINVAL - \a signalNumber value is invalid;
	 */

	std::pair<int, bool> test(uint8_t signalNumber) const;

private:

	/**
	 * \brief Sets value of single bit.
	 *
	 * \param [in] signalNumber is the bit position that will be modified, [0; 31]
	 * \param [in] value is the new value for selected bit
	 *
	 * \return 0 on success, error code otherwise:
	 * - EINVAL - \a signalNumber value is invalid;
	 */

	int set(uint8_t signalNumber, bool value);

	/// internal bitset for 32 signals
	std::bitset<32> bitset_;
};

}	// namespace distortos

#endif	// INCLUDE_DISTORTOS_SIGNALSET_HPP_<commit_msg>SignalSet: add type alias for used std::bitset<commit_after>/**
 * \file
 * \brief SignalSet class header
 *
 * \author Copyright (C) 2015 <NAME> http://www.distortec.com http://www.freddiechopin.info
 *
 * \par License
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
 * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * \date 2015-02-09
 */

#ifndef INCLUDE_DISTORTOS_SIGNALSET_HPP_
#define INCLUDE_DISTORTOS_SIGNALSET_HPP_

#include <bitset>

namespace distortos
{

/**
 * \brief SignalSet class is used as a set of signals.
 *
 * Similar to POSIX sigset_t - http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html
 */

class SignalSet
{
public:

	/// type of internal bitset for 32 signals
	using Bitset = std::bitset<32>;

	/// tag struct to construct empty SignalSet
	struct Empty
	{

	};

	/// tag struct to construct full SignalSet
	struct Full
	{

	};

	/// tag object to construct empty SignalSet
	constexpr static Empty empty = {};

	/// tag object to construct full SignalSet
	constexpr static Full full = {};

	/**
	 * \brief SignalSet's constructor
	 *
	 * \param [in] bitmask is the bit mask used to initialize internal bitset
	 */

	constexpr explicit SignalSet(uint32_t bitmask) :
			bitset_{bitmask}
	{

	}

	/**
	 * \brief SignalSet's constructor
	 *
	 * Constructs empty SignalSet.
	 *
	 * Similar to sigemptyset() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigemptyset.html#
	 */

	constexpr explicit SignalSet(const Empty&) :
			SignalSet{uint32_t{}}
	{

	}

	/**
	 * \brief SignalSet's constructor
	 *
	 * Constructs full SignalSet.
	 *
	 * Similar to sigfillset() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigfillset.html#
	 */

	constexpr explicit SignalSet(const Full&) :
			SignalSet{~uint32_t{}}
	{

	}

	/**
	 * \brief Sets single bit.
	 *
	 * Similar to sigaddset() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaddset.html#
	 *
	 * \param [in] signalNumber is the bit position that will be set, [0; 31]
	 *
	 * \return 0 on success, error code otherwise:
	 * - EINVAL - \a signalNumber value is invalid;
	 */

	int add(const uint8_t signalNumber)
	{
		return set(signalNumber, true);
	}

	Bitset getBitset() const
	{
		return bitset_;
	}

	/**
	 * \brief Clears single bit.
	 *
	 * Similar to sigdelset() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigdelset.html#
	 *
	 * \param [in] signalNumber is the bit position that will be cleared, [0; 31]
	 *
	 * \return 0 on success, error code otherwise:
	 * - EINVAL - \a signalNumber value is invalid;
	 */

	int remove(const uint8_t signalNumber)
	{
		return set(signalNumber, false);
	}

	/**
	 * \brief Tests whether the bit is set.
	 *
	 * Similar to sigismember() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigismember.html#
	 *
	 * \param [in] signalNumber is the bit position that will be tested, [0; 31]
	 *
	 * \return pair with return code (0 on success, error code otherwise) and value of selected bit; error codes:
	 * - EINVAL - \a signalNumber value is invalid;
	 */

	std::pair<int, bool> test(uint8_t signalNumber) const;

private:

	/**
	 * \brief Sets value of single bit.
	 *
	 * \param [in] signalNumber is the bit position that will be modified, [0; 31]
	 * \param [in] value is the new value for selected bit
	 *
	 * \return 0 on success, error code otherwise:
	 * - EINVAL - \a signalNumber value is invalid;
	 */

	int set(uint8_t signalNumber, bool value);

	/// internal bitset for 32 signals
	Bitset bitset_;
};

}	// namespace distortos

#endif	// INCLUDE_DISTORTOS_SIGNALSET_HPP_
{'fraction_non_alphanumeric': 0.1158477508650519, 'fraction_numerical': 0.02961937716262976, 'mean_word_length': 3.2207943925233646, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2207090', 'n_tokens_mistral': 2707, 'n_tokens_neox': 2322, 'n_words': 734}