tk::Reader class

Reader base serves as a base class for various file readers. It does generic low-level I/O, e.g., opening and closing a file, and associated error handling.

Derived classes

class ASCMeshReader
ASCMeshReader : tk::Reader.
class GmshMeshReader
class HyperMeshReader
HyperMeshReader : tk::Reader.
class NetgenMeshReader
NetgenMeshReader : tk::Reader.
class RDGFLOMeshReader
RDGFLOMeshReader : tk::Reader.
class STLTxtMeshReader
STLTxtMeshReader : tk::Reader.
class UGRIDMeshReader
UGRIDMeshReader : tk::Reader.

Constructors, destructors, conversion operators

Reader(const std::string& filename, std::ios_base::openmode mode = std::ifstream::in) explicit
Constructor: Acquire file handle.
~Reader() virtual noexcept
Destructor: Release file handle.

Public functions

void read(char* data, std::streamsize count)
auto firstline() -> std::string
Return first line (for detection of file type based on header)
auto lines() -> std::vector<std::string>
Read file and return a string for each line.
auto line(std::size_t lineNum) -> std::string
Read a given line from file.

Protected variables

const std::string m_filename
File name.
std::ifstream m_inFile
File input stream.

Function documentation

tk::Reader::Reader(const std::string& filename, std::ios_base::openmode mode = std::ifstream::in) explicit

Constructor: Acquire file handle.

Parameters
filename in Name of file to open for reading
mode in Open mode, see http://en.cppreference.com/w/cpp/io/ios_base/openmode

tk::Reader::~Reader() virtual noexcept

Destructor: Release file handle.

Exception safety: no-throw guarantee: never throws exceptions. Error handling, while done by throwing and catching exceptions, results in warnings to terminal. We use C-style printf, since that will not throw exceptions.

void tk::Reader::read(char* data, std::streamsize count)

Parameters
data in Buffer to read to
count in Number of characters to read

Unformatted read

std::string tk::Reader::firstline()

Return first line (for detection of file type based on header)

Returns First line read from file. This can be used for detection of file type based on header.

std::vector<std::string> tk::Reader::lines()

Read file and return a string for each line.

Returns A std::vector< std::string >, a string for each line of a file.

std::string tk::Reader::line(std::size_t lineNum)

Read a given line from file.

Parameters
lineNum in Line number to read from file
Returns Line read from file at line given