<commit_before>/**
 * \file
 * \brief BufferingBlockDevice class header
 *
 * \author Copyright (C) 2019 <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/.
 */

#ifndef INCLUDE_DISTORTOS_DEVICES_MEMORY_BUFFERINGBLOCKDEVICE_HPP_
#define INCLUDE_DISTORTOS_DEVICES_MEMORY_BUFFERINGBLOCKDEVICE_HPP_

#include "distortos/devices/memory/BlockDevice.hpp"

namespace distortos
{

namespace devices
{

class BlockDevice;

/**
 * BufferingBlockDevice class is a buffering wrapper for BlockDevice.
 *
 * This class tries to minimize amount of BlockDevice operations by buffering both reads and writes. This can give
 * signigicant gain in case of devices like SD cards, where each operation may cause the device to become "busy" for a
 * noticeable amount of time. With this class several adjacent reads or writes can be combined into a single larger
 * operation, which is much faster overall when you also include the waits for the SD card to become "idle".
 *
 * Another use for this class is as a proxy between a file system and a block device which requires specific alignment.
 *
 * \ingroup devices
 */

class BufferingBlockDevice : public BlockDevice
{
public:

	/**
	 * \brief BufferingBlockDevice's constructor
	 *
	 * \param [in] blockDevice is a reference to associated block device
	 * \param [in] readBuffer is a pointer to buffer for reads, its address must be aligned to
	 * `DISTORTOS_BLOCKDEVICE_BUFFER_ALIGNMENT` bytes
	 * \param [in] readBufferSize is the size of \a readBuffer, bytes, must be a multiple of \a blockDevice block size
	 * \param [in] writeBuffer is a pointer to buffer for writes, its address must be aligned to
	 * `DISTORTOS_BLOCKDEVICE_BUFFER_ALIGNMENT` bytes
	 * \param [in] writeBufferSize is the size of \a writeBuffer, bytes, must be a multiple of \a blockDevice block size
	 */

	constexpr explicit BufferingBlockDevice(BlockDevice& blockDevice, void* const readBuffer,
			const size_t readBufferSize, void* const writeBuffer, const size_t writeBufferSize) :
					readBufferAddress_{},
					writeBufferAddress_{},
					blockDevice_{blockDevice},
					readBuffer_{readBuffer},
					readBufferSize_{readBufferSize},
					writeBuffer_{writeBuffer},<commit_msg>fixup BufferingBlockDevice<commit_after>/**
 * \file
 * \brief BufferingBlockDevice class header
 *
 * \author Copyright (C) 2019 <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/.
 */

#ifndef INCLUDE_DISTORTOS_DEVICES_MEMORY_BUFFERINGBLOCKDEVICE_HPP_
#define INCLUDE_DISTORTOS_DEVICES_MEMORY_BUFFERINGBLOCKDEVICE_HPP_

#include "distortos/devices/memory/BlockDevice.hpp"

namespace distortos
{

namespace devices
{

class BlockDevice;

/**
 * BufferingBlockDevice class is a buffering wrapper for BlockDevice.
 *
 * This class tries to minimize amount of BlockDevice operations by buffering both reads and writes. Such buffering can
 * give signigicant gain in case of devices like SD cards, where each operation may cause the device to become "busy"
 * for a noticeable amount of time. With this class several adjacent reads or writes can be combined into a single
 * larger operation, which is much faster overall when you also include the waits for the SD card to become "idle".
 *
 * Another use for this class is as a proxy between a file system and a block device which requires specific alignment.
 *
 * \ingroup devices
 */

class BufferingBlockDevice : public BlockDevice
{
public:

	/**
	 * \brief BufferingBlockDevice's constructor
	 *
	 * \param [in] blockDevice is a reference to associated block device
	 * \param [in] readBuffer is a pointer to buffer for reads, its address must be aligned to
	 * `DISTORTOS_BLOCKDEVICE_BUFFER_ALIGNMENT` bytes
	 * \param [in] readBufferSize is the size of \a readBuffer, bytes, must be a multiple of \a blockDevice block size
	 * \param [in] writeBuffer is a pointer to buffer for writes, its address must be aligned to
	 * `DISTORTOS_BLOCKDEVICE_BUFFER_ALIGNMENT` bytes
	 * \param [in] writeBufferSize is the size of \a writeBuffer, bytes, must be a multiple of \a blockDevice block size
	 */

	constexpr explicit BufferingBlockDevice(BlockDevice& blockDevice, void* const readBuffer,
			const size_t readBufferSize, void* const writeBuffer, const size_t writeBufferSize) :
					readBufferAddress_{},
					writeBufferAddress_{},
					blockDevice_{blockDevice},
					readBuffer_{readBuffer},
					readBufferSize_{readBufferSize},
					writeBuffer_{writeBuffer},
{'fraction_non_alphanumeric': 0.06706439004320099, 'fraction_numerical': 0.0032915038058012754, 'mean_word_length': 4.360529217199559, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '528485', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1307, 'n_words': 567}