FileSpec.hpp

Go to the documentation of this file.
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 //  This file is part of GPSTk, the GPS Toolkit.
00020 //
00021 //  The GPSTk is free software; you can redistribute it and/or modify
00022 //  it under the terms of the GNU Lesser General Public License as published
00023 //  by the Free Software Foundation; either version 2.1 of the License, or
00024 //  any later version.
00025 //
00026 //  The GPSTk is distributed in the hope that it will be useful,
00027 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00028 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00029 //  GNU Lesser General Public License for more details.
00030 //
00031 //  You should have received a copy of the GNU Lesser General Public
00032 //  License along with GPSTk; if not, write to the Free Software Foundation,
00033 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00034 //  
00035 //  Copyright 2004, The University of Texas at Austin
00036 //
00037 //============================================================================
00038 
00039 //============================================================================
00040 //
00041 //This software developed by Applied Research Laboratories at the University of
00042 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00043 //Department of Defense. The U.S. Government retains all rights to use,
00044 //duplicate, distribute, disclose, or release this software. 
00045 //
00046 //Pursuant to DoD Directive 523024 
00047 //
00048 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00049 //                           release, distribution is unlimited.
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             // see DayTime for more information on the following elements
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    }; // class FileSpec
00319 
00321    FileSpec::FileSpecType& operator-- (FileSpec::FileSpecType& fst, int);
00323    FileSpec::FileSpecType& operator++ (FileSpec::FileSpecType& fst, int);
00324 
00326 
00327 } // namespace gpstk
00328 
00329 #endif 

Generated on Tue May 22 03:30:58 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1