<commit_before>/*
Copyright (c) 2013 <NAME>, <NAME>
Copyright (c) 2012 <NAME>, <NAME>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

#include "Types.h"
#include "File.h"

namespace crown
{

/// A reader that offers a convenient way to read text from a File
///
/// @ingroup Filesystem
class TextReader
{
public:

	//-----------------------------------------------------------------------------
	TextReader(File& file) : m_file(file) {}

	/// Reads characters from file and stores them as a C string
	/// into string until (size-1) characters have been read or
	/// either a newline or the End-of-File is reached, whichever
	/// comes first.
	/// A newline character makes fgets stop reading, but it is considered
	/// a valid character and therefore it is included in the string copied to string.
	/// A null character is automatically appended in str after the characters read to
	/// signal the end of the C string.
	size_t read_string(char* string, size_t size)
	{
		char current_char;
		size_t bytes_read = 0;

		while(!m_file.end_of_file() && bytes_read < size - 1)
		{
			m_file.read(&current_char, 1);
			string[bytes_read] = current_char;

			bytes_read++;

			if (current_char == '\n')
			{
				break;
			}
		}

		string[bytes_read] = '\0';

		return bytes_read;
	}

private:

	File& m_file;
};

/// A reader that offers a convenient way to write text to a File
///
/// @ingroup Filesystem
class TextWriter
{
public:

	//-----------------------------------------------------------------------------
	TextWriter(File& file) : m_file(file) {}

	/// Writes the string pointed by string to the file.
	/// The function begins copying from the address specified (string)
	/// until it reaches the terminating null character ('\0').
	/// The final null character is not copied to the file.
	void write_string(const char* string)
	{
		m_file.write(string, string::strlen(string));
	}

private:

	File& m_file;
};

/// A writer that offers a convenient way to write to a File
///
/// @ingroup Filesystem
class BinaryWriter
{
public:

	//-----------------------------------------------------------------------------
	BinaryWriter(File& file) : m_file(file) {}

	template <typename T>
	void write(const T& data)
	{
		m_file.write(&data, sizeof(T));
	}

	void skip(size_t bytes)
	{
		m_file.skip(bytes);
	}

private:

	File& m_file;
};

/// A reader that offers a convenient way to read from a File
///
/// @ingroup Filesystem
class BinaryReader
{
public:

	//-----------------------------------------------------------------------------
	BinaryReader(File& file) : m_file(file) {}

	template <typename T>
	void read(T& data)
	{
		m_file.read(&data, sizeof(T));
	}
<commit_msg>Add read/write data blocks<commit_after>/*
Copyright (c) 2013 <NAME>, <NAME>
Copyright (c) 2012 <NAME>, <NAME>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

#include "Types.h"
#include "File.h"

namespace crown
{

/// A reader that offers a convenient way to read text from a File
///
/// @ingroup Filesystem
class TextReader
{
public:

	//-----------------------------------------------------------------------------
	TextReader(File& file) : m_file(file) {}

	/// Reads characters from file and stores them as a C string
	/// into string until (size-1) characters have been read or
	/// either a newline or the End-of-File is reached, whichever
	/// comes first.
	/// A newline character makes fgets stop reading, but it is considered
	/// a valid character and therefore it is included in the string copied to string.
	/// A null character is automatically appended in str after the characters read to
	/// signal the end of the C string.
	size_t read_string(char* string, size_t size)
	{
		char current_char;
		size_t bytes_read = 0;

		while(!m_file.end_of_file() && bytes_read < size - 1)
		{
			m_file.read(&current_char, 1);
			string[bytes_read] = current_char;

			bytes_read++;

			if (current_char == '\n')
			{
				break;
			}
		}

		string[bytes_read] = '\0';

		return bytes_read;
	}

private:

	File& m_file;
};

/// A reader that offers a convenient way to write text to a File
///
/// @ingroup Filesystem
class TextWriter
{
public:

	//-----------------------------------------------------------------------------
	TextWriter(File& file) : m_file(file) {}

	/// Writes the string pointed by string to the file.
	/// The function begins copying from the address specified (string)
	/// until it reaches the terminating null character ('\0').
	/// The final null character is not copied to the file.
	void write_string(const char* string)
	{
		m_file.write(string, string::strlen(string));
	}

private:

	File& m_file;
};

/// A writer that offers a convenient way to write to a File
///
/// @ingroup Filesystem
class BinaryWriter
{
public:

	//-----------------------------------------------------------------------------
	BinaryWriter(File& file) : m_file(file) {}

	void write(const void* data, size_t size)
	{
		m_file.write(data, size);
	}

	template <typename T>
	void write(const T& data)
	{
		m_file.write(&data, sizeof(T));
	}

	void skip(size_t bytes)
	{
		m_file.skip(bytes);
	}

private:

	File& m_file;
};

/// A reader that offers a convenient way to read from a File
///
/// @ingroup Filesystem
class BinaryReader
{
public:

	//-----------------------------------------------------------------------------
	BinaryReader(File& file) : m_file(file) {}

	void read(void* data, size_t size)
	{
		m_file.read(data, size);
	}

	template <typename T>
	void read(T& data)
	{
		m_file.read(&data, sizeof(T));
	}

{'fraction_non_alphanumeric': 0.17280149912996923, 'fraction_numerical': 0.003747824923035738, 'mean_word_length': 2.5614871306005718, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '3502984', 'n_tokens_mistral': 2227, 'n_tokens_neox': 2070, 'n_words': 890}