Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Private Member Functions | Friends | List of all members
gnsstk::FFStream Class Reference

Detailed Description

Formatted File Stream (FFStream). This is just a root class to provide the single point formatted i/o operators (such as '<<' & '>>' ).

As a special design consideration, all exceptions thrown are based on gnsstk::Exception - all std::exception throws are rethrown as gnsstk::Exception. Furthermore, exceptions will not be thrown unless exceptions are set to be thrown:

fs.exceptions(std::fstream::failbit);

where fs is the name of your file stream. Then when an exception occurs, conditionalThrow() will throw the last thrown exception. Otherwise when an exception occurs, the stream sets ios::fail and will not read any more. Exceptions for this class store the record number of the file for when the exception occurred as well as the file name and any detailed information about the error. For gnsstk::FFTextStream, the line number of the file where the error was found is also recorded, allowing for easy location of file problems.

When operating on the file, recordNumber will automatically increment with each read and write operation. When a file is opened with the constructor or with open(), all internal FFStream variables are reset. Derived classes should make sure any of their internal variables are reset when either of those function are called.

Many file types have header data as part of the file format. When reading the file, the reader is not required to explicitly read in the header to access the data. To facilitate this, each of these stream classes has an internal header object that will store the header. The stream keeps track of whether it read the header or not, and reads the header if the internal state says it hasn't been read. When writing a file, the stream's internal header is used for those formats which use header information to determine what data is in the records. See RinexObsHeader::reallyGetRecord() and RinexObsData::reallyGetRecord() for an example of this.

See also
FFData for more information
RinexObsData::reallyGetRecord() and RinexObsHeader::reallyGetRecord() for more information for files that read header data.
Warning
When using open(), the internal header data of the stream is not guaranteed to be retained.

Definition at line 119 of file FFStream.hpp.

#include <FFStream.hpp>

Inheritance diagram for gnsstk::FFStream:
Inheritance graph
[legend]

Public Member Functions

void conditionalThrow (void)
 
void dumpState (std::ostream &s=std::cout) const
 A function to help debug FFStreams. More...
 
 FFStream ()
 Default constructor, initialize internal data. More...
 
 FFStream (const char *fn, std::ios::openmode mode=std::ios::in)
 
 FFStream (const std::string &fn, std::ios::openmode mode=std::ios::in)
 
virtual void open (const char *fn, std::ios::openmode mode)
 
virtual void open (const std::string &fn, std::ios::openmode mode)
 
virtual ~FFStream ()
 Virtual destructor, close the stream etc. More...
 

Static Public Member Functions

static bool isFFStream (std::istream &i)
 Check if the input stream is the kind of RinexObsStream. More...
 

Public Attributes

std::string filename
 file name More...
 
FFStreamError mostRecentException
 This stores the most recently thrown exception. More...
 
unsigned int recordNumber
 keeps track of the number of records read More...
 

Protected Member Functions

virtual void tryFFStreamGet (FFData &rec)
 
virtual void tryFFStreamPut (const FFData &rec)
 

Private Member Functions

void init (const char *fn, std::ios::openmode mode)
 Initialize internal data structures according to file name & mode. More...
 

Friends

class FFData
 FFData is a friend so it can access the try* functions. More...
 

Constructor & Destructor Documentation

◆ FFStream() [1/3]

gnsstk::FFStream::FFStream ( )

Default constructor, initialize internal data.

Definition at line 49 of file FFStream.cpp.

◆ ~FFStream()

gnsstk::FFStream::~FFStream ( )
virtual

Virtual destructor, close the stream etc.

Definition at line 56 of file FFStream.cpp.

◆ FFStream() [2/3]

gnsstk::FFStream::FFStream ( const char *  fn,
std::ios::openmode  mode = std::ios::in 
)

Common constructor.

Parameters
[in]fnfile name.
[in]modefile open mode (std::ios)

Definition at line 62 of file FFStream.cpp.

◆ FFStream() [3/3]

gnsstk::FFStream::FFStream ( const std::string &  fn,
std::ios::openmode  mode = std::ios::in 
)

Common constructor.

Parameters
[in]fnfile name.
[in]modefile open mode (std::ios)

Definition at line 82 of file FFStream.cpp.

Member Function Documentation

◆ conditionalThrow()

void gnsstk::FFStream::conditionalThrow ( void  )
inline

Throws mostRecentException only if the stream is enabled to throw exceptions when failbit is set. You can set this behavior with the following line of code:

ffstreamobject.exceptions(ifstream::failbit);

where ffstreamobject is the name of your stream object.

Exceptions
FFStreamError

Definition at line 213 of file FFStream.hpp.

◆ dumpState()

void gnsstk::FFStream::dumpState ( std::ostream &  s = std::cout) const

A function to help debug FFStreams.

Definition at line 141 of file FFStream.cpp.

◆ init()

void gnsstk::FFStream::init ( const char *  fn,
std::ios::openmode  mode 
)
private

Initialize internal data structures according to file name & mode.

Definition at line 115 of file FFStream.cpp.

◆ isFFStream()

bool gnsstk::FFStream::isFFStream ( std::istream &  i)
static

Check if the input stream is the kind of RinexObsStream.

Definition at line 125 of file FFStream.cpp.

◆ open() [1/2]

void gnsstk::FFStream::open ( const char *  fn,
std::ios::openmode  mode 
)
virtual

◆ open() [2/2]

void gnsstk::FFStream::open ( const std::string &  fn,
std::ios::openmode  mode 
)
virtual

Overrides fstream:open so derived classes can make appropriate internal changes (line count, header info, etc).

Reimplemented in gnsstk::RinexObsStream, gnsstk::Rinex3ObsStream, gnsstk::RinexClockStream, and gnsstk::FFTextStream.

Definition at line 92 of file FFStream.cpp.

◆ tryFFStreamGet()

void gnsstk::FFStream::tryFFStreamGet ( FFData rec)
protectedvirtual

Encapsulates shared try/catch blocks for all file types to hide std::exception.

Exceptions
FFStreamError
StringUtils::StringException

Reimplemented in gnsstk::FFTextStream.

Definition at line 162 of file FFStream.cpp.

◆ tryFFStreamPut()

void gnsstk::FFStream::tryFFStreamPut ( const FFData rec)
protectedvirtual

Encapsulates shared try/catch blocks for all file types to hide std::exception.

Exceptions
FFStreamError
StringUtils::StringException

Reimplemented in gnsstk::FFTextStream.

Definition at line 284 of file FFStream.cpp.

Friends And Related Function Documentation

◆ FFData

friend class FFData
friend

FFData is a friend so it can access the try* functions.

Definition at line 182 of file FFStream.hpp.

Member Data Documentation

◆ filename

std::string gnsstk::FFStream::filename

file name

Definition at line 179 of file FFStream.hpp.

◆ mostRecentException

FFStreamError gnsstk::FFStream::mostRecentException

This stores the most recently thrown exception.

Definition at line 173 of file FFStream.hpp.

◆ recordNumber

unsigned int gnsstk::FFStream::recordNumber

keeps track of the number of records read

Definition at line 176 of file FFStream.hpp.


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


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:44