Nvwa  1.1
Classes | Public Types | Public Member Functions | Private Member Functions | List of all members
nvwa::mmap_line_reader Class Reference

Class to allow iteration over all lines of a mmappable file. More...

#include <mmap_line_reader.h>

Classes

class  iterator
 Iterator that contains the line content. More...
 

Public Types

enum  strip_type { strip_delimiter, no_strip_delimiter }
 Enumeration of whether the delimiter should be stripped. More...
 

Public Member Functions

 mmap_line_reader (const char *path, char delimiter='\n', strip_type strip=strip_delimiter)
 Constructor. More...
 
 mmap_line_reader (int fd, char delimiter='\n', strip_type strip=strip_delimiter)
 Constructor. More...
 
 ~mmap_line_reader ()
 Destructor. More...
 
bool read (std::string &output, off_t &offset)
 Reads content from the mmaped file. More...
 

Private Member Functions

void initialize ()
 Initializes the object. More...
 

Detailed Description

Class to allow iteration over all lines of a mmappable file.

Member Enumeration Documentation

◆ strip_type

Enumeration of whether the delimiter should be stripped.

Enumerator
strip_delimiter 

The delimiter should be stripped.

no_strip_delimiter 

The delimiter should be retained.

Constructor & Destructor Documentation

◆ mmap_line_reader() [1/2]

nvwa::mmap_line_reader::mmap_line_reader ( const char *  path,
char  delimiter = '\n',
strip_type  strip = strip_delimiter 
)
explicit

Constructor.

Parameters
pathpath to the file to open
delimiterthe delimiter between text `lines' (default to LF)
stripenumerator about whether to strip the delimiter

◆ mmap_line_reader() [2/2]

nvwa::mmap_line_reader::mmap_line_reader ( int  fd,
char  delimiter = '\n',
strip_type  strip = strip_delimiter 
)
explicit

Constructor.

Parameters
patha file descriptor
delimiterthe delimiter between text `lines' (default to LF)
stripenumerator about whether to strip the delimiter

◆ ~mmap_line_reader()

nvwa::mmap_line_reader::~mmap_line_reader ( )

Destructor.

Member Function Documentation

◆ initialize()

void nvwa::mmap_line_reader::initialize ( )
private

Initializes the object.

It gets the file size and mmaps the whole file.

◆ read()

bool nvwa::mmap_line_reader::read ( std::string &  output,
off_t &  offset 
)

Reads content from the mmaped file.

Parameters
[out]outputstring to receive the line
[in,out]offsetoffset of reading pos on entry; end offset on exit
Returns
true if line content is returned; false otherwise

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