WRApplication
External kratos "application" for multiscale time integration.
FileContentIterator Class Reference

Iterator interface around a file pointer. More...

Collaboration diagram for FileContentIterator:

Public Types

using FileAccess = std::optional< std::pair< std::fstream, LockObject > >
 
using iterator_category = std::forward_iterator_tag
 
using value_type = std::pair< FileContentIterator, FileContentIterator >
 An iterator pair {begin,end} representing a range within the file. More...
 
using difference_type = std::ptrdiff_t
 
using pointer = void
 
using reference = void
 

Public Member Functions

 FileContentIterator (std::shared_ptr< FileAccess > &&rpFileAccess, char delimiter='\n')
 
 FileContentIterator (const std::shared_ptr< FileAccess > &rpFileAccess, char delimiter='\n')
 
 FileContentIterator ()=delete
 
 FileContentIterator (FileContentIterator &&rOther)=default
 
 FileContentIterator (const FileContentIterator &rOther)=default
 
FileContentIteratoroperator= (FileContentIterator &&rOther)=default
 
FileContentIteratoroperator= (const FileContentIterator &rOther)=default
 
FileContentIteratoroperator++ ()
 
FileContentIterator operator++ (int)
 
value_type operator* () const
 
std::string value () const
 Read the associated range from the file into a string. More...
 
void SeekEOF ()
 Set the iterator to the end of the file. More...
 

Friends

bool operator== (const FileContentIterator &rLeft, const FileContentIterator &rRight)
 
bool operator!= (const FileContentIterator &rLeft, const FileContentIterator &rRight)
 
bool operator< (const FileContentIterator &rLeft, const FileContentIterator &rRight)
 

Detailed Description

Iterator interface around a file pointer.

This class represents a read-only iterator over the items of a delimited file. Dereferencing this iterator yields a a range instead of reading the file to a string; if you need the value_type to be a string, use FileStringIterator. Alternatively, you can use FileContentIterator::value to read the pointed-to range into a string.

Access to the file is provided by an std::fstream and an associated lock that ensures that no other thread has access to the file while any iterators to it are alive. The iterators position within the file is stored separately, and is restored every time some operation is performed on the iterator. This makes sure multiple iterators can use the file.

Warning
Even though the file stream is tied to the lifetime of a lock, the user can still create a separate stream+lock pair to the same file on a different thread. Please don't do that ... .

Member Typedef Documentation

◆ difference_type

using difference_type = std::ptrdiff_t

◆ FileAccess

using FileAccess = std::optional<std::pair< std::fstream, LockObject > >

◆ iterator_category

using iterator_category = std::forward_iterator_tag

◆ pointer

using pointer = void

◆ reference

using reference = void

◆ value_type

An iterator pair {begin,end} representing a range within the file.

Todo:
Change this to the Range class if #10114 ever gets merged (@matekelemen).

Constructor & Destructor Documentation

◆ FileContentIterator() [1/5]

FileContentIterator ( std::shared_ptr< FileAccess > &&  rpFileAccess,
char  delimiter = '\n' 
)

◆ FileContentIterator() [2/5]

FileContentIterator ( const std::shared_ptr< FileAccess > &  rpFileAccess,
char  delimiter = '\n' 
)

◆ FileContentIterator() [3/5]

FileContentIterator ( )
delete

◆ FileContentIterator() [4/5]

FileContentIterator ( FileContentIterator &&  rOther)
default

◆ FileContentIterator() [5/5]

FileContentIterator ( const FileContentIterator rOther)
default

Member Function Documentation

◆ operator*()

value_type operator* ( ) const

◆ operator++() [1/2]

FileContentIterator& operator++ ( )

◆ operator++() [2/2]

FileContentIterator operator++ ( int  )

◆ operator=() [1/2]

FileContentIterator& operator= ( const FileContentIterator rOther)
default

◆ operator=() [2/2]

FileContentIterator& operator= ( FileContentIterator &&  rOther)
default

◆ SeekEOF()

void SeekEOF ( )

Set the iterator to the end of the file.

◆ value()

std::string value ( ) const

Read the associated range from the file into a string.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const FileContentIterator rLeft,
const FileContentIterator rRight 
)
friend

◆ operator<

bool operator< ( const FileContentIterator rLeft,
const FileContentIterator rRight 
)
friend

◆ operator==

bool operator== ( const FileContentIterator rLeft,
const FileContentIterator rRight 
)
friend

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