MeVisLab Toolbox Reference
ml::ByteDataReader Class Reference

Base class to implement raw data loaders which need byte swapping and basic file access on byte or raw data level. More...

#include <mlByteDataReader.h>

Inheritance diagram for ml::ByteDataReader:
ml::DMFileReader ml::R2SonicWC::R2SonicWCLoader

Public Member Functions

 ByteDataReader ()
 Default constructor which gets its settings later. More...
 
 ByteDataReader (const std::string &fileName)
 Constructor already setting the file name. More...
 
virtual ~ByteDataReader ()
 Destructor (automatically closes the current open file if there is any and clear allocated subimage data). More...
 
virtual std::string getFileName () const
 Returns the currently used file name or "" on default case. More...
 
virtual void setFileName (const std::string &fileName)
 Sets the new file name. More...
 
virtual void open ()
 Opens the file if possible, isGood() will return true on success, otherwise false; if byte swapping may be required in file format then derived classes should overwrite this method and call _setNeedsByteSwapping() to make get*BitUWordInLocalEndianess() methods work correctly. More...
 
virtual bool isOpen () const
 Returns true if the file is open, otherwise false. More...
 
virtual void close ()
 Closes the file if it was open, otherwise the call is ignored. More...
 
virtual bool isGood () const
 Returns true if the recent operations since the last clearState() call were successful. More...
 
virtual std::string getErrorState () const
 Returns the current state string which is non empty on any error, empty otherwise. More...
 
virtual void clearErrorState ()
 Resets the error state to success, i.e. to an empty string. More...
 
virtual void setIndent (const std::string &indent)
 Sets the default indentation string for tag dumps. More...
 
virtual const std::string & getIndent () const
 The default indentation string for tag dumps. More...
 
bool needsByteSwapping () const
 Returns true if raw file data needs byte swapping, otherwise false; needs to be set with _setNeedsByteSwapping when opening the file in derived classes. More...
 
virtual void prefetch ()
 Loads all file content into memory to avoid expensive file descriptor access on each get*Word call. More...
 
virtual const MLuint8getPrefetchData () const
 Returns pointer to prefetch data (or nullptr if not available). More...
 
virtual void clearPrefetchData ()
 If any data is in the prefetch data memory then it is freed. More...
 
MLuint8 get8BitUWord (MLuint64 pos) const
 Read an unsigned 8 bit word from position pos. More...
 
MLuint16 get16BitUWord (MLuint64 pos) const
 Read an unsigned 16 bit word from position pos. More...
 
MLuint16 get16BitUWordInLocalEndianess (MLuint64 pos) const
 Read an unsigned 16 bit word from position pos and convert it in local endianness. More...
 
MLuint32 get32BitUWord (MLuint64 pos) const
 Read an unsigned 32 bit word from position pos. More...
 
MLuint32 get32BitUWordInLocalEndianess (MLuint64 pos) const
 Read an unsigned 32 bit word from position pos and convert it in local endianness. More...
 
MLuint64 get64BitUWord (MLuint64 pos) const
 Read an unsigned 64 bit word from position pos. More...
 
MLuint64 get64BitUWordInLocalEndianess (MLuint64 pos) const
 Read an unsigned 64 bit word from position pos and convert it in local endianness. More...
 
std::string getNonTerminatedDataAsString (MLuint originPosition, MLuint numChars) const
 Return a non-null terminated data area starting at position originPosition of length numChars as std::string. More...
 
MLuint8getDataChunk (MLuint64 pos, MLuint64 numBytes) const
 Reads numBytes from position pos in the file and returns it as allocated data chunk which has to be freed with MLFree(). More...
 
const MLuint8getPrefetchDataChunk (MLuint64 pos, MLuint64 numBytes) const
 Returns a data pointer to position pos with size numBytes in the prefetch data if available and if chunk size is sufficient. More...
 
virtual std::string getAsString (const std::string &prefix="", const std::string &sep=", ", const size_t maxNumBinaryEntries=8, const size_t maxNumStringEntries=20) const
 Convert content to a human readable string with the prefix prefix before all lines and separator sep between all subcomponents. More...
 
MLint getFileSizeFromCurrentDescriptor ()
 Returns MLFileGetSizeFromDescriptor(_getFileDescriptor()). More...
 
void appendStringToState (const std::string &errDesc) const
 Appends the given string to error state string (which also sets bad read state). More...
 

Protected Member Functions

int _getFileDescriptor () const
 Returns the current file descriptor. More...
 
void _appendErrNoToState (const std::string &errDesc) const
 Appends the given string as error description, translates errno to an MLErrorCode an also adds that state as an error description. More...
 
void _setNeedsByteSwapping (bool needsSwapping)
 To se set to true in open() by derived classes if raw file data needs byte swapping, otherwise it should be set to false; defaults to false. More...
 

Detailed Description

Base class to implement raw data loaders which need byte swapping and basic file access on byte or raw data level.

Definition at line 23 of file mlByteDataReader.h.

Constructor & Destructor Documentation

◆ ByteDataReader() [1/2]

ml::ByteDataReader::ByteDataReader ( )

Default constructor which gets its settings later.

◆ ByteDataReader() [2/2]

ml::ByteDataReader::ByteDataReader ( const std::string &  fileName)

Constructor already setting the file name.

◆ ~ByteDataReader()

virtual ml::ByteDataReader::~ByteDataReader ( )
virtual

Destructor (automatically closes the current open file if there is any and clear allocated subimage data).

Member Function Documentation

◆ _appendErrNoToState()

void ml::ByteDataReader::_appendErrNoToState ( const std::string &  errDesc) const
protected

Appends the given string as error description, translates errno to an MLErrorCode an also adds that state as an error description.

◆ _getFileDescriptor()

int ml::ByteDataReader::_getFileDescriptor ( ) const
protected

Returns the current file descriptor.

◆ _setNeedsByteSwapping()

void ml::ByteDataReader::_setNeedsByteSwapping ( bool  needsSwapping)
protected

To se set to true in open() by derived classes if raw file data needs byte swapping, otherwise it should be set to false; defaults to false.

◆ appendStringToState()

void ml::ByteDataReader::appendStringToState ( const std::string &  errDesc) const

Appends the given string to error state string (which also sets bad read state).

◆ clearErrorState()

virtual void ml::ByteDataReader::clearErrorState ( )
virtual

Resets the error state to success, i.e. to an empty string.

◆ clearPrefetchData()

virtual void ml::ByteDataReader::clearPrefetchData ( )
virtual

If any data is in the prefetch data memory then it is freed.

◆ close()

virtual void ml::ByteDataReader::close ( )
virtual

Closes the file if it was open, otherwise the call is ignored.

Reimplemented in ml::DMFileReader.

◆ get16BitUWord()

MLuint16 ml::ByteDataReader::get16BitUWord ( MLuint64  pos) const

Read an unsigned 16 bit word from position pos.

◆ get16BitUWordInLocalEndianess()

MLuint16 ml::ByteDataReader::get16BitUWordInLocalEndianess ( MLuint64  pos) const

Read an unsigned 16 bit word from position pos and convert it in local endianness.

◆ get32BitUWord()

MLuint32 ml::ByteDataReader::get32BitUWord ( MLuint64  pos) const

Read an unsigned 32 bit word from position pos.

◆ get32BitUWordInLocalEndianess()

MLuint32 ml::ByteDataReader::get32BitUWordInLocalEndianess ( MLuint64  pos) const

Read an unsigned 32 bit word from position pos and convert it in local endianness.

◆ get64BitUWord()

MLuint64 ml::ByteDataReader::get64BitUWord ( MLuint64  pos) const

Read an unsigned 64 bit word from position pos.

◆ get64BitUWordInLocalEndianess()

MLuint64 ml::ByteDataReader::get64BitUWordInLocalEndianess ( MLuint64  pos) const

Read an unsigned 64 bit word from position pos and convert it in local endianness.

◆ get8BitUWord()

MLuint8 ml::ByteDataReader::get8BitUWord ( MLuint64  pos) const

Read an unsigned 8 bit word from position pos.

◆ getAsString()

virtual std::string ml::ByteDataReader::getAsString ( const std::string &  prefix = "",
const std::string &  sep = ", ",
const size_t  maxNumBinaryEntries = 8,
const size_t  maxNumStringEntries = 20 
) const
virtual

Convert content to a human readable string with the prefix prefix before all lines and separator sep between all subcomponents.

If a binary tag is displayed then the number of shown values is controlled with maxNumBinaryEntries; if there are more then "..." is displayed instead. If a binary tag of type Uint16 which might be a unicoded string then the number of shown values is controlled with maxNumStringEntries; if there are more then "..." is displayed instead.

Reimplemented in ml::DMFileReader, and ml::R2SonicWC::R2SonicWCLoader.

◆ getDataChunk()

MLuint8* ml::ByteDataReader::getDataChunk ( MLuint64  pos,
MLuint64  numBytes 
) const

Reads numBytes from position pos in the file and returns it as allocated data chunk which has to be freed with MLFree().

This function always reads from file even if prefetch() was called before.

◆ getErrorState()

virtual std::string ml::ByteDataReader::getErrorState ( ) const
virtual

Returns the current state string which is non empty on any error, empty otherwise.

◆ getFileName()

virtual std::string ml::ByteDataReader::getFileName ( ) const
virtual

Returns the currently used file name or "" on default case.

◆ getFileSizeFromCurrentDescriptor()

MLint ml::ByteDataReader::getFileSizeFromCurrentDescriptor ( )

Returns MLFileGetSizeFromDescriptor(_getFileDescriptor()).

◆ getIndent()

virtual const std::string& ml::ByteDataReader::getIndent ( ) const
virtual

The default indentation string for tag dumps.

◆ getNonTerminatedDataAsString()

std::string ml::ByteDataReader::getNonTerminatedDataAsString ( MLuint  originPosition,
MLuint  numChars 
) const

Return a non-null terminated data area starting at position originPosition of length numChars as std::string.

◆ getPrefetchData()

virtual const MLuint8* ml::ByteDataReader::getPrefetchData ( ) const
virtual

Returns pointer to prefetch data (or nullptr if not available).

◆ getPrefetchDataChunk()

const MLuint8* ml::ByteDataReader::getPrefetchDataChunk ( MLuint64  pos,
MLuint64  numBytes 
) const

Returns a data pointer to position pos with size numBytes in the prefetch data if available and if chunk size is sufficient.

Otherwise an error state is set and nullptr is returned.

◆ isGood()

virtual bool ml::ByteDataReader::isGood ( ) const
virtual

Returns true if the recent operations since the last clearState() call were successful.

◆ isOpen()

virtual bool ml::ByteDataReader::isOpen ( ) const
virtual

Returns true if the file is open, otherwise false.

◆ needsByteSwapping()

bool ml::ByteDataReader::needsByteSwapping ( ) const

Returns true if raw file data needs byte swapping, otherwise false; needs to be set with _setNeedsByteSwapping when opening the file in derived classes.

◆ open()

virtual void ml::ByteDataReader::open ( )
virtual

Opens the file if possible, isGood() will return true on success, otherwise false; if byte swapping may be required in file format then derived classes should overwrite this method and call _setNeedsByteSwapping() to make get*BitUWordInLocalEndianess() methods work correctly.

Reimplemented in ml::DMFileReader, and ml::R2SonicWC::R2SonicWCLoader.

◆ prefetch()

virtual void ml::ByteDataReader::prefetch ( )
virtual

Loads all file content into memory to avoid expensive file descriptor access on each get*Word call.

This, however, requires that enough memory is available. Note also that if large files are read and only small sections are read, that prefetching can make everything slower.

◆ setFileName()

virtual void ml::ByteDataReader::setFileName ( const std::string &  fileName)
virtual

Sets the new file name.

◆ setIndent()

virtual void ml::ByteDataReader::setIndent ( const std::string &  indent)
virtual

Sets the default indentation string for tag dumps.


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