FFStream.hpp

Go to the documentation of this file.
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 //  This file is part of GPSTk, the GPS Toolkit.
00015 //
00016 //  The GPSTk is free software; you can redistribute it and/or modify
00017 //  it under the terms of the GNU Lesser General Public License as published
00018 //  by the Free Software Foundation; either version 2.1 of the License, or
00019 //  any later version.
00020 //
00021 //  The GPSTk is distributed in the hope that it will be useful,
00022 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024 //  GNU Lesser General Public License for more details.
00025 //
00026 //  You should have received a copy of the GNU Lesser General Public
00027 //  License along with GPSTk; if not, write to the Free Software Foundation,
00028 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00029 //
00030 //  Copyright 2004, The University of Texas at Austin
00031 //
00032 //============================================================================
00033 
00034 //============================================================================
00035 //
00036 //This software developed by Applied Research Laboratories at the University of
00037 //Texas at Austin, under contract to an agency or agencies within the U.S.
00038 //Department of Defense. The U.S. Government retains all rights to use,
00039 //duplicate, distribute, disclose, or release this software.
00040 //
00041 //Pursuant to DoD Directive 523024
00042 //
00043 // DISTRIBUTION STATEMENT A: This software has been approved for public
00044 //                           release, distribution is unlimited.
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    }; // End of class 'FFStream'
00250 
00252 
00253 }  // End of namespace gpstk
00254 #endif   // GPSTK_FFSTREAM_HPP
00255 

Generated on Wed Feb 8 03:30:59 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1