YGP::DirectorySearch Class Reference

Class to search for files in a certain (locally accesable) directory. More...

Inherits YGP::IDirectorySearch.

Inherited by YGP::PathDirectorySearch.

List of all members.

Public Member Functions

 DirectorySearch ()
 DirectorySearch (const std::string &search)
virtual ~DirectorySearch ()
virtual void setSearchValue (const std::string &search)
virtual std::string getDirectory () const
virtual std::string getFileSpec () const
virtual bool isValid () const
Searching
const Filefind (const std::string &search, unsigned long attribs=IDirectorySearch::FILE_NORMAL)
virtual const Filefind (unsigned long attribs=IDirectorySearch::FILE_NORMAL)
virtual const Filenext ()

Static Public Member Functions

static bool isValid (const std::string &dir)

Protected Types

enum  {
  DIRSRCH_OK = 0, NO_ENTRY, NO_DIR, NO_FILE,
  LAST
}

Protected Member Functions

virtual int checkIntegrity () const
void cleanup ()

Protected Attributes

std::string searchDir
std::string searchFile
unsigned long attr


Detailed Description

Class to search for files in a certain (locally accesable) directory.

This search can be restricted to files matching certain name-criterias or by attributes.

The name-part of the files to search supports UNIX-like wildcards; that are the asterisk (*) for any number of any characters, the question-mark for any single character and a set of characters in brackets (([) and (])). This set can contain a list of characters (like [abcde]) or a region (like [a-e]). To invert this set use a leading caret (^) or a leading exclamation mark (!), like ([^a-e]).

The found (and matching) files are retrieved by objects of type File.

Note:
The class does not do any word expansion for the search-path (like expanding the tilde (~) to the home-directory)!

Member Enumeration Documentation

anonymous enum [protected]

Status of object.

Enumerator:
DIRSRCH_OK  Object is in a valid state.
NO_ENTRY  Object is in a valid state, but has no entry found.
NO_DIR  No directory to search in specified.
NO_FILE  No file to search for specified.


Constructor & Destructor Documentation

YGP::DirectorySearch::DirectorySearch (  ) 

Defaultconstructor.

YGP::DirectorySearch::DirectorySearch ( const std::string &  search  ) 

Constructor; creates an object with the files to search.

The parameter may include path-information.

Parameters:
search Files (including the path) to search for.

YGP::DirectorySearch::~DirectorySearch (  )  [virtual]

Destructor.


Member Function Documentation

int YGP::DirectorySearch::checkIntegrity (  )  const [protected, virtual]

Checks if this object is integer.

If yes 0 is returned, else a number describing the error.

Returns:
int Status; 0: OK

void YGP::DirectorySearch::cleanup (  )  [protected]

Releases all internally used resources.

const File * YGP::DirectorySearch::find ( unsigned long  attribs = IDirectorySearch::FILE_NORMAL  )  [virtual]

Searches for previously specified files with the passed attributes.

Retrieves the first file matching the previously specified search-criteria.

Parameters:
attribs Attributes the searched files must have
Returns:
const File* Pointer to found file or NULL
Parameters:
attribs Attributes the file must contain
Returns:
const File* Pointer to found file-object or NULL
Precondition:
The search values must have been specified!

Implements YGP::IDirectorySearch.

Reimplemented in YGP::PathDirectorySearch.

const File* YGP::DirectorySearch::find ( const std::string &  search,
unsigned long  attribs = IDirectorySearch::FILE_NORMAL 
) [inline]

Searches for the specified files with the passed attributes.

Parameters:
search Files to search for
attribs Attributes the searched files must have
Returns:
const File* Pointer to found file or NULL

Reimplemented in YGP::PathDirectorySearch.

virtual std::string YGP::DirectorySearch::getDirectory (  )  const [inline, virtual]

Returns the directory part of the files to search for.

Implements YGP::IDirectorySearch.

virtual std::string YGP::DirectorySearch::getFileSpec (  )  const [inline, virtual]

Returns the file specification of the files to search for.

Implements YGP::IDirectorySearch.

bool YGP::DirectorySearch::isValid ( const std::string &  dir  )  [static]

Checks if the passed string specifies an existing directory.

Parameters:
dir Directory whose validity should be checked
Returns:
bool True if the directory exists

bool YGP::DirectorySearch::isValid (  )  const [virtual]

Checks if the directory-part of this object specifies an existing directory.

Returns:
bool True if the directory exists

Implements YGP::IDirectorySearch.

const File * YGP::DirectorySearch::next (  )  [virtual]

Method to find the next file matching the previously specified values.

Returns the next matching file according to parameters specified in earlier find-calls.

Returns:
const File* Pointer to found file or NULL
If a file was found 0 is returned, errno otherwise.
Returns:
const File* Pointer to found file-object or NULL
Precondition:
The search must have already been started by a find!

Implements YGP::IDirectorySearch.

Reimplemented in YGP::PathDirectorySearch.

void YGP::DirectorySearch::setSearchValue ( const std::string &  search  )  [virtual]

Sets the value for the next search.

Internally it splits the search-string in its directory- and filepart; it prepares the internal data also for a new search.

Parameters:
search Files to find

Implements YGP::IDirectorySearch.


Member Data Documentation

unsigned long YGP::DirectorySearch::attr [protected]

Attributes the found file must have set.

std::string YGP::DirectorySearch::searchDir [protected]

Holding the directory part of the search value.

std::string YGP::DirectorySearch::searchFile [protected]

Holding the file part of the search value.


The documentation for this class was generated from the following files:

YGP Version 0.9.31 - Generated on Wed Nov 18 11:25:27 2009 by doxygen 1.5.8