| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# DirSearchPath Class Reference

`#include <DirSearchPath.h>`

List of all members.

## Detailed Description

search for files in a list of directories

Author:
  Paolo Calafiura <pcalafiura@lbl.gov> - ATLAS Collaboration
  Id
    DirSearchPath.h,v 1.2 2007/10/16 15:37:25 marcocle Exp

Definition at line 18 of file DirSearchPath.h.

## Public Types
typedef boost::filesystem::path | path
## Public Member Functions
modifiers
bool | add (const path &dir)
  | Exceptions:
  | filesystem_error |
bool | addCWD ()
| add current work dir (*nix pwd) to path
accessors
bool | find (const std::string &fileName, std::string &fullFileName) const
| returns a flag if fileName found in search path, and sets ref to fully qualified file name (in native form)
bool | find (const path &file, path &fileFound) const
| returns a flag if file found in search path. Sets ref to completed path
std::list< path > | find_all (const path &file) const
| returns lists of files found in search path.
## Static Public Member Functions
helpers
static bool | existsDir (const std::string &dirName)
| check dirName is valid
static bool | existsDir (const path &dir)
| check dir path is valid
## Private Attributes
std::list< path > | m_dirs
| the dir container
## Classes
class | eqPath
| name More...

## Member Typedef Documentation

typedef boost::filesystem::path DirSearchPath::path

Definition at line 20 of file DirSearchPath.h.

## Constructor & Destructor Documentation

DirSearchPath::DirSearchPath | ( |  | ) | `[inline]`

Definition at line 24 of file DirSearchPath.h.

References addCWD().

    00024 { addCWD(); }

DirSearchPath::DirSearchPath | ( | const std::string & | stringifiedPath,
|  | const char * | separator = `",:"` |
| ) |  |  |

Exceptions:

  | boost::filesystem::filesystem_error |

Definition at line 20 of file DirSearchPath.cpp.

References add(), and addCWD().

    00020                                                                                     {
    00021   addCWD(); //FIXME is this a good idea?
    00022
    00023   typedef  tokenizer<char_separator<char> > Tokenizer;
    00024
    00025   Tokenizer tok(stringifiedPath, char_separator<char>(separator));
    00026
    00027
    00028   //add names to dir container, filtering dir names to remove invalid ones
    00029   //notice how we iterate over all tokens even if there is an illegal one
    00030   Tokenizer::iterator it = tok.begin();
    00031   while(it != tok.end()) {
    00032     try {
    00033       //path p( *(it++), boost::filesystem::native);
    00034       // For some reason native() does not work with boost 1.31. Changed to no_check and cross the fingers....
    00035       path p( *(it++), boost::filesystem::no_check);
    00036       add(p);
    00037     }
    00038     catch (boost::filesystem::filesystem_error /*err*/) {
    00039     }
    00040   }
    00041 }

DirSearchPath::DirSearchPath | ( |  | ) | `[inline]`

Definition at line 24 of file DirSearchPath.h.

References addCWD().

    00024 { addCWD(); }

DirSearchPath::DirSearchPath | ( | const std::string & | stringifiedPath,
|  | const char * | separator = `",:"` |
| ) |  |  |

Exceptions:

  | boost::filesystem::filesystem_error |

Definition at line 20 of file DirSearchPath.cpp.

References add(), and addCWD().

    00020                                                                                     {
    00021   addCWD(); //FIXME is this a good idea?
    00022
    00023   typedef  tokenizer<char_separator<char> > Tokenizer;
    00024
    00025   Tokenizer tok(stringifiedPath, char_separator<char>(separator));
    00026
    00027
    00028   //add names to dir container, filtering dir names to remove invalid ones
    00029   //notice how we iterate over all tokens even if there is an illegal one
    00030   Tokenizer::iterator it = tok.begin();
    00031   while(it != tok.end()) {
    00032     try {
    00033       //path p( *(it++), boost::filesystem::native);
    00034       // For some reason native() does not work with boost 1.31. Changed to no_check and cross the fingers....
    00035       path p( *(it++), boost::filesystem::no_check);
    00036       add(p);
    00037     }
    00038     catch (boost::filesystem::filesystem_error /*err*/) {
    00039     }
    00040   }
    00041 }

## Member Function Documentation

bool DirSearchPath::add | ( | const path & | dir | ) |

Exceptions:

  | filesystem_error |

Definition at line 62 of file DirSearchPath.cpp.

References existsDir(), std::find_if(), and m_dirs.

Referenced by addCWD(), and DirSearchPath().

    00062                                        {
    00063   bool dirExist(existsDir(dir));
    00064   //add dir to path even if dir does not (yet) exist,
    00065   // but don't add twice same dir
    00066   if (m_dirs.end() == std::find_if(m_dirs.begin(), m_dirs.end(), eqPath(dir)))
    00067     m_dirs.push_back(dir);
    00068   return dirExist;
    00069 }

bool DirSearchPath::addCWD | ( |  | ) |

add current work dir (*nix pwd) to path

Definition at line 58 of file DirSearchPath.cpp.

References add().

Referenced by DirSearchPath().

    00058                            {
    00059   return add(boost::filesystem::current_path());
    00060 }

bool DirSearchPath::find | ( | const std::string & | fileName,
|  | std::string & | fullFileName |
| ) |  |  | const

returns a flag if fileName found in search path, and sets ref to fully qualified file name (in native form)

bool DirSearchPath::find | ( | const path & | file,
|  | path & | fileFound |
| ) |  |  | const

returns a flag if file found in search path. Sets ref to completed path

Definition at line 83 of file DirSearchPath.cpp.

References m_dirs.

    00083                                                                 {
    00084   bool rc(false);
    00085   for (std::list<path>::const_iterator iDir=m_dirs.begin(); iDir!=m_dirs.end(); ++iDir) {
    00086     path full(*iDir / file);
    00087     if (exists(full)) {
    00088       fileFound = full;
    00089       rc = true;
    00090       break;
    00091     }
    00092   }
    00093   return rc;
    00094 }

std::list< DirSearchPath::path > DirSearchPath::find_all | ( | const path & | file | ) | const

returns lists of files found in search path.

Definition at line 98 of file DirSearchPath.cpp.

References m_dirs, and std::list< _Tp, _Alloc >::push_back().

    00098                                               {
    00099   std::list<path> found;
    00100   for (std::list<path>::const_iterator iDir=m_dirs.begin(); iDir!=m_dirs.end(); ++iDir) {
    00101     path full(*iDir / file);
    00102     if (exists(full)) {
    00103       found.push_back(full);
    00104     }
    00105   }
    00106   return found;
    00107 }

bool DirSearchPath::existsDir | ( | const std::string & | dirName | ) | `[static]`

check dirName is valid

Definition at line 110 of file DirSearchPath.cpp.

Referenced by add().

    00110                                                       {
    00111   bool rc(false);
    00112   try {
    00113     rc=is_directory(path(dirName));
    00114   } catch(...) {}
    00115   return rc;
    00116 }

bool DirSearchPath::existsDir | ( | const path & | dir | ) | `[static]`

check dir path is valid

Definition at line 117 of file DirSearchPath.cpp.

    00117                                              {
    00118   return (exists(dir) && is_directory(dir));
    00119 }

## Member Data Documentation

std::list<path> DirSearchPath::m_dirs`[private]`

the dir container

Definition at line 80 of file DirSearchPath.h.

Referenced by add(), find(), and find_all().

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/GaudiKernel/v25r2/GaudiKernel/DirSearchPath.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/GaudiKernel/v25r2/src/Lib/DirSearchPath.cpp