ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::RecordFile< T > Class Template Reference

a file of records of a trivially copyable type on the disk More...

#include <ADS/external/RecordFile.h>

Public types

using value_type = T
 the type of the records
using size_type = std::size_t
 the type of the sizes

Public member functions

 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
bool empty (void) const
 whether the file has no record
void append (const T *src, std::size_t n)
 the \( n \) records of src appended at the end of the file, which is made if it does not exist, after its last whole record (the bytes of a record left partial by a write interrupted, which size() and the scans do not count, are dropped)
template<class F>
void forEach (F &&f, std::size_t buffer=defaultBuffer) const
 \( f( x ) \) for each record \( x \) of the file, in order, read through a buffer of buffer records
std::vector< T > readAll (void) const
 all the records of the file, in order
void clear (void)
 the file emptied, and made if it does not exist
void remove (void)
 the file deleted from the disk, if it is there

Static public attributes

static constexpr std::size_t defaultBuffer
 the records of a buffer of 1 MB, the default of the scans and of the writers

Detailed description

template<class T>
requires std::is_trivially_copyable_v< T >
class ADS::RecordFile< T >

a file of records of a trivially copyable type on the disk

Member typedef documentation

◆ size_type

template<class T>
using ADS::RecordFile< T >::size_type = std::size_t

the type of the sizes

◆ value_type

template<class T>
using ADS::RecordFile< T >::value_type = T

the type of the records

Constructor and destructor documentation

◆ RecordFile()

template<class T>
ADS::RecordFile< T >::RecordFile ( std::filesystem::path path)
explicit

the file at path, whose records are those already there, if any

Member function documentation

◆ append()

template<class T>
void ADS::RecordFile< T >::append ( const T * src,
std::size_t n )

the \( n \) records of src appended at the end of the file, which is made if it does not exist, after its last whole record (the bytes of a record left partial by a write interrupted, which size() and the scans do not count, are dropped)

Precondition
src is not null unless \( n = 0 \)
Postcondition
size() grows by \( n \)

◆ clear()

template<class T>
void ADS::RecordFile< T >::clear ( void )

the file emptied, and made if it does not exist

Postcondition
empty()

◆ empty()

template<class T>
bool ADS::RecordFile< T >::empty ( void ) const
nodiscard

whether the file has no record

◆ forEach()

template<class T>
template<class F>
void ADS::RecordFile< T >::forEach ( F && f,
std::size_t buffer = defaultBuffer ) const

\( f( x ) \) for each record \( x \) of the file, in order, read through a buffer of buffer records

Precondition
buffer \( \ge 1 \)

◆ path()

template<class T>
const std::filesystem::path & ADS::RecordFile< T >::path ( void ) const
nodiscard

the path of the file

◆ readAll()

template<class T>
std::vector< T > ADS::RecordFile< T >::readAll ( void ) const
nodiscard

all the records of the file, in order

◆ remove()

template<class T>
void ADS::RecordFile< T >::remove ( void )

the file deleted from the disk, if it is there

Postcondition
empty()

◆ size()

template<class T>
std::size_t ADS::RecordFile< T >::size ( void ) const
nodiscard

the number of whole records of the file, 0 if it does not exist

Member data documentation

◆ defaultBuffer

template<class T>
std::size_t ADS::RecordFile< T >::defaultBuffer
staticconstexpr
Initial value:
=
sizeof( T ) >= ( std::size_t( 1 ) << 20 )
? 1
: ( std::size_t( 1 ) << 20 ) / sizeof( T )

the records of a buffer of 1 MB, the default of the scans and of the writers


The documentation for this class was generated from the following file: