ug4
ug::MatrixIO Class Reference

Generic matrix I/O functionality. More...

#include <matrix_io.h>

+ Inheritance diagram for ug::MatrixIO:

Public Types

enum  OpenMode { EXISTING = 1 , NEW = 2 }
 Specifies how file names pointing to non-existing files should be handeld. More...
 

Public Member Functions

std::string get_mat_file_name () const
 Retreive associated exchange file path and name. More...
 
 MatrixIO ()
 Number of rows as specified in the matrix exchange file. More...
 
 MatrixIO (std::string mFile, int openMode=EXISTING)
 Constructor specifying matrix exchange file path. More...
 
void set_mat_file_name (std::string mFile, int openMode=EXISTING)
 Sets associated file to another one. More...
 
 ~MatrixIO ()
 Destructor. More...
 

Private Member Functions

void close_file ()
 Closes file stream. More...
 
void open_file (std::ios_base::openmode mode=std::ios_base::in)
 Opens the associated file in m_matFileStream. More...
 

Private Attributes

std::fstream m_matFileStream
 Internal file stream for reading from and writing into the matrix exchange file. More...
 
MatrixFileType m_matFileType
 Matrix exchange file type. More...
 
std::string * m_pMatFileName
 Full path name of the matrix exchange file. More...
 

Detailed Description

Generic matrix I/O functionality.

This is the generic class for matrix I/O functionality. For actual matrix I/O operations use one of it's subclasses specifying the specific behaviour for one of the supported matrix exchange file formats.

Note
Please include this header file, when you want to use the I/O functions for a specific exchange file format.

Member Enumeration Documentation

◆ OpenMode

Specifies how file names pointing to non-existing files should be handeld.

Enumerator
EXISTING 

Only existing files are valid files (i.e. non-existing file result in error)

NEW 

Non-existing files are created with the specified file name.

Constructor & Destructor Documentation

◆ MatrixIO() [1/2]

ug::MatrixIO::MatrixIO ( )

Number of rows as specified in the matrix exchange file.

Number of columns as specified in the matrix exchange file Number of data lines as specified in the matrix exchange file

Default constructor

◆ MatrixIO() [2/2]

ug::MatrixIO::MatrixIO ( std::string  mFile,
int  openMode = EXISTING 
)

Constructor specifying matrix exchange file path.

Parameters
[in]mFilepath and name of matrix exchange file.
[in]openModehow to deal with non-existing files (a value of MatrixIO::OpenMode)

References set_mat_file_name().

◆ ~MatrixIO()

ug::MatrixIO::~MatrixIO ( )

Destructor.

The destructor calls MatrixIO::close_file to make sure, that write operations to the associated exchange file are flushed and terminated correctly.

References close_file(), and m_pMatFileName.

Member Function Documentation

◆ close_file()

void ug::MatrixIO::close_file ( )
private

Closes file stream.

References m_matFileStream.

Referenced by ~MatrixIO().

◆ get_mat_file_name()

std::string ug::MatrixIO::get_mat_file_name ( ) const

Retreive associated exchange file path and name.

Returns
String representation of exchange file with full path as set by constructor or MatrixIO::set_mat_file_name.

References m_pMatFileName.

◆ open_file()

void ug::MatrixIO::open_file ( std::ios_base::openmode  mode = std::ios_base::in)
private

Opens the associated file in m_matFileStream.

Parameters
[in]modeModus of the resulting file stream (a value of std::ios_base::openmode). Defaults to std::ios_base::in.
Exceptions
std::runtime_errorif m_pMatFileName is empty
std::runtime_errorif file stream can not be opened (i.e. failbit or badbit are set)

References m_matFileStream, m_pMatFileName, and UG_ASSERT.

◆ set_mat_file_name()

void ug::MatrixIO::set_mat_file_name ( std::string  mFile,
int  openMode = EXISTING 
)

Sets associated file to another one.

Parameters
[in]mFileFull path and name of matrix exchange file.
[in]openModehow to deal with non-existing files
Exceptions
std::runtime_errorif exchange file is not found and openMode=OpenMode::Existing.
UGErrorif openMode is non of OpenMode

References EXISTING, ug::FileExists(), m_pMatFileName, NEW, UG_ASSERT, and UG_THROW.

Referenced by MatrixIO().

Member Data Documentation

◆ m_matFileStream

std::fstream ug::MatrixIO::m_matFileStream
private

Internal file stream for reading from and writing into the matrix exchange file.

Referenced by close_file(), and open_file().

◆ m_matFileType

MatrixFileType ug::MatrixIO::m_matFileType
private

Matrix exchange file type.

◆ m_pMatFileName

std::string* ug::MatrixIO::m_pMatFileName
private

Full path name of the matrix exchange file.

Referenced by get_mat_file_name(), open_file(), set_mat_file_name(), and ~MatrixIO().


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