FICHeader.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: FICHeader.cpp 70 2006-08-01 18:36:21Z ehagen $"
00002 
00003 
00004 
00010 //============================================================================
00011 //
00012 //  This file is part of GPSTk, the GPS Toolkit.
00013 //
00014 //  The GPSTk is free software; you can redistribute it and/or modify
00015 //  it under the terms of the GNU Lesser General Public License as published
00016 //  by the Free Software Foundation; either version 2.1 of the License, or
00017 //  any later version.
00018 //
00019 //  The GPSTk is distributed in the hope that it will be useful,
00020 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 //  GNU Lesser General Public License for more details.
00023 //
00024 //  You should have received a copy of the GNU Lesser General Public
00025 //  License along with GPSTk; if not, write to the Free Software Foundation,
00026 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027 //  
00028 //  Copyright 2004, The University of Texas at Austin
00029 //
00030 //============================================================================
00031 
00032 //============================================================================
00033 //
00034 //This software developed by Applied Research Laboratories at the University of
00035 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00036 //Department of Defense. The U.S. Government retains all rights to use,
00037 //duplicate, distribute, disclose, or release this software. 
00038 //
00039 //Pursuant to DoD Directive 523024 
00040 //
00041 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00042 //                           release, distribution is unlimited.
00043 //
00044 //=============================================================================
00045 
00046 
00047 
00048 
00049 
00050 
00051 #include "StringUtils.hpp"
00052 #include "FICHeader.hpp"
00053 #include "FICStream.hpp"
00054 #include "FICAStream.hpp"
00055 
00056 using namespace gpstk::StringUtils;
00057 
00058 const int gpstk::FICHeader::headerSize = 40;
00059 
00060 
00061 namespace gpstk
00062 {
00063    using namespace std;
00064 
00065    
00066    void FICHeader::reallyPutRecord(FFStream& ffs) const 
00067       throw(std::exception, gpstk::StringUtils::StringException, 
00068             gpstk::FFStreamError)
00069    {
00070       string theHeader(header);
00071       if(FICStream* strm = dynamic_cast<FICStream*>(&ffs))
00072       {
00073             // This is a binary FIC stream, so
00074             // send the 40 character header, truncated or padded 
00075             //  with ' ' as needed.
00076          *strm << leftJustify(theHeader, headerSize, ' ');
00077       }
00078       else if (FICAStream* ficas = dynamic_cast<FICAStream*>(&ffs))
00079       {
00080             // If this is a FICA stream, add some extra stuff as well as
00081             // send the 40 character header, truncated or padded 
00082             //  with ' ' as needed.
00083          *ficas << "    " << leftJustify(theHeader, headerSize, ' ') << '\n';
00084       }
00085       else
00086       {
00087          gpstk::FFStreamError e("Attempt to write a FICHeader object"
00088                                 " to a non-FIC(A)Stream FFStream.");
00089          GPSTK_THROW(e);
00090       }
00091    }
00092 
00093    void FICHeader::dump(ostream& s) const 
00094    {
00095       s << header << endl;
00096    };
00097 
00098    void FICHeader::reallyGetRecord(FFStream& ffs)
00099       throw(std::exception, gpstk::StringUtils::StringException, 
00100             gpstk::FFStreamError)
00101    {
00102       FICStreamBase *fsb = dynamic_cast<FICStreamBase *>(&ffs);
00103       if(fsb == NULL)
00104       {
00105          gpstk::FFStreamError e("Attempt to read a FICHeader object"
00106                                 " from a non-FICStreamBase FFStream.");
00107          GPSTK_THROW(e);
00108       }
00109 
00110       char c[headerSize + 1];
00111       
00112          // if this is a FICA stream, get 4 characters
00113       FICAStream* ficas = dynamic_cast<FICAStream*>(&ffs);
00114       
00115       if (ficas)
00116       {
00117          const int blankChrs = 4;
00118          char whitespaces[blankChrs + 1];
00119          ffs.read(whitespaces, blankChrs);
00120       }
00121       
00122       ffs.read(c, headerSize);
00123       if (ffs.gcount() != headerSize)
00124       {
00125          FFStreamError e("Error reading header");
00126          GPSTK_THROW(e);
00127       }
00128       
00129       c[headerSize]='\0';
00130       header = c;
00131       fsb->headerRead=true;
00132       fsb->header.header = header;
00133       
00134       if (ficas)
00135       {
00136          string line;
00137          ficas->formattedGetLine(line);
00138          ficas->formattedGetLine(line);
00139       }
00140    }  // end of FICHeader::getRecord()
00141 
00142 } // namespace gpstk

Generated on Wed Sep 8 03:30:53 2010 for GPS ToolKit Software Library by  doxygen 1.3.9.1