00001 #pragma ident "$Id: FFStream.hpp 1349 2008-08-06 19:33:13Z architest $"
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
00058 #include "StringUtils.hpp"
00059
00060 #ifdef _MSC_VER
00061 using namespace std;
00062 #endif
00063
00064 namespace gpstk
00065 {
00068
00071 NEW_EXCEPTION_CLASS(EndOfFile, gpstk::FFStreamError);
00072
00124 class FFStream : public std::fstream
00125 {
00126 public:
00127
00129 virtual ~FFStream(void) {};
00130
00131
00135 FFStream()
00136 : recordNumber(0) {};
00137
00138
00144 FFStream( const char* fn,
00145 std::ios::openmode mode=std::ios::in )
00146 :
00147 #ifdef _MSC_VER
00148 fstream(fn, mode),
00149 #else
00150 std::fstream(fn, mode),
00151 #endif
00152 recordNumber(0), filename(fn)
00153 { clear(); }
00154
00155
00161 FFStream( const std::string& fn,
00162 std::ios::openmode mode=std::ios::in )
00163 :
00164 #ifdef _MSC_VER
00165 fstream(fn.c_str(), mode),
00166 #else
00167 std::fstream(fn.c_str(), mode),
00168 #endif
00169 recordNumber(0), filename(fn)
00170 { clear(); };
00171
00172
00177 virtual void open( const char* fn,
00178 std::ios::openmode mode );
00179
00180
00185 virtual void open( const std::string& fn,
00186 std::ios::openmode mode )
00187 { open( fn.c_str(), mode ); };
00188
00189
00191 void dumpState(std::ostream& s = std::cout) const;
00192
00193
00203 inline void conditionalThrow(void) throw(FFStreamError)
00204 {
00205
00206 if (exceptions() & std::fstream::failbit)
00207 {
00208 GPSTK_THROW(mostRecentException);
00209 }
00210
00211 };
00212
00213
00217 FFStreamError mostRecentException;
00218
00219
00221 unsigned int recordNumber;
00222
00223
00225 std::string filename;
00226
00228
00229
00231 friend class FFData;
00232
00233
00234 protected:
00235
00236
00239 virtual void tryFFStreamGet(FFData& rec)
00240 throw(FFStreamError, gpstk::StringUtils::StringException);
00241
00242
00245 virtual void tryFFStreamPut(const FFData& rec)
00246 throw(FFStreamError, gpstk::StringUtils::StringException);
00247
00248
00249 };
00250
00252
00253 }
00254 #endif // GPSTK_FFSTREAM_HPP
00255