The Gaudi Framework  master (37c0b60a)
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 40 of file DirSearchPath.cpp.

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

Member Function Documentation

◆ add()

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

Definition at line 61 of file DirSearchPath.cpp.

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

◆ addCWD()

bool DirSearchPath::addCWD ( )

add current work dir (*nix pwd) to path

Definition at line 59 of file DirSearchPath.cpp.

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

◆ existsDir() [1/2]

bool DirSearchPath::existsDir ( const path dir)
static

check dir path is valid

Definition at line 111 of file DirSearchPath.cpp.

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

◆ existsDir() [2/2]

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

check dirName is valid

Definition at line 104 of file DirSearchPath.cpp.

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

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

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

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

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

◆ find_all()

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

returns lists of files found in search path.

Definition at line 94 of file DirSearchPath.cpp.

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

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:70
DirSearchPath::addCWD
bool addCWD()
add current work dir (*nix pwd) to path
Definition: DirSearchPath.cpp:59
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:104
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:61
IOTest.rc
rc
Definition: IOTest.py:114