00001 #pragma ident "$Id: FICHeader.cpp 70 2006-08-01 18:36:21Z ehagen $"
00002
00003
00004
00010
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
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
00074
00075
00076 *strm << leftJustify(theHeader, headerSize, ' ');
00077 }
00078 else if (FICAStream* ficas = dynamic_cast<FICAStream*>(&ffs))
00079 {
00080
00081
00082
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
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 }
00141
00142 }