| The Gaudi Framework v29r0 (ff2e7097)

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

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | Public Types | Private Attributes | List of all members
DirSearchPath Class Reference

search for files in a list of directories More...

`#include <GaudiKernel/DirSearchPath.h>`

Collaboration diagram for DirSearchPath:
[legend]

## Classes
class | eqPath
| name More...

## Public Types
typedef boost::filesystem::path | path

## Public Member Functions
constructors
| DirSearchPath ()
| DirSearchPath (const std::string &stringifiedPath, const char *separator=",:")
modifiers
bool | add (const path &dir)
bool | addCWD ()
| add current work dir (*nix pwd) to path More...
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) More...
bool | find (const path &file, path &fileFound) const
| returns a flag if file found in search path. Sets ref to completed path More...
std::list< path > | find_all (const path &file) const
| returns lists of files found in search path. More...

## Static Public Member Functions
helpers
static bool | existsDir (const std::string &dirName)
| check dirName is valid More...
static bool | existsDir (const path &dir)
| check dir path is valid More...

## Private Attributes
std::vector< path > | m_dirs
| the dir container More...

## Detailed Description

search for files in a list of directories

Author
  Paolo Calafiura pcala.nosp@m.fiur.nosp@m.a@lbl.nosp@m..gov - ATLAS Collaboration

Definition at line 17 of file DirSearchPath.h.

## 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.

24 { addCWD(); }
DirSearchPath::addCWD
bool addCWD()
add current work dir (*nix pwd) to path
Definition: DirSearchPath.cpp:50

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

Exceptions

  boost::filesystem::filesystem_error |

Definition at line 29 of file DirSearchPath.cpp.

30 {
31 addCWD(); // FIXME is this a good idea?
32
33 typedef tokenizer<char_separator<char>> Tokenizer;
34
35 Tokenizer tok( stringifiedPath, char_separator<char>( separator ) );
36
37 // add names to dir container, filtering dir names to remove invalid ones
38 // notice how we iterate over all tokens even if there is an illegal one
39 auto it = tok.begin();
40 while ( it != tok.end() ) {
41 try {
42 path p( *( it++ ) );
43 add( p );
44 } catch ( boost::filesystem::filesystem_error& /*err*/ ) {
45 }
46 }
47 }
DirSearchPath::path
boost::filesystem::path path
Definition: DirSearchPath.h:20
DirSearchPath::add
bool add(const path &dir)
Definition: DirSearchPath.cpp:52
DirSearchPath::addCWD
bool addCWD()
add current work dir (*nix pwd) to path
Definition: DirSearchPath.cpp:50

## Member Function Documentation

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

Exceptions

  filesystem_error |

Definition at line 52 of file DirSearchPath.cpp.

53 {
54 bool dirExist( existsDir( dir ) );
55 // add dir to path even if dir does not (yet) exist,
56 // but don't add twice same dir
57 if ( m_dirs.end() == std::find_if( m_dirs.begin(), m_dirs.end(), eqPath( dir ) ) ) m_dirs.push_back( dir );
58 return dirExist;
59 }
std::vector::end
T end(T...args)
DirSearchPath::m_dirs
std::vector< path > m_dirs
the dir container
Definition: DirSearchPath.h:78
std::vector::push_back
T push_back(T...args)
std::find_if
T find_if(T...args)
std::vector::begin
T begin(T...args)
DirSearchPath::existsDir
static bool existsDir(const std::string &dirName)
check dirName is valid
Definition: DirSearchPath.cpp:100

bool DirSearchPath::addCWD | ( |  | ) |

add current work dir (*nix pwd) to path

Definition at line 50 of file DirSearchPath.cpp.

50 { return add( boost::filesystem::current_path() ); }
DirSearchPath::add
bool add(const path &dir)
Definition: DirSearchPath.cpp:52

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

check dirName is valid

Definition at line 100 of file DirSearchPath.cpp.

101 {
102 bool rc( false );
103 try {
104 rc = is_directory( path( dirName ) );
105 } catch ( ... ) {
106 }
107 return rc;
108 }
DirSearchPath::path
boost::filesystem::path path
Definition: DirSearchPath.h:20
IOTest.rc
rc
Definition: IOTest.py:103

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

check dir path is valid

Definition at line 109 of file DirSearchPath.cpp.

109 { return ( exists( dir ) && is_directory( dir ) ); }

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)

Definition at line 62 of file DirSearchPath.cpp.

63 {
64 bool rc( false );
65 try {
66 path fileFound;
67 if ( ( rc = find( path( fileName ), fileFound ) ) ) fullFileName = fileFound.string();
68 } catch ( ... ) {
69 }
70 return rc;
71 }
DirSearchPath::path
boost::filesystem::path path
Definition: DirSearchPath.h:20
std::string::string
T string(T...args)
IOTest.rc
rc
Definition: IOTest.py:103
DirSearchPath::find
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...
Definition: DirSearchPath.cpp:62

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 74 of file DirSearchPath.cpp.

75 {
76 bool rc( false );
77 for ( const auto& iDir : m_dirs ) {
78 path full{iDir / file};
79 if ( exists( full ) ) {
80 fileFound = full;
81 rc = true;
82 break;
83 }
84 }
85 return rc;
86 }
DirSearchPath::path
boost::filesystem::path path
Definition: DirSearchPath.h:20
DirSearchPath::m_dirs
std::vector< path > m_dirs
the dir container
Definition: DirSearchPath.h:78
IOTest.rc
rc
Definition: IOTest.py:103

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

returns lists of files found in search path.

Definition at line 89 of file DirSearchPath.cpp.

90 {
91 std::list<path> found;
92 for ( const auto& iDir : m_dirs ) {
93 path full{iDir / file};
94 if ( exists( full ) ) found.push_back( full );
95 }
96 return found;
97 }
DirSearchPath::path
boost::filesystem::path path
Definition: DirSearchPath.h:20
DirSearchPath::m_dirs
std::vector< path > m_dirs
the dir container
Definition: DirSearchPath.h:78
std::list::push_back
T push_back(T...args)
std::list
STL class.

## Member Data Documentation

std::vector<path> DirSearchPath::m_dirs
| private

the dir container

Definition at line 78 of file DirSearchPath.h.

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

- GaudiKernel/GaudiKernel/DirSearchPath.h
- GaudiKernel/src/Lib/DirSearchPath.cpp