00001 #pragma ident "$Id: FFStream.hpp 3316 2012-09-11 06:44:29Z yanweignss $"
00002
00009 #ifndef GPSTK_FFSTREAM_HPP
00010 #define GPSTK_FFSTREAM_HPP
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include <iostream>
00051 #include <fstream>
00052 #include <string>
00053 #include <typeinfo>
00054
00055 #include "FFStreamError.hpp"
00056 #include "FFData.hpp"
00057 #include "StringUtils.hpp"
00058
00059
00060 namespace gpstk
00061 {
00064
00067 NEW_EXCEPTION_CLASS(EndOfFile, gpstk::FFStreamError);
00068
00120 class FFStream : public std::fstream
00121 {
00122 public:
00123
00125 virtual ~FFStream(void) {};
00126
00127
00131 FFStream()
00132 : recordNumber(0) {};
00133
00134
00140 FFStream( const char* fn, std::ios::openmode mode=std::ios::in )
00141 : std::fstream(fn, mode), recordNumber(0), filename(fn)
00142 { clear(); }
00143
00144
00150 FFStream( const std::string& fn, std::ios::openmode mode=std::ios::in )
00151 : std::fstream(fn.c_str(), mode), recordNumber(0), filename(fn)
00152 { clear(); };
00153
00154
00159 virtual void open( const char* fn, std::ios::openmode mode );
00160
00161
00166 virtual void open( const std::string& fn, std::ios::openmode mode )
00167 { open( fn.c_str(), mode ); };
00168
00169
00171 void dumpState(std::ostream& s = std::cout) const;
00172
00173
00183 inline void conditionalThrow(void) throw(FFStreamError)
00184 {
00185
00186 if (exceptions() & std::fstream::failbit)
00187 {
00188 GPSTK_THROW(mostRecentException);
00189 }
00190
00191 };
00192
00194 static bool IsFFStream(std::istream& i)
00195 {
00196 try
00197 {
00198 FFStream& r = dynamic_cast<FFStream&>(i);
00199 }
00200 catch(...)
00201 {
00202 return false;
00203 }
00204
00205 return true;
00206 }
00207
00208
00212 FFStreamError mostRecentException;
00213
00214
00216 unsigned int recordNumber;
00217
00218
00220 std::string filename;
00221
00223
00224
00226 friend class FFData;
00227
00228
00229 protected:
00230
00231
00234 virtual void tryFFStreamGet(FFData& rec)
00235 throw(FFStreamError, gpstk::StringUtils::StringException);
00236
00237
00240 virtual void tryFFStreamPut(const FFData& rec)
00241 throw(FFStreamError, gpstk::StringUtils::StringException);
00242
00243
00244 };
00245
00247
00248 }
00249 #endif // GPSTK_FFSTREAM_HPP
00250