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:
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.
Definition at line 119 of file FFStream.hpp.
#include <FFStream.hpp>
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... | |
gnsstk::FFStream::FFStream | ( | ) |
Default constructor, initialize internal data.
Definition at line 49 of file FFStream.cpp.
|
virtual |
Virtual destructor, close the stream etc.
Definition at line 56 of file FFStream.cpp.
gnsstk::FFStream::FFStream | ( | const char * | fn, |
std::ios::openmode | mode = std::ios::in |
||
) |
Common constructor.
[in] | fn | file name. |
[in] | mode | file open mode (std::ios) |
Definition at line 62 of file FFStream.cpp.
gnsstk::FFStream::FFStream | ( | const std::string & | fn, |
std::ios::openmode | mode = std::ios::in |
||
) |
Common constructor.
[in] | fn | file name. |
[in] | mode | file open mode (std::ios) |
Definition at line 82 of file FFStream.cpp.
|
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:
where ffstreamobject is the name of your stream object.
FFStreamError |
Definition at line 213 of file FFStream.hpp.
void gnsstk::FFStream::dumpState | ( | std::ostream & | s = std::cout | ) | const |
A function to help debug FFStreams.
Definition at line 141 of file FFStream.cpp.
|
private |
Initialize internal data structures according to file name & mode.
Definition at line 115 of file FFStream.cpp.
|
static |
Check if the input stream is the kind of RinexObsStream.
Definition at line 125 of file FFStream.cpp.
|
virtual |
Overrides fstream::open so derived classes can make appropriate internal changes (line count, header info, etc).
Reimplemented in gnsstk::AshtechStream, gnsstk::RinexObsStream, gnsstk::Rinex3ObsStream, gnsstk::RinexClockStream, gnsstk::FFTextStream, gnsstk::SEMStream, gnsstk::RinexMetStream, gnsstk::YumaStream, gnsstk::IonexStream, gnsstk::FFBinaryStream, gnsstk::Rinex3NavStream, gnsstk::AntexStream, gnsstk::RinexNavStream, gnsstk::SP3Stream, and gnsstk::Rinex3ClockStream.
Definition at line 100 of file FFStream.cpp.
|
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.
|
protectedvirtual |
Encapsulates shared try/catch blocks for all file types to hide std::exception.
FFStreamError | |
StringUtils::StringException |
Reimplemented in gnsstk::FFTextStream.
Definition at line 162 of file FFStream.cpp.
Encapsulates shared try/catch blocks for all file types to hide std::exception.
FFStreamError | |
StringUtils::StringException |
Reimplemented in gnsstk::FFTextStream.
Definition at line 284 of file FFStream.cpp.
|
friend |
FFData is a friend so it can access the try* functions.
Definition at line 182 of file FFStream.hpp.
std::string gnsstk::FFStream::filename |
file name
Definition at line 179 of file FFStream.hpp.
FFStreamError gnsstk::FFStream::mostRecentException |
This stores the most recently thrown exception.
Definition at line 173 of file FFStream.hpp.
unsigned int gnsstk::FFStream::recordNumber |
keeps track of the number of records read
Definition at line 176 of file FFStream.hpp.