49#ifndef __ADS_RecordFile
50 #define __ADS_RecordFile
80 requires std::is_trivially_copyable_v< T >
93 sizeof( T ) >= ( std::size_t( 1 ) << 20 )
95 : ( std::size_t( 1 ) << 20 ) /
sizeof( T );
101 [[nodiscard]]
const std::filesystem::path &
path(
void )
const;
104 [[nodiscard]] std::size_t
size(
void )
const;
107 [[nodiscard]]
bool empty(
void )
const;
115 void append(
const T * src , std::size_t n );
124 [[nodiscard]] std::vector< T >
readAll(
void )
const;
137 std::filesystem::path f_path;
149 requires std::is_trivially_copyable_v< T >
194 [[nodiscard]] std::
size_t pending(
void ) const;
204 std::vector< T > f_buf;
223 const std::string & prefix =
"ads-" );
238 [[nodiscard]]
const std::filesystem::path &
path(
void )
const;
241 [[nodiscard]] std::filesystem::path
247 std::filesystem::path f_path;
259#include "ADS/external/impl/RecordFile.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
a file of records of a trivially copyable type on the disk
Definition RecordFile.h:82
T value_type
the type of the records
Definition RecordFile.h:87
std::size_t size_type
the type of the sizes
Definition RecordFile.h:88
static constexpr std::size_t defaultBuffer
the records of a buffer of 1 MB, the default of the scans and of the writers
Definition RecordFile.h:92
void forEach(F &&f, std::size_t buffer=defaultBuffer) const
for each record of the file, in order, read through a buffer of buffer records
bool empty(void) const
whether the file has no record
void append(const T *src, std::size_t n)
the records of src appended at the end of the file, which is made if it does not exist,...
void remove(void)
the file deleted from the disk, if it is there
RecordFile(std::filesystem::path path)
the file at path, whose records are those already there, if any
const std::filesystem::path & path(void) const
the path of the file
std::size_t size(void) const
the number of whole records of the file, 0 if it does not exist
void clear(void)
the file emptied, and made if it does not exist
std::vector< T > readAll(void) const
all the records of the file, in order
RecordWriter(RecordWriter &&) noexcept=default
the writer moved, its buffer with it
std::size_t pending(void) const
the records in the buffer, not yet in the file
void push(const T &x)
appends , writing the buffer when it is full
RecordFile< T > & file(void) const
the file written
void flush(void)
the records of the buffer written to the file
RecordWriter(RecordFile< T > &file, std::size_t buffer=RecordFile< T >::defaultBuffer)
the writer at the end of file (which must outlive it), with a buffer of buffer records
TempDirectory(TempDirectory &&other) noexcept
the directory moved: the moved one removes nothing
TempDirectory(const TempDirectory &)=delete
no copy, since the directory would be removed twice
TempDirectory & operator=(const TempDirectory &)=delete
no copy, since the directory would be removed twice
~TempDirectory()
the directory removed with all that it holds, errors dropped
const std::filesystem::path & path(void) const
the path of the directory
TempDirectory(const std::filesystem::path &parent={}, const std::string &prefix="ads-")
a new directory, of a name not taken, in parent (the temporary directory of the system if empty),...
std::filesystem::path operator/(const std::string &name) const
the path of the file name in the directory