FileHunter Class Reference
[File and Directory Processing Utilities]

#include <FileHunter.hpp>

List of all members.


Detailed Description

FileHunter is a class designed to find files matching specified criteria.

The specified criteria is threefold: 1. The File Specification. This is a path and/or file description which is the most important search criteria. For instance, the specification for a Rinex Obs file might be: /archive/ADMS%3n/RINEXOBS/S%2n%t%3jA.2y0 where the '%#char' elements denote fields such as year, day, station number, and so on. In this example, FileHunter is smart enough to search all station directories (ADMS401, ADMS402, etc) but it won't search any directories (or subdirectories) other than ones that match the initial specification. 2. Start and end times. If you simply call find(), FileHunter will return all files that match the specification. You can specify DayTimes to only return files whose dates (according to the file name) fall between those times. Note that you can tell find() to return the list of files ascending, descending, or unsorted (unsorted will return them in disk order). 3. Filters. Filters can be used on any field that your file specification includes. The most appropriate use of this is to filter for a certain set of stations, but it will allow you to filter ANY field (day, year, etc) that is in the file specification.

For more information about file specifications, see the comments in the FileSpec class. Also check the file FileSpecTest in the test subdirectory below this one for examples.

Limitations: If a file specification has two or more of the same field defined, only the first one is used. This is only if they repeat in a single directory or path. For instance, this would be ok: /ADMS%3n/FILE%3n but in this case: /ADMS%3n/%3j%3j only the first 3j would be used for the day field. Also, wildcards cannot be used. Sorry - it's a limitation of how regular expressions are used. Finally, if you specify a version field, all files matching will be reurned. You can either use extractField() on the returned files to determine the latest version or select the version you want returned by using setFilter().

Definition at line 109 of file FileHunter.hpp.

Public Types

typedef std::pair< FileSpec::FileSpecType,
std::vector< std::string > > 
FilterPair
 Pairs of FileSpecTypes and lists of strings for filtering the search results.
enum  FileChunking { WEEK, DAY, HOUR, MINUTE }
 This describes how the files to be searched are chunked i.e. More...

Public Member Functions

 FileHunter (const std::string &filespec) throw (FileHunterException)
 Constructs a FileHunter using a file specification.
 FileHunter (const FileSpec &filespec) throw (FileHunterException)
 Constructs a FileHunter using a FileSpec.
FileHunternewHunt (const std::string &filespec) throw (FileHunterException)
 Rather than building a new file hunter, this lets you change the filespec you're searching for.
FileHunternewHunt (const FileSpec &filespec) throw (FileHunterException)
 Changes the file spec you're searching for in FileHunter.
FileHuntersetFilter (const FileSpec::FileSpecType fst, const std::vector< std::string > &filter) throw (FileHunterException)
 Filters FOR the strings in /a filter in the field specified by /a fst when searching.
std::vector< std::string > find (const gpstk::DayTime &start=gpstk::DayTime::BEGINNING_OF_TIME, const gpstk::DayTime &end=gpstk::DayTime::END_OF_TIME, const FileSpec::FileSpecSortType fsst=FileSpec::ascending, enum FileChunking chunk=DAY) const throw (FileHunterException)
 Does the searching for the files.
void dump (std::ostream &o) const
 outputs the file spec into a semi-readable format

Protected Member Functions

void init (const std::string &filespec) throw (FileHunterException)
 Shared code between the constructor and newHunt.
std::vector< std::string > searchHelper (const std::string &directory, const FileSpec &fs) const throw (FileHunterException)
 Performs a search for the given file spec on the given directory.
void filterHelper (std::vector< std::string > &fileList, const FileSpec &fs) const throw (FileHunterException)
 If there is a filter set, this will find the filtered items and set fileList to contain only those.

Protected Attributes

std::vector< FileSpecfileSpecList
 Holds the broken down list of the file specification for searching.
std::vector< FilterPairfilterList
 Stores the list of things to filter for.


Member Typedef Documentation

typedef std::pair<FileSpec::FileSpecType, std::vector<std::string> > FilterPair
 

Pairs of FileSpecTypes and lists of strings for filtering the search results.

Definition at line 126 of file FileHunter.hpp.


Member Enumeration Documentation

enum FileChunking
 

This describes how the files to be searched are chunked i.e.

a DAY chunking means one file is written per day

Enumeration values:
WEEK 
DAY 
HOUR 
MINUTE 

Definition at line 115 of file FileHunter.hpp.


Constructor & Destructor Documentation

FileHunter const std::string &  filespec  )  throw (FileHunterException)
 

Constructs a FileHunter using a file specification.

This can be a full or relative path and/or a file specification. See FileSpec for details on how to format a file specification.

Exceptions:
FileHunterException when there's a problem with the filespec

Definition at line 69 of file FileHunter.cpp.

References GPSTK_RETHROW.

FileHunter const FileSpec filespec  )  throw (FileHunterException)
 

Constructs a FileHunter using a FileSpec.

Exceptions:
FileHunterException when there's a problem with the filespec

Definition at line 82 of file FileHunter.cpp.

References GPSTK_RETHROW.


Member Function Documentation

void dump std::ostream &  o  )  const
 

outputs the file spec into a semi-readable format

Definition at line 687 of file FileHunter.cpp.

References Exception::dump(), and FileHunter::fileSpecList.

Referenced by main().

void filterHelper std::vector< std::string > &  fileList,
const FileSpec fs
const throw (FileHunterException) [protected]
 

If there is a filter set, this will find the filtered items and set fileList to contain only those.

Definition at line 636 of file FileHunter.cpp.

References gpstk::StringUtils::rightJustify().

vector< string > find const gpstk::DayTime start = gpstk::DayTime::BEGINNING_OF_TIME,
const gpstk::DayTime end = gpstk::DayTime::END_OF_TIME,
const FileSpec::FileSpecSortType  fsst = FileSpec::ascending,
enum FileChunking  chunk = DAY
const throw (FileHunterException)
 

Does the searching for the files.

Set /a start and /a end for specifying times of files (according to their file names) for returning.

Warning:
This method is NOT MT-Safe.
Parameters:
start the start time to limit the search
end the end time to limit the search
fsst set to change the order the list is returned
chunk the type of file chunking to use to select files
Returns:
a list of files matching the file specification, start and end times, and filters ordered according to fsst. This list can be empty if no files are found.
Exceptions:
FileHunterException when there's a problem searching.

Definition at line 136 of file FileHunter.cpp.

References GPSTK_THROW, and slash.

Referenced by FileFilterFrame::init(), and main().

void init const std::string &  filespec  )  throw (FileHunterException) [protected]
 

Shared code between the constructor and newHunt.

Definition at line 336 of file FileHunter.cpp.

References Exception::addText(), GPSTK_RETHROW, GPSTK_THROW, and slash.

FileHunter& newHunt const FileSpec filespec  )  throw (FileHunterException) [inline]
 

Changes the file spec you're searching for in FileHunter.

Exceptions:
FileHunterException when there's an error in the filespec

Definition at line 156 of file FileHunter.hpp.

FileHunter & newHunt const std::string &  filespec  )  throw (FileHunterException)
 

Rather than building a new file hunter, this lets you change the filespec you're searching for.

Exceptions:
FileHunterException when there's a problem with the filespec

Definition at line 95 of file FileHunter.cpp.

References GPSTK_RETHROW.

Referenced by main().

vector< string > searchHelper const std::string &  directory,
const FileSpec fs
const throw (FileHunterException) [protected]
 

Performs a search for the given file spec on the given directory.

Warning:
This method is NOT MT-Safe.
Returns:
a list of matching directories/files

Definition at line 523 of file FileHunter.cpp.

References Exception::addText(), GPSTK_THROW, gpstk::StringUtils::isLike(), and slash.

FileHunter & setFilter const FileSpec::FileSpecType  fst,
const std::vector< std::string > &  filter
throw (FileHunterException)
 

Filters FOR the strings in /a filter in the field specified by /a fst when searching.

Parameters:
fst A FileSpecType you want to run a filter on.
filter a list of strings to search for.in the filter.
Exceptions:
FileHunterException when /a fst can't be found.

Definition at line 109 of file FileHunter.cpp.

Referenced by FileFilterFrame::init(), and main().


Member Data Documentation

std::vector<FileSpec> fileSpecList [protected]
 

Holds the broken down list of the file specification for searching.

Definition at line 221 of file FileHunter.hpp.

Referenced by FileHunter::dump().

std::vector<FilterPair> filterList [protected]
 

Stores the list of things to filter for.

Definition at line 224 of file FileHunter.hpp.


The documentation for this class was generated from the following files:
Generated on Thu Feb 9 03:31:36 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1