FFBinaryStream.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: FFBinaryStream.hpp 3140 2012-06-18 15:03:02Z susancummins $"
00002 
00003 
00004 
00010 #ifndef GPSTK_FFBINARYSTREAM_HPP
00011 #define GPSTK_FFBINARYSTREAM_HPP
00012 
00013 //============================================================================
00014 //
00015 //  This file is part of GPSTk, the GPS Toolkit.
00016 //
00017 //  The GPSTk is free software; you can redistribute it and/or modify
00018 //  it under the terms of the GNU Lesser General Public License as published
00019 //  by the Free Software Foundation; either version 2.1 of the License, or
00020 //  any later version.
00021 //
00022 //  The GPSTk is distributed in the hope that it will be useful,
00023 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025 //  GNU Lesser General Public License for more details.
00026 //
00027 //  You should have received a copy of the GNU Lesser General Public
00028 //  License along with GPSTk; if not, write to the Free Software Foundation,
00029 //  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
00030 //  
00031 //  Copyright 2004, The University of Texas at Austin
00032 //
00033 //============================================================================
00034 
00035 //============================================================================
00036 //
00037 //This software developed by Applied Research Laboratories at the University of
00038 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00039 //Department of Defense. The U.S. Government retains all rights to use,
00040 //duplicate, distribute, disclose, or release this software. 
00041 //
00042 //Pursuant to DoD Directive 523024 
00043 //
00044 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00045 //                           release, distribution is unlimited.
00046 //
00047 //=============================================================================
00048 
00049 
00050 
00051 
00052 
00053 
00054 #include "FFStream.hpp"
00055 
00056 namespace gpstk
00057 {
00060  
00066    class FFBinaryStream : public FFStream
00067    {
00068    public:
00070       virtual ~FFBinaryStream() {};
00071       
00073       FFBinaryStream() {}
00074 
00080       FFBinaryStream(const char* fn, 
00081                      std::ios::openmode mode=std::ios::in|std::ios::binary)
00082          : FFStream(fn, mode|std::ios::binary) {}
00083 
00085       virtual void open(const char* fn, std::ios::openmode mode)
00086          { FFStream::open(fn, mode|std::ios::binary); }
00087 
00095       template <class T> T getData() throw(FFStreamError, EndOfFile)
00096       {
00097          T data;
00098          getData((char*)&data, sizeof(T));
00099          return data;
00100       } // end of getData(FFStream& strm)
00101 
00102       void getData(char* buff, size_t length) throw(FFStreamError, EndOfFile)
00103       {
00104          try
00105          {
00106             read(buff, length);
00107          }
00108          catch(std::exception& exc)
00109          {
00110             if (gcount() != length && eof())
00111             {
00112                EndOfFile err("EOF encountered");
00113                GPSTK_THROW(err);
00114             }
00115             else
00116             {
00117                FFStreamError err(exc.what());
00118                std::cout << err << std::endl;
00119                GPSTK_THROW(err);
00120             }
00121          }
00122          catch(...)
00123          {
00124             FFStreamError err("Unknown exception");
00125             GPSTK_THROW(err);
00126          }
00127       } // end of getData(char*, size_t))
00128 
00137       template <class T> void writeData(const T& data)
00138          throw(FFStreamError)
00139       {
00140          T temp = data;
00141          writeData((char*)&data, sizeof(T));
00142          return;
00143       } // end of writeData(FFStream& strm, const T& data)
00144 
00145       void writeData(const char* buff, size_t length)
00146          throw(FFStreamError)
00147       {
00148          try
00149          {
00150             write(buff, length);
00151          }
00152          catch(std::exception& exc)
00153          {
00154             FFStreamError err(exc.what());
00155             GPSTK_THROW(err);
00156          }
00157          catch(...)
00158          {
00159             FFStreamError err("Unknown exception");
00160             GPSTK_THROW(err);
00161          }
00162       
00163          if (fail() || bad())
00164          {
00165             FFStreamError err("Error writing data");
00166             GPSTK_THROW(err);
00167          }
00168          return;
00169       } // end of writeData(const char*, size_t)
00170 
00171    };
00173 }
00174 #endif

Generated on Fri May 24 03:31:06 2013 for GPS ToolKit Software Library by  doxygen 1.3.9.1