<commit_before>/**
 * \file
 * \brief IntrusiveForwardList template 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-12-21
 */

#ifndef ESTD_INTRUSIVEFORWARDLIST_HPP_
#define ESTD_INTRUSIVEFORWARDLIST_HPP_

#include <iterator>

#include <cstddef>

namespace estd
{

namespace internal
{

class IntrusiveForwardListBase;

}

/**
 * \brief IntrusiveForwardListNode class is the node that is needed for the object to be linked in IntrusiveForwardList
 *
 * To some extent, this class can be considered to be a limited (raw) iterator.
 *
 * The object that wants to be linked in IntrusiveForwardList must contain a variable of this type - one for each
 * intrusive forward list that will be used with object.
 */

class IntrusiveForwardListNode
{
public:

	/// AccessKey class is used to limit access to IntrusiveForwardListNode's linkAfter() and unlinkNext() functions -
	/// only internal::IntrusiveForwardListBase can link/unlink nodes
	class AccessKey
	{
		friend class internal::IntrusiveForwardListBase;

		/**
		 * \brief AccessKey's constructor
		 */

		constexpr AccessKey()
		{

		}

		AccessKey(const AccessKey&) = delete;
		AccessKey(AccessKey&&) = delete;
		const AccessKey& operator=(const AccessKey&) = delete;
		AccessKey& operator=(AccessKey&&) = delete;
	};

	/**
	 * \brief IntrusiveForwardListNode's constructor
	 */

	constexpr IntrusiveForwardListNode() :
			nextNode_{}
	{

	}

	/**
	 * \return pointer to next node on the list
	 */

	IntrusiveForwardListNode* getNextNode() const
	{
		return nextNode_;
	}

	/**
	 * \return true if the node is linked in some list, false otherwise
	 */

	bool isLinked() const
	{
		return nextNode_ != nullptr;
	}

	/**
	 * \brief Links the node in the list after \a position.
	 *
	 * \note Access to this function is restricted only to functions from internal::IntrusiveForwardListBase class
	 *
	 * \param [in] position is a pointer to node after which this node will be linked
	 * \param [in] accessKey is used to limit access to this function
	 */

	void linkAfter(IntrusiveForwardListNode* const position, AccessKey)
	{
		nextNode_ = position->getNextNode();
		position->nextNode_ = this;
	}

	/**
	 * \brief Swaps contents with another node.
	 *
	 * \param [in] other is a reference to IntrusiveForwardListNode with which contents of this node will be swapped
	 */

	void swap(IntrusiveForwardListNode& other)
	{
		using std::swap;
		swap(nextNode_, other.nextNode_);
	}

	/**
	 * \brief Unlinks the node following this one from the list.
	 *
	 * \note Access to this function is restricted only to functions from internal::IntrusiveForwardListBase class
	 *
	 * \param [in] accessKey is used to limit access to this function
	 */

	void unlinkNext(AccessKey)
	{
		auto& nextNode = *nextNode_;
		nextNode_ = nextNode.nextNode_;

		nextNode.nextNode_ = {};
	}

private:
<commit_msg>IntrusiveForwardListNode: add private reset() function<commit_after>/**
 * \file
 * \brief IntrusiveForwardList template 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-12-23
 */

#ifndef ESTD_INTRUSIVEFORWARDLIST_HPP_
#define ESTD_INTRUSIVEFORWARDLIST_HPP_

#include <iterator>

#include <cstddef>

namespace estd
{

namespace internal
{

class IntrusiveForwardListBase;

}

/**
 * \brief IntrusiveForwardListNode class is the node that is needed for the object to be linked in IntrusiveForwardList
 *
 * To some extent, this class can be considered to be a limited (raw) iterator.
 *
 * The object that wants to be linked in IntrusiveForwardList must contain a variable of this type - one for each
 * intrusive forward list that will be used with object.
 */

class IntrusiveForwardListNode
{
public:

	/// AccessKey class is used to limit access to IntrusiveForwardListNode's linkAfter() and unlinkNext() functions -
	/// only internal::IntrusiveForwardListBase can link/unlink nodes
	class AccessKey
	{
		friend class internal::IntrusiveForwardListBase;

		/**
		 * \brief AccessKey's constructor
		 */

		constexpr AccessKey()
		{

		}

		AccessKey(const AccessKey&) = delete;
		AccessKey(AccessKey&&) = delete;
		const AccessKey& operator=(const AccessKey&) = delete;
		AccessKey& operator=(AccessKey&&) = delete;
	};

	/**
	 * \brief IntrusiveForwardListNode's constructor
	 */

	constexpr IntrusiveForwardListNode() :
			nextNode_{}
	{

	}

	/**
	 * \return pointer to next node on the list
	 */

	IntrusiveForwardListNode* getNextNode() const
	{
		return nextNode_;
	}

	/**
	 * \return true if the node is linked in some list, false otherwise
	 */

	bool isLinked() const
	{
		return nextNode_ != nullptr;
	}

	/**
	 * \brief Links the node in the list after \a position.
	 *
	 * \note Access to this function is restricted only to functions from internal::IntrusiveForwardListBase class
	 *
	 * \param [in] position is a pointer to node after which this node will be linked
	 * \param [in] accessKey is used to limit access to this function
	 */

	void linkAfter(IntrusiveForwardListNode* const position, AccessKey)
	{
		nextNode_ = position->getNextNode();
		position->nextNode_ = this;
	}

	/**
	 * \brief Swaps contents with another node.
	 *
	 * \param [in] other is a reference to IntrusiveForwardListNode with which contents of this node will be swapped
	 */

	void swap(IntrusiveForwardListNode& other)
	{
		using std::swap;
		swap(nextNode_, other.nextNode_);
	}

	/**
	 * \brief Unlinks the node following this one from the list.
	 *
	 * \note Access to this function is restricted only to functions from internal::IntrusiveForwardListBase class
	 *
	 * \param [in] accessKey is used to limit access to this function
	 */

	void unlinkNext(AccessKey)
	{
		auto& nextNode = *nextNode_;
		nextNode_ = nextNode.nextNode_;

		nextNode.nextNode_ = {};
	}

private:

	/**
	 * \brief Resets the node to the same state as right after construction.
	 */

	void reset()
	{
		nextNode_ = {};
	}

{'fraction_non_alphanumeric': 0.09218094201772113, 'fraction_numerical': 0.004974351002642624, 'mean_word_length': 3.658942795076032, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '3207971', 'n_tokens_mistral': 2103, 'n_tokens_neox': 1884, 'n_words': 693}