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

appends to a RecordFile through a buffer of records, the file opened only to write the buffer More...

#include <ADS/external/RecordFile.h>

Public member functions

 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
 RecordWriter (RecordWriter &&) noexcept=default
 the writer moved, its buffer with it
 RecordWriter (const RecordWriter &)=delete
 no copy, since the records of the buffer would be written twice
RecordWriter & operator= (const RecordWriter &)=delete
 no copy, since the records of the buffer would be written twice
 ~RecordWriter ()
 flush(), an error of the file system being dropped: a program that must see it calls flush() before
void push (const T &x)
 appends \( x \), writing the buffer when it is full
void flush (void)
 the records of the buffer written to the file
std::size_t pending (void) const
 the records in the buffer, not yet in the file
RecordFile< T > & file (void) const
 the file written

Detailed description

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

appends to a RecordFile through a buffer of records, the file opened only to write the buffer

Constructor and destructor documentation

◆ RecordWriter() [1/3]

template<class T>
ADS::RecordWriter< T >::RecordWriter ( RecordFile< T > & file,
std::size_t buffer = RecordFile< T >::defaultBuffer )
explicit

the writer at the end of file (which must outlive it), with a buffer of buffer records

Precondition
buffer \( \ge 1 \)

◆ RecordWriter() [2/3]

template<class T>
ADS::RecordWriter< T >::RecordWriter ( RecordWriter< T > && )
defaultnoexcept

the writer moved, its buffer with it

◆ RecordWriter() [3/3]

template<class T>
ADS::RecordWriter< T >::RecordWriter ( const RecordWriter< T > & )
delete

no copy, since the records of the buffer would be written twice

◆ ~RecordWriter()

template<class T>
ADS::RecordWriter< T >::~RecordWriter ( )

flush(), an error of the file system being dropped: a program that must see it calls flush() before

Member function documentation

◆ file()

template<class T>
RecordFile< T > & ADS::RecordWriter< T >::file ( void ) const
nodiscard

the file written

◆ flush()

template<class T>
void ADS::RecordWriter< T >::flush ( void )

the records of the buffer written to the file

Postcondition
pending() is 0

◆ operator=()

template<class T>
RecordWriter & ADS::RecordWriter< T >::operator= ( const RecordWriter< T > & )
delete

no copy, since the records of the buffer would be written twice

◆ pending()

template<class T>
std::size_t ADS::RecordWriter< T >::pending ( void ) const
nodiscard

the records in the buffer, not yet in the file

◆ push()

template<class T>
void ADS::RecordWriter< T >::push ( const T & x)

appends \( x \), writing the buffer when it is full

In pseudocode, \( b \) the records of a full buffer:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{push}( x ) \cr 2 & \quad \text{append } x \text{ to the buffer} \cr 3 & \quad \textbf{if}\ \text{the buffer holds } b \text{ records} \ \textbf{then}\ \mathrm{flush}()\quad \triangleright\ \text{open } \text{the file, append the buffer, close the file} \end{array}} \]


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