| The Gaudi Framework v32r1 (f65d50dc)

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

## ◆ path

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

Definition at line 19 of file DirSearchPath.h.

## Constructor & Destructor Documentation

## ◆ DirSearchPath() [1/2]

DirSearchPath::DirSearchPath | ( |  | ) |
| inline

Definition at line 23 of file DirSearchPath.h.

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

## ◆ DirSearchPath() [2/2]

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

Exceptions

  boost::filesystem::filesystem_error |

Definition at line 29 of file DirSearchPath.cpp.

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

## Member Function Documentation

## ◆ add()

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

Exceptions

  filesystem_error |

Definition at line 50 of file DirSearchPath.cpp.

50 {
51 bool dirExist( existsDir( dir ) );
52 // add dir to path even if dir does not (yet) exist,
53 // but don't add twice same dir
54 if ( m_dirs.end() == std::find_if( m_dirs.begin(), m_dirs.end(), eqPath( dir ) ) ) m_dirs.push_back( dir );
55 return dirExist;
56 }
std::vector::end
T end(T... args)
DirSearchPath::m_dirs
std::vector< path > m_dirs
the dir container
Definition: DirSearchPath.h:77
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:93

## ◆ addCWD()

bool DirSearchPath::addCWD | ( |  | ) |

add current work dir (*nix pwd) to path

Definition at line 48 of file DirSearchPath.cpp.

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

## ◆ existsDir() [1/2]

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

check dirName is valid

Definition at line 93 of file DirSearchPath.cpp.

93 {
94 bool rc( false );
95 try {
96 rc = is_directory( path( dirName ) );
97 } catch ( ... ) {}
98 return rc;
99 }
DirSearchPath::path
boost::filesystem::path path
Definition: DirSearchPath.h:19
IOTest.rc
rc
Definition: IOTest.py:101

## ◆ existsDir() [2/2]

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

check dir path is valid

Definition at line 100 of file DirSearchPath.cpp.

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

## ◆ find() [1/2]

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

59 {
60 bool rc( false );
61 try {
62 path fileFound;
63 if ( ( rc = find( path( fileName ), fileFound ) ) ) fullFileName = fileFound.string();
64 } catch ( ... ) {}
65 return rc;
66 }
DirSearchPath::path
boost::filesystem::path path
Definition: DirSearchPath.h:19
std::string::string
T string(T... args)
IOTest.rc
rc
Definition: IOTest.py:101
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:59

## ◆ find() [2/2]

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

69 {
70 bool rc( false );
71 for ( const auto& iDir : m_dirs ) {
72 path full{iDir / file};
73 if ( exists( full ) ) {
74 fileFound = full;
75 rc = true;
76 break;
77 }
78 }
79 return rc;
80 }
DirSearchPath::path
boost::filesystem::path path
Definition: DirSearchPath.h:19
DirSearchPath::m_dirs
std::vector< path > m_dirs
the dir container
Definition: DirSearchPath.h:77
IOTest.rc
rc
Definition: IOTest.py:101
Gaudi::Accumulators::atomicity::full

## ◆ find_all()

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

returns lists of files found in search path.

Definition at line 83 of file DirSearchPath.cpp.

83 {
84 std::list<path> found;
85 for ( const auto& iDir : m_dirs ) {
86 path full{iDir / file};
87 if ( exists( full ) ) found.push_back( full );
88 }
89 return found;
90 }
DirSearchPath::path
boost::filesystem::path path
Definition: DirSearchPath.h:19
DirSearchPath::m_dirs
std::vector< path > m_dirs
the dir container
Definition: DirSearchPath.h:77
std::list::push_back
T push_back(T... args)
std::list
STL class.
Gaudi::Accumulators::atomicity::full

## Member Data Documentation

## ◆ m_dirs

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

the dir container

Definition at line 77 of file DirSearchPath.h.

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

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