libpniio
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
pni::io::data_reader Class Reference

base class for data readers More...

#include <data_reader.hpp>

Inheritance diagram for pni::io::data_reader:
Inheritance graph
[legend]
Collaboration diagram for pni::io::data_reader:
Collaboration graph
[legend]

Public Member Functions

virtual ~data_reader ()
 destructor More...
 
pni::core::string filename () const
 get filename More...
 
void filename (const pni::core::string &fname)
 set filename More...
 
virtual void close ()
 close the file More...
 
virtual void open ()
 open file More...
 

Protected Member Functions

std::ifstream & _get_stream () const
 get stream More...
 
void _set_binary ()
 set binary mode More...
 
 data_reader ()
 default constructor More...
 
 data_reader (const pni::core::string &fname, bool binary=false)
 standard constructor More...
 
 data_reader (data_reader &&r)
 move constructor More...
 
 data_reader (const data_reader &r)=delete
 copy constructor is deleted More...
 
data_readeroperator= (const data_reader &r)=delete
 copy assigment is deleted More...
 
data_readeroperator= (data_reader &&r)
 move assignment More...
 

Private Member Functions

std::unique_ptr< std::ifstream > _open_stream (const pni::core::string &fname) const
 open the stream More...
 

Private Attributes

pni::core::string _fname
 name of the file More...
 
bool _is_binary
 flag determining how files will be opened More...
 
std::unique_ptr< std::ifstream > _istream
 stream from which to read data More...
 

Detailed Description

This is the base class for all data readers. Actually this class only manages the name of the file to open for reading. One cannot instantiate an object of this class directly. This is done via the concrete reader classes. Thus all constructors are protected making them available only for derived classes.

Constructor & Destructor Documentation

pni::io::data_reader::data_reader ( )
protected
pni::io::data_reader::data_reader ( const pni::core::string &  fname,
bool  binary = false 
)
explicitprotected

This constructor takes the name of the file from which to reads data as its only argument and opens the file.

Exceptions
FileErrorif opening the file fails
Parameters
fnamename of the file
binaryif true stream will be opened in binary mode
pni::io::data_reader::data_reader ( data_reader &&  r)
protected
pni::io::data_reader::data_reader ( const data_reader r)
protecteddelete
pni::io::data_reader::~data_reader ( )
virtual

Member Function Documentation

std::ifstream& pni::io::data_reader::_get_stream ( ) const
inlineprotected

Return a non-const reference to the stream on the file. This method is protected and thus only available to derived classes which can use this method to obtain a reference to the stream.

Returns
non-const stream reference
std::unique_ptr< std::ifstream > pni::io::data_reader::_open_stream ( const pni::core::string &  fname) const
private

Virtual private method opening the stream. This class provides a default implementation for this method. If a different way of opening a stream is required this method must be overloaded by child classes.

Exceptions
file_errorif opening the file fails
memory_allocation_errorif allocation of a stream object fails
Parameters
fnamefile name
Returns
unique pointer to the input stream
void pni::io::data_reader::_set_binary ( )
inlineprotected

Set the stream mode to binary. This method is primarily used by default constructors which do not have parameters.

void pni::io::data_reader::close ( )
virtual

Reimplemented in pni::io::tiff_reader, and pni::io::cbf_reader.

string pni::io::data_reader::filename ( ) const
Returns
name of the file from which to read data
void pni::io::data_reader::filename ( const pni::core::string &  fname)
Parameters
fnamename of the file to read data from
void pni::io::data_reader::open ( )
virtual

Opens the file given by filename.

Exceptions
FileErrorin case of errors

Reimplemented in pni::io::tiff_reader, and pni::io::cbf_reader.

data_reader& pni::io::data_reader::operator= ( const data_reader r)
protecteddelete
data_reader & pni::io::data_reader::operator= ( data_reader &&  r)
protected

Field Documentation

pni::core::string pni::io::data_reader::_fname
private
bool pni::io::data_reader::_is_binary
private
std::unique_ptr<std::ifstream> pni::io::data_reader::_istream
mutableprivate

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