The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
DirSearchPath Class Reference

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

#include </builds/gaudi/Gaudi/GaudiKernel/include/GaudiKernel/DirSearchPath.h>

Collaboration diagram for DirSearchPath:

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
 
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< pathfind_all (const path &file) const
 returns lists of files found in search path.
 

helpers

std::vector< pathm_dirs
 the dir container
 
static bool existsDir (const std::string &dirName)
 check dirName is valid
 
static bool existsDir (const path &dir)
 check dir path is valid
 

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 28 of file DirSearchPath.h.

Member Typedef Documentation

◆ path

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

Definition at line 30 of file DirSearchPath.h.

Constructor & Destructor Documentation

◆ DirSearchPath() [1/2]

DirSearchPath::DirSearchPath ( )
inline

Definition at line 34 of file DirSearchPath.h.

34{ addCWD(); }
bool addCWD()
add current work dir (*nix pwd) to path

◆ DirSearchPath() [2/2]

DirSearchPath::DirSearchPath ( const std::string & stringifiedPath,
const char * separator = ",:" )
Exceptions
boost::filesystem::filesystem_error

Definition at line 34 of file DirSearchPath.cpp.

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

Member Function Documentation

◆ add()

bool DirSearchPath::add ( const path & dir)
Exceptions
filesystem_error

Definition at line 55 of file DirSearchPath.cpp.

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

◆ addCWD()

bool DirSearchPath::addCWD ( )

add current work dir (*nix pwd) to path

Definition at line 53 of file DirSearchPath.cpp.

53{ return add( boost::filesystem::current_path() ); }

◆ existsDir() [1/2]

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

check dir path is valid

Definition at line 105 of file DirSearchPath.cpp.

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

◆ existsDir() [2/2]

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

check dirName is valid

Definition at line 98 of file DirSearchPath.cpp.

98 {
99 bool rc( false );
100 try {
101 rc = is_directory( path( dirName ) );
102 } catch ( ... ) {}
103 return rc;
104}

◆ find() [1/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 74 of file DirSearchPath.cpp.

74 {
75 bool rc( false );
76 for ( const auto& iDir : m_dirs ) {
77 path full{ iDir / file };
78 if ( exists( full ) ) {
79 fileFound = full;
80 rc = true;
81 break;
82 }
83 }
84 return rc;
85}

◆ find() [2/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 64 of file DirSearchPath.cpp.

64 {
65 bool rc( false );
66 try {
67 path fileFound;
68 if ( ( rc = find( path( fileName ), fileFound ) ) ) fullFileName = fileFound.string();
69 } catch ( ... ) {}
70 return rc;
71}
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...

◆ find_all()

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

returns lists of files found in search path.

Definition at line 88 of file DirSearchPath.cpp.

88 {
89 std::list<path> found;
90 for ( const auto& iDir : m_dirs ) {
91 path full{ iDir / file };
92 if ( exists( full ) ) found.push_back( full );
93 }
94 return found;
95}

Member Data Documentation

◆ m_dirs

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

the dir container

Definition at line 84 of file DirSearchPath.h.


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