All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DirSearchPath Class Reference

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

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

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::list< pathm_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
Id
DirSearchPath.h,v 1.2 2007/10/16 15:37:25 marcocle Exp

Definition at line 19 of file DirSearchPath.h.

Member Typedef Documentation

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

Definition at line 21 of file DirSearchPath.h.

Constructor & Destructor Documentation

DirSearchPath::DirSearchPath ( )
inline

Definition at line 25 of file DirSearchPath.h.

25 { addCWD(); }
bool addCWD()
add current work dir (*nix pwd) to path
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  Tokenizer::iterator it = tok.begin();
39  while(it != tok.end()) {
40  try {
41  path p(*(it++));
42  add(p);
43  }
44  catch (boost::filesystem::filesystem_error &/*err*/) {
45  }
46  }
47 }
boost::filesystem::path path
Definition: DirSearchPath.h:21
bool add(const path &dir)
STL Include files.
Definition: Tokenizer.h:24
bool addCWD()
add current work dir (*nix pwd) to path

Member Function Documentation

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

Definition at line 54 of file DirSearchPath.cpp.

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

add current work dir (*nix pwd) to path

Definition at line 50 of file DirSearchPath.cpp.

50  {
51  return add(boost::filesystem::current_path());
52 }
bool add(const path &dir)
bool DirSearchPath::existsDir ( const std::string &  dirName)
static

check dirName is valid

Definition at line 102 of file DirSearchPath.cpp.

102  {
103  bool rc(false);
104  try {
105  rc=is_directory(path(dirName));
106  } catch(...) {}
107  return rc;
108 }
boost::filesystem::path path
Definition: DirSearchPath.h:21
tuple rc
Definition: IOTest.py:92
bool DirSearchPath::existsDir ( const path dir)
static

check dir path is valid

Definition at line 109 of file DirSearchPath.cpp.

109  {
110  return (exists(dir) && is_directory(dir));
111 }
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)) )
69  fullFileName = fileFound.string();
70  } catch (...) {}
71  return rc;
72 }
boost::filesystem::path path
Definition: DirSearchPath.h:21
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...
tuple rc
Definition: IOTest.py:92
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 75 of file DirSearchPath.cpp.

75  {
76  bool rc(false);
77  for (std::list<path>::const_iterator iDir=m_dirs.begin(); iDir!=m_dirs.end(); ++iDir) {
78  path full(*iDir / file);
79  if (exists(full)) {
80  fileFound = full;
81  rc = true;
82  break;
83  }
84  }
85  return rc;
86 }
std::list< path > m_dirs
the dir container
Definition: DirSearchPath.h:81
boost::filesystem::path path
Definition: DirSearchPath.h:21
tuple rc
Definition: IOTest.py:92
list file
Definition: ana.py:160
std::list< DirSearchPath::path > DirSearchPath::find_all ( const path file) const

returns lists of files found in search path.

Definition at line 90 of file DirSearchPath.cpp.

90  {
91  std::list<path> found;
92  for (std::list<path>::const_iterator iDir=m_dirs.begin(); iDir!=m_dirs.end(); ++iDir) {
93  path full(*iDir / file);
94  if (exists(full)) {
95  found.push_back(full);
96  }
97  }
98  return found;
99 }
std::list< path > m_dirs
the dir container
Definition: DirSearchPath.h:81
boost::filesystem::path path
Definition: DirSearchPath.h:21
list file
Definition: ana.py:160

Member Data Documentation

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

the dir container

Definition at line 81 of file DirSearchPath.h.


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