59 return fst = (fst == FileSpec::unknown) ?
66 return fst = (fst == FileSpec::end) ?
71 bool FileSpec::FileSpecSort::operator() (
const std::string& l,
79 if (fileSpec.hasField(fst))
81 for (
unsigned i = 0; i < fileSpec.fileSpecList.size(); i++)
83 std::string::size_type offset = fileSpec.fileSpecList[i].offset;
84 std::string::size_type numCh = fileSpec.fileSpecList[i].numCh;
85 if (fileSpec.fileSpecList[i].type == fst)
87 std::string lsub(l.substr(offset, numCh));
88 std::string rsub(r.substr(offset, numCh));
89 if (((sortDir == ascending) && (lsub < rsub)) ||
90 ((sortDir == descending) && (lsub > rsub)))
108 if (fst == station)
return string(
"n");
109 else if (fst == receiver)
return string(
"r");
110 else if (fst == prn)
return string(
"p");
111 else if (fst == selected)
return string(
"t");
112 else if (fst == sequence)
return string(
"I");
113 else if (fst ==
version)
return string(
"v");
114 else if (fst == fixed)
return string(
"");
115 else if (fst == clock)
return string(
"k");
116 else if (fst == text)
return string(
"x");
118 else if (fst ==
year)
return string(
"y");
119 else if (fst ==
month)
return string(
"m");
120 else if (fst == dayofmonth)
return string(
"d");
121 else if (fst ==
hour)
return string(
"H");
122 else if (fst ==
minute)
return string(
"M");
123 else if (fst ==
second)
return string(
"S");
124 else if (fst == fsecond)
return string(
"f");
125 else if (fst == gpsweek)
return string(
"G");
126 else if (fst == fullgpsweek)
return string(
"F");
127 else if (fst == gpssecond)
return string(
"g");
128 else if (fst ==
mjd)
return string(
"Q");
129 else if (fst == dayofweek)
return string(
"w");
130 else if (fst ==
day)
return string(
"j");
131 else if (fst == doysecond)
return string(
"s");
132 else if (fst == zcount)
return string(
"Z");
133 else if (fst == zcountfloor)
return string(
"z");
134 else if (fst == unixsec)
return string(
"U");
135 else if (fst == unixusec)
return string(
"u");
136 else if (fst == fullzcount)
return string(
"C");
139 FileSpecException fse(
"Unknown FileSpecType: " +
asString(fst));
146 if (fst ==
string(
"n"))
return station;
147 else if (fst ==
string(
"r"))
return receiver;
148 else if (fst ==
string(
"p"))
return prn;
149 else if (fst ==
string(
"t"))
return selected;
150 else if (fst ==
string(
"I"))
return sequence;
151 else if (fst ==
string(
"v"))
return version;
152 else if (fst ==
string(
"k"))
return clock;
153 else if (fst ==
string(
"x"))
return text;
155 else if (fst ==
string(
"Y") ||
156 fst ==
string(
"y"))
return year;
157 else if (fst ==
string(
"m"))
return month;
158 else if (fst ==
string(
"d"))
return dayofmonth;
159 else if (fst ==
string(
"H"))
return hour;
160 else if (fst ==
string(
"M"))
return minute;
161 else if (fst ==
string(
"S"))
return second;
162 else if (fst ==
string(
"f"))
return fsecond;
163 else if (fst ==
string(
"G"))
return gpsweek;
164 else if (fst ==
string(
"F"))
return fullgpsweek;
165 else if (fst ==
string(
"g"))
return gpssecond;
166 else if (fst ==
string(
"Q"))
return mjd;
167 else if (fst ==
string(
"w"))
return dayofweek;
168 else if (fst ==
string(
"j"))
return day;
169 else if (fst ==
string(
"s"))
return doysecond;
170 else if (fst ==
string(
"Z"))
return zcount;
171 else if (fst ==
string(
"z"))
return zcountfloor;
172 else if (fst ==
string(
"U"))
return unixsec;
173 else if (fst ==
string(
"u"))
return unixusec;
174 else if (fst ==
string(
"C") ||
175 fst ==
string(
"c"))
return fullzcount;
178 FileSpecException fse(
"Unknown FileSpecType: " + fst);
184 string FileSpec::createSearchString()
const
189 vector<FileSpecElement>::const_iterator itr = fileSpecList.begin();
190 while (itr != fileSpecList.end())
193 if ( ((*itr).type <= unknown) || ((*itr).type >= end) )
195 FileSpecException fse(
"Unknown FileSpecType: " +
200 else if ((*itr).type == fixed)
202 searchString += (*itr).field;
207 searchString += string((*itr).numCh,
'?');
216 string FileSpec::extractField(
const string& filename,
220 if ((fst <= unknown) || (fst >= end))
222 FileSpecException fse(
"Unknown FileSpecType: " +
223 convertFileSpecType(fst));
228 vector<FileSpecElement>::const_iterator itr = fileSpecList.begin();
229 while (itr != fileSpecList.end())
232 if ((*itr).type == fst)
234 return filename.substr((*itr).offset, (*itr).numCh);
241 FileSpecException fse(
"Couldn't find specified FileSpecType: " +
242 convertFileSpecType(fst));
247 CommonTime FileSpec::extractCommonTime(
const string& filename)
const
259 FileSpecException fse(exc);
260 fse.addText(
"Can't generate a CommonTime for this FileSpec");
263 catch(std::exception& exc)
265 FileSpecException fse(
"std::exception: " +
string(exc.what()));
266 fse.addText(
"Can't generate a CommonTime for this FileSpec");
271 FileSpecException fse(
"unknown exception");
272 fse.addText(
"Can't generate a CommonTime for this FileSpec");
288 vector<FileSpecElement>::const_iterator fslItr = fileSpecList.begin();
289 while (fslItr != fileSpecList.end())
291 FSTStringMap::const_iterator fstsItr = fstsMap.find((*fslItr).type);
294 if (fstsItr != fstsMap.end())
296 if ((*fstsItr).first == text)
305 if ((*fslItr).numCh == 0)
308 toReturn += (*fstsItr).second;
325 toReturn += (*fslItr).field;
336 void FileSpec::sortList(vector<string>& fileList,
340 stable_sort(fileList.begin(), fileList.end(), q);
359 vector<string> copyOfFileList = fileList;
362 vector<FileSpecElement>::const_iterator itr = fileSpecList.begin();
363 vector<FileSpecElement> versionVec;
364 while (itr != fileSpecList.end())
367 versionVec.push_back(*itr);
372 vector<string>::size_type index;
373 for (index = 0; index < copyOfFileList.size(); index++)
375 string::size_type slashpos = copyOfFileList[index].rfind(
slash);
376 if (slashpos != string::npos)
377 copyOfFileList[index].erase(0, slashpos + 1);
378 copyOfFileList[index].erase(versionVec[0].offset,
379 versionVec[0].numCh);
388 map<string, string> versionMap;
389 for (index = 0; index < copyOfFileList.size(); index++)
390 versionMap[copyOfFileList[index]] = fileList[index];
392 fileList.erase(fileList.begin(), fileList.end());
393 map<string, string>::iterator mapitr = versionMap.begin();
394 while (mapitr != versionMap.end())
396 fileList.push_back((*mapitr).second);
404 o <<
"FileSpec string: " << fileSpecString << endl;
406 o <<
"offset numch type field" << endl;
407 vector<FileSpecElement>::const_iterator itr = fileSpecList.begin();
408 while (itr != fileSpecList.end())
410 o << setw(6) << (*itr).offset << setw(6) << (*itr).numCh
411 << setw(6) << convertFileSpecType((*itr).type)
414 << setw(6 + ((*itr).field.size() > 5 ? ((*itr).field.size()-5): 0))
415 << (*itr).field << endl;
420 void FileSpec::init(
const string& fileSpec)
424 fileSpecList.clear();
425 fileSpecString.clear();
427 fileSpecString = fileSpec;
431 string::size_type offset = 0;
443 string::size_type
pos = fs.find(
'%');
444 atom = fs.substr(0,
pos);
455 fileSpecList.push_back(fse);
465 fileSpecList.push_back(fse);
466 offset += atom.size();
467 atom.erase(atom.begin(), atom.end());
478 int rawNumChs =
asInt(fs);
479 int numChs = (rawNumChs == 0) ? 1 : rawNumChs;
491 if ((fs.substr(0,1) ==
string(
"x")) && (rawNumChs == 0))
495 if ((fs.substr(0,1) ==
string(
"Y")) && (numChs < 4))
505 fileSpecList.push_back(fse);
506 fileSpecSet.insert(fst);
512 catch(FileSpecException& e)
514 e.addText(
"Check your file spec for errors: " + fileSpec);
517 catch(StringException& e)
519 FileSpecException fse(e);
520 fse.addText(
"String exception: Check the file spec for errors: " + fileSpec);
523 catch(std::exception& e)
525 FileSpecException fse(
"std::exception: " +
string(e.what()));
526 fse.addText(
"Check the file spec for errors: " + fileSpec);
531 FileSpecException fse(
"Unknown exception: Check the file spec for errors: " + fileSpec);