The Gaudi Framework  master (594c33fa)
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
 

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

helpers

std::vector< pathm_dirs
 the dir container More...
 
static bool existsDir (const std::string &dirName)
 check dirName is valid More...
 
static bool existsDir (const path &dir)
 check dir path is valid 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 29 of file DirSearchPath.h.

Member Typedef Documentation

◆ path

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

Definition at line 31 of file DirSearchPath.h.

Constructor & Destructor Documentation

◆ DirSearchPath() [1/2]

DirSearchPath::DirSearchPath ( )
inline

Definition at line 35 of file DirSearchPath.h.

35 { addCWD(); }

◆ DirSearchPath() [2/2]

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

Definition at line 39 of file DirSearchPath.cpp.

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

Member Function Documentation

◆ add()

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

Definition at line 60 of file DirSearchPath.cpp.

60  {
61  bool dirExist( existsDir( dir ) );
62  // add dir to path even if dir does not (yet) exist,
63  // but don't add twice same dir
64  if ( m_dirs.end() == std::find_if( m_dirs.begin(), m_dirs.end(), eqPath( dir ) ) ) m_dirs.push_back( dir );
65  return dirExist;
66 }

◆ addCWD()

bool DirSearchPath::addCWD ( )

add current work dir (*nix pwd) to path

Definition at line 58 of file DirSearchPath.cpp.

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

◆ existsDir() [1/2]

bool DirSearchPath::existsDir ( const path dir)
static

check dir path is valid

Definition at line 110 of file DirSearchPath.cpp.

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

◆ existsDir() [2/2]

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

check dirName is valid

Definition at line 103 of file DirSearchPath.cpp.

103  {
104  bool rc( false );
105  try {
106  rc = is_directory( path( dirName ) );
107  } catch ( ... ) {}
108  return rc;
109 }

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

79  {
80  bool rc( false );
81  for ( const auto& iDir : m_dirs ) {
82  path full{ iDir / file };
83  if ( exists( full ) ) {
84  fileFound = full;
85  rc = true;
86  break;
87  }
88  }
89  return rc;
90 }

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

69  {
70  bool rc( false );
71  try {
72  path fileFound;
73  if ( ( rc = find( path( fileName ), fileFound ) ) ) fullFileName = fileFound.string();
74  } catch ( ... ) {}
75  return rc;
76 }

◆ find_all()

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

returns lists of files found in search path.

Definition at line 93 of file DirSearchPath.cpp.

93  {
94  std::list<path> found;
95  for ( const auto& iDir : m_dirs ) {
96  path full{ iDir / file };
97  if ( exists( full ) ) found.push_back( full );
98  }
99  return found;
100 }

Member Data Documentation

◆ m_dirs

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

the dir container

Definition at line 89 of file DirSearchPath.h.


The documentation for this class was generated from the following files:
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:69
DirSearchPath::addCWD
bool addCWD()
add current work dir (*nix pwd) to path
Definition: DirSearchPath.cpp:58
std::string::string
T string(T... args)
DirSearchPath::m_dirs
std::vector< path > m_dirs
the dir container
Definition: DirSearchPath.h:89
std::list
STL class.
Gaudi::Accumulators::atomicity::full
@ full
std::find_if
T find_if(T... args)
std::vector::push_back
T push_back(T... args)
DirSearchPath::existsDir
static bool existsDir(const std::string &dirName)
check dirName is valid
Definition: DirSearchPath.cpp:103
DirSearchPath::path
boost::filesystem::path path
Definition: DirSearchPath.h:31
std::vector::begin
T begin(T... args)
std::vector::end
T end(T... args)
DirSearchPath::add
bool add(const path &dir)
Definition: DirSearchPath.cpp:60
IOTest.rc
rc
Definition: IOTest.py:114