00001 #pragma ident "$Id: FileSpec.hpp 930 2007-11-27 16:57:42Z snelsen $"
00002
00003
00004
00010 #ifndef GPSTK_FILESPEC_HPP
00011 #define GPSTK_FILESPEC_HPP
00012
00013 #include <vector>
00014 #include <functional>
00015 #include <map>
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
00052
00053
00054
00055
00056
00057
00058 #include "DayTime.hpp"
00059
00060 #ifdef _WIN32
00061 const char slash = '\\';
00062 #else
00063 const char slash = '/';
00064 #endif
00065
00066 namespace gpstk
00067 {
00070
00074 NEW_EXCEPTION_CLASS(FileSpecException, gpstk::Exception);
00075
00086 class FileSpec
00087 {
00088 public:
00099 enum FileSpecType
00100 {
00101 unknown,
00102 station,
00103 receiver,
00104 prn,
00105 selected,
00106 sequence,
00107 version,
00108
00109 fixed,
00110 clock,
00111 text,
00112
00113
00114
00115 year,
00116 month,
00117 dayofmonth,
00118 hour,
00119 minute,
00120 second,
00121 fsecond,
00122 gpsweek,
00123 fullgpsweek,
00124 gpssecond,
00125 mjd,
00126 dayofweek,
00127 day,
00128 doysecond,
00129 zcount,
00130 zcountfloor,
00131 unixsec,
00132 unixusec,
00133 fullzcount,
00134
00135 end
00136 };
00137
00140 typedef std::map<FileSpecType, std::string> FSTStringMap;
00141
00142
00145 enum FileSpecSortType
00146 {
00147 none,
00148 ascending,
00149 descending
00150 };
00151
00153 FileSpec() {}
00154
00156 FileSpec(const std::string& fileSpec)
00157 throw(FileSpecException)
00158 {init(fileSpec);}
00159
00161 virtual ~FileSpec() {}
00162
00164 virtual FileSpec& newSpec(const std::string& fileSpec)
00165 throw(FileSpecException)
00166 {init(fileSpec); return *this;}
00167
00169 virtual std::string getSpecString(void) const
00170 {return fileSpecString;}
00171
00178 virtual std::string createSearchString() const
00179 throw(FileSpecException);
00180
00189 virtual std::string extractField(const std::string& filename,
00190 const FileSpecType) const
00191 throw(FileSpecException);
00192
00197 virtual bool hasField(const FileSpecType) const
00198 throw(FileSpecException);
00199
00206 virtual gpstk::DayTime extractDayTime(const std::string& filename) const
00207 throw(FileSpecException);
00208
00221 virtual std::string toString(const gpstk::DayTime& dt,
00222 const FSTStringMap& fstsMap = FSTStringMap())
00223 const;
00224
00235 virtual void sortList(std::vector<std::string>& fileList,
00236 const FileSpecSortType fsst = ascending) const
00237 throw(FileSpecException);
00238
00240 virtual void dump(std::ostream& o) const;
00241
00242 protected:
00244 virtual void init(const std::string& fileSpec)
00245 throw(FileSpecException);
00246
00247 public:
00253 static std::string convertFileSpecType(const FileSpecType)
00254 throw(FileSpecException);
00255
00261 static FileSpecType convertFileSpecType(const std::string&)
00262 throw(FileSpecException);
00263
00264 protected:
00267 class FileSpecElement
00268 {
00269 public:
00271 FileSpecElement(const std::string::size_type numChars = 0,
00272 const std::string::size_type offs = 0,
00273 const FileSpecType fst = unknown,
00274 const std::string& fld = std::string())
00275 : numCh(numChars), offset(offs), type(fst), field(fld)
00276 {};
00277
00279 std::string::size_type numCh;
00281 std::string::size_type offset;
00283 FileSpecType type;
00287 std::string field;
00288 };
00289
00292 struct FileSpecSort :
00293 public std::binary_function<std::string,std::string,bool>
00294 {
00295 public:
00296 FileSpecSort(std::string::size_type o, std::string::size_type l,
00297 const FileSpecSortType s)
00298 : offset(o), length(l), sortBy(s) {}
00302 bool operator() (const std::string& l, const std::string& r) const;
00303 private:
00305 std::string::size_type offset;
00307 std::string::size_type length;
00309 FileSpecSortType sortBy;
00310 };
00311
00313 std::vector<FileSpecElement> fileSpecList;
00315 std::string fileSpecString;
00316
00317
00318 };
00319
00321 FileSpec::FileSpecType& operator-- (FileSpec::FileSpecType& fst, int);
00323 FileSpec::FileSpecType& operator++ (FileSpec::FileSpecType& fst, int);
00324
00326
00327 }
00328
00329 #endif