<commit_before>#line 2 "togo/file_io.hpp"
/**
@copyright MIT license; see @ref index or the accompanying LICENSE file.

@file file_io.hpp
@brief File IO.
@ingroup io
@ingroup file_io
*/

#pragma once

#include <togo/config.hpp>
#include <togo/types.hpp>
#include <togo/io_types.hpp>
#include <togo/io_proto.hpp>

#if defined(TOGO_PLATFORM_IS_POSIX)
	#include <togo/impl/file_io/posix.hpp>
#else
	#error "missing file_io implementation for target platform"
#endif

namespace togo {

/**
	@addtogroup io
	@{
*/
/**
	@addtogroup file_io
	@{
*/

/**
	File reader.
*/
class FileReader
	: public virtual IStreamBase
	, public IStreamSeekable
	, public IReader
{
public:
	FileStreamData _data{};

	~FileReader() override;
	FileReader() = default;

	FileReader(FileReader const&) = delete;
	FileReader(FileReader&&) = delete;
	FileReader& operator=(FileReader const&) = delete;
	FileReader& operator=(FileReader&&) = delete;

	/// Attempt to open a file.
	///
	/// Returns false if the file could not be opened.
	bool open(char const* path);

	/// Close the stream.
	void close();

private:
// IStreamBase implementation
	IOStatus status() const override;

// IStreamSeekable implementation
	u64 position() override;
	u64 seek_to(u64 position) override;
	u64 seek_relative(s64 offset) override;

// IReader implementation
	IOStatus read(void* data, unsigned size, unsigned* const read_size) override;
};

/**
	File writer.
*/
class FileWriter
	: public virtual IStreamBase
	, public IStreamSeekable
	, public IWriter
{
public:
	FileStreamData _data{};

	~FileWriter() override;
	FileWriter() = default;

	FileWriter(FileWriter const&) = delete;
	FileWriter(FileWriter&&) = delete;
	FileWriter& operator=(FileWriter const&) = delete;
	FileWriter& operator=(FileWriter&&) = delete;

	/// Attempt to open a file.
	///
	/// Returns false if the file could not be opened.<commit_msg>file_io: removed const not matching interface.<commit_after>#line 2 "togo/file_io.hpp"
/**
@copyright MIT license; see @ref index or the accompanying LICENSE file.

@file file_io.hpp
@brief File IO.
@ingroup io
@ingroup file_io
*/

#pragma once

#include <togo/config.hpp>
#include <togo/types.hpp>
#include <togo/io_types.hpp>
#include <togo/io_proto.hpp>

#if defined(TOGO_PLATFORM_IS_POSIX)
	#include <togo/impl/file_io/posix.hpp>
#else
	#error "missing file_io implementation for target platform"
#endif

namespace togo {

/**
	@addtogroup io
	@{
*/
/**
	@addtogroup file_io
	@{
*/

/**
	File reader.
*/
class FileReader
	: public virtual IStreamBase
	, public IStreamSeekable
	, public IReader
{
public:
	FileStreamData _data{};

	~FileReader() override;
	FileReader() = default;

	FileReader(FileReader const&) = delete;
	FileReader(FileReader&&) = delete;
	FileReader& operator=(FileReader const&) = delete;
	FileReader& operator=(FileReader&&) = delete;

	/// Attempt to open a file.
	///
	/// Returns false if the file could not be opened.
	bool open(char const* path);

	/// Close the stream.
	void close();

private:
// IStreamBase implementation
	IOStatus status() const override;

// IStreamSeekable implementation
	u64 position() override;
	u64 seek_to(u64 position) override;
	u64 seek_relative(s64 offset) override;

// IReader implementation
	IOStatus read(void* data, unsigned size, unsigned* read_size) override;
};

/**
	File writer.
*/
class FileWriter
	: public virtual IStreamBase
	, public IStreamSeekable
	, public IWriter
{
public:
	FileStreamData _data{};

	~FileWriter() override;
	FileWriter() = default;

	FileWriter(FileWriter const&) = delete;
	FileWriter(FileWriter&&) = delete;
	FileWriter& operator=(FileWriter const&) = delete;
	FileWriter& operator=(FileWriter&&) = delete;

	/// Attempt to open a file.
	///
	/// Returns false if the file could not be opened.
{'fraction_non_alphanumeric': 0.12423679320414123, 'fraction_numerical': 0.005840191133528006, 'mean_word_length': 4.460869565217391, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4399960', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1254, 'n_words': 363}