FFStream.hpp

Go to the documentation of this file.
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 //  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110, 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 #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    }; // End of class 'FFStream'
00245 
00247 
00248 }  // End of namespace gpstk
00249 #endif   // GPSTK_FFSTREAM_HPP
00250 

Generated on Sat May 18 03:31:04 2013 for GPS ToolKit Software Library by  doxygen 1.3.9.1