0.4.1
Loading...
Searching...
No Matches
NAV::FileReader Class Reference

Abstract File Reader class. More...

Public Types

enum  FileType : uint8_t {
  NONE ,
  BINARY ,
  ASCII
}
 File Type Enumeration. More...
 
enum  GuiResult : uint8_t {
  PATH_UNCHANGED ,
  PATH_CHANGED ,
  PATH_CHANGED_INVALID
}
 Results enum for the gui config. More...
 

Public Member Functions

 FileReader (const FileReader &)=delete
 Copy constructor.
 
 FileReader (FileReader &&)=delete
 Move constructor.
 
FileReaderoperator= (const FileReader &)=delete
 Copy assignment operator.
 
FileReaderoperator= (FileReader &&)=delete
 Move assignment operator.
 
virtual ~FileReader ()=default
 Destructor.
 

Protected Member Functions

void deinitialize ()
 Deinitialize the file reader.
 
virtual FileType determineFileType ()
 Virtual Function to determine the File Type.
 
auto eof () const
 Check whether the end of file is reached.
 
 FileReader ()=default
 Default constructor.
 
size_t getCurrentLineNumber () const
 Get the current line number.
 
std::filesystem::path getFilepath ()
 Returns the path of the file.
 
auto & getline (std::string &str)
 Reads a line from the filestream.
 
bool good () const
 Fast error checking.
 
GuiResult guiConfig (const char *vFilters, const std::vector< std::string > &extensions, size_t id, const std::string &nameId)
 ImGui config.
 
auto & ignore (std::streamsize count, int delim)
 Extracts and discards characters from the input stream until and including delim.
 
bool initialize ()
 Initialize the file reader.
 
auto peek ()
 Looking ahead in the stream.
 
auto & read (char *__s, std::streamsize __n)
 Extraction without delimiters.
 
virtual void readHeader ()
 Virtual Function to read the Header of a file.
 
auto readsome (char *s, std::streamsize count)
 Extracts up to count immediately available characters from the input stream. The extracted characters are stored into the character array pointed to by s.
 
void resetReader ()
 Moves the read cursor to the start.
 
void restore (const json &j)
 Restores the node from a json object.
 
json save () const
 Saves the node into a json object.
 
auto & seekg (std::streamoff pos, std::ios_base::seekdir dir)
 Changing the current read position.
 
std::streampos tellg ()
 Getting the current read position.
 

Protected Attributes

FileType _fileType
 File Type.
 
std::vector< std::string > _headerColumns
 Header Columns of a CSV file.
 
std::string _path
 Path to the file.
 

Private Attributes

std::streampos _dataStart
 Start of the data in the file.
 
std::ifstream _filestream
 File stream to read the file.
 
size_t _lineCnt
 Line counter.
 
size_t _lineCntDataStart
 Line counter data start.
 

Detailed Description

Abstract File Reader class.

Definition at line 30 of file FileReader.hpp.

Member Enumeration Documentation

◆ FileType

enum NAV::FileReader::FileType : uint8_t

File Type Enumeration.

Enumerator
NONE 

Not specified.

BINARY 

Binary data.

ASCII 

Ascii text data.

Definition at line 34 of file FileReader.hpp.

◆ GuiResult

Results enum for the gui config.

Enumerator
PATH_UNCHANGED 

No changes made.

PATH_CHANGED 

The path changed and exists.

PATH_CHANGED_INVALID 

The path changed but does not exist or is invalid.

Definition at line 53 of file FileReader.hpp.

Constructor & Destructor Documentation

◆ ~FileReader()

virtual NAV::FileReader::~FileReader ( )
virtualdefault

Destructor.

◆ FileReader() [1/3]

NAV::FileReader::FileReader ( const FileReader & )
delete

Copy constructor.

◆ FileReader() [2/3]

NAV::FileReader::FileReader ( FileReader && )
delete

Move constructor.

◆ FileReader() [3/3]

NAV::FileReader::FileReader ( )
protecteddefault

Default constructor.

Member Function Documentation

◆ deinitialize()

void NAV::FileReader::deinitialize ( )
protected

Deinitialize the file reader.

Definition at line 136 of file FileReader.cpp.

◆ determineFileType()

NAV::FileReader::FileType NAV::FileReader::determineFileType ( )
nodiscardprotectedvirtual

Virtual Function to determine the File Type.

Returns
The File path which was recognized

Reimplemented in NAV::CsvFile, NAV::EmlidFile, NAV::KvhFile, NAV::MultiImuFile, NAV::NmeaFile, NAV::RinexNavFile, NAV::RinexObsFile, NAV::RtklibPosFile, NAV::UbloxFile, NAV::UlogFile, and NAV::VectorNavFile.

Definition at line 150 of file FileReader.cpp.

◆ eof()

auto NAV::FileReader::eof ( ) const
inlinenodiscardprotected

Check whether the end of file is reached.

Definition at line 141 of file FileReader.hpp.

◆ getCurrentLineNumber()

size_t NAV::FileReader::getCurrentLineNumber ( ) const
inlinenodiscardprotected

Get the current line number.

Definition at line 152 of file FileReader.hpp.

◆ getFilepath()

std::filesystem::path NAV::FileReader::getFilepath ( )
protected

Returns the path of the file.

Definition at line 44 of file FileReader.cpp.

◆ getline()

auto & NAV::FileReader::getline ( std::string & str)
inlineprotected

Reads a line from the filestream.

Parameters
strString to read the line into

Definition at line 103 of file FileReader.hpp.

◆ good()

bool NAV::FileReader::good ( ) const
inlinenodiscardprotected

Fast error checking.

Returns
True if no error flags are set. A wrapper around rdstate.

Definition at line 145 of file FileReader.hpp.

◆ guiConfig()

NAV::FileReader::GuiResult NAV::FileReader::guiConfig ( const char * vFilters,
const std::vector< std::string > & extensions,
size_t id,
const std::string & nameId )
protected

ImGui config.

Parameters
[in]vFiltersFilter to apply for file names
[in]extensionsExtensions to filter
[in]idUnique id for creating the dialog uid
[in]nameIdName of the node triggering the window used for logging
Returns
True if changes occurred

Definition at line 23 of file FileReader.cpp.

◆ ignore()

auto & NAV::FileReader::ignore ( std::streamsize count,
int delim )
inlineprotected

Extracts and discards characters from the input stream until and including delim.

Parameters
countnumber of characters to extract
delimdelimiting character to stop the extraction at. It is also extracted.
Returns
The filestream

Definition at line 126 of file FileReader.hpp.

◆ initialize()

bool NAV::FileReader::initialize ( )
protected

Initialize the file reader.

Definition at line 76 of file FileReader.cpp.

◆ operator=() [1/2]

FileReader & NAV::FileReader::operator= ( const FileReader & )
delete

Copy assignment operator.

◆ operator=() [2/2]

FileReader & NAV::FileReader::operator= ( FileReader && )
delete

Move assignment operator.

◆ peek()

auto NAV::FileReader::peek ( )
inlinenodiscardprotected

Looking ahead in the stream.

Returns
The next character, or eof(). If, after constructing the sentry object, good() is false, returns traits::eof(). Otherwise reads but does not extract the next input character.

Definition at line 149 of file FileReader.hpp.

◆ read()

auto & NAV::FileReader::read ( char * __s,
std::streamsize __n )
inlineprotected

Extraction without delimiters.

Parameters
__sA character array.
__nMaximum number of characters to store.
Returns
The filestream if the stream state is good(), extracts characters and stores them into __s until one of the following happens: - __n characters are stored - the input sequence reaches end-of-file, in which case the error state is set to failbit|eofbit.
Note
This function is not overloaded on signed char and unsigned char.

Definition at line 120 of file FileReader.hpp.

◆ readHeader()

void NAV::FileReader::readHeader ( )
protectedvirtual

Virtual Function to read the Header of a file.

The base implementation reads a CSV file header

Attention
If your file does not have a header, this functions needs to be overridden with an empty function

Reimplemented in NAV::CsvFile, NAV::MultiImuFile, NAV::NmeaFile, NAV::RinexNavFile, NAV::RinexObsFile, NAV::RtklibPosFile, NAV::UlogFile, and NAV::VectorNavFile.

Definition at line 177 of file FileReader.cpp.

◆ readsome()

auto NAV::FileReader::readsome ( char * s,
std::streamsize count )
inlineprotected

Extracts up to count immediately available characters from the input stream. The extracted characters are stored into the character array pointed to by s.

Parameters
[out]spointer to the character array to store the characters to
[in]countmaximum number of characters to read
Returns
The number of characters actually extracted.

Definition at line 113 of file FileReader.hpp.

◆ resetReader()

void NAV::FileReader::resetReader ( )
protected

Moves the read cursor to the start.

Definition at line 203 of file FileReader.cpp.

◆ restore()

void NAV::FileReader::restore ( const json & j)
protected

Restores the node from a json object.

Parameters
[in]jJson object with the node state

Definition at line 66 of file FileReader.cpp.

◆ save()

json NAV::FileReader::save ( ) const
nodiscardprotected

Saves the node into a json object.

Definition at line 55 of file FileReader.cpp.

◆ seekg()

auto & NAV::FileReader::seekg ( std::streamoff pos,
std::ios_base::seekdir dir )
inlineprotected

Changing the current read position.

Parameters
posA file offset object.
dirThe direction in which to seek.
Returns
The filestream if fail() is not true, calls rdbuf()->pubseekoff(__off,__dir). If that function fails, sets failbit.
Note
This function first clears eofbit. It does not count the number of characters extracted, if any, and therefore does not affect the next call to gcount().

Definition at line 133 of file FileReader.hpp.

◆ tellg()

std::streampos NAV::FileReader::tellg ( )
inlinenodiscardprotected

Getting the current read position.

Returns
A file position object. If fail() is not false, returns pos_type(-1) to indicate failure. Otherwise returns rdbuf()->pubseekoff(0,cur,in).
Note
This function does not count the number of characters extracted, if any, and therefore does not affect the next call to gcount(). At variance with putback, unget and seekg, eofbit is not cleared first.

Definition at line 138 of file FileReader.hpp.

Field Documentation

◆ _dataStart

std::streampos NAV::FileReader::_dataStart
private

Start of the data in the file.

Definition at line 166 of file FileReader.hpp.

◆ _filestream

std::ifstream NAV::FileReader::_filestream
private

File stream to read the file.

Definition at line 164 of file FileReader.hpp.

◆ _fileType

FileType NAV::FileReader::_fileType
protected

File Type.

Definition at line 157 of file FileReader.hpp.

◆ _headerColumns

std::vector<std::string> NAV::FileReader::_headerColumns
protected

Header Columns of a CSV file.

Definition at line 160 of file FileReader.hpp.

◆ _lineCnt

size_t NAV::FileReader::_lineCnt
private

Line counter.

Definition at line 168 of file FileReader.hpp.

◆ _lineCntDataStart

size_t NAV::FileReader::_lineCntDataStart
private

Line counter data start.

Definition at line 170 of file FileReader.hpp.

◆ _path

std::string NAV::FileReader::_path
protected

Path to the file.

Definition at line 155 of file FileReader.hpp.


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