Gaudi Framework, version v22r4

Home   Generated: Fri Sep 2 2011
Classes | Public Types | Private Attributes

DirSearchPath Class Reference

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

#include <DirSearchPath.h>

Collaboration diagram for DirSearchPath:
Collaboration graph
[legend]

List of all members.

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.

Static Public Member Functions

helpers
static bool existsDir (const std::string &dirName)
 check dirName is valid
static bool existsDir (const path &dir)
 check dir path is valid

Private Attributes

std::list< pathm_dirs
 the dir container

Detailed Description

search for files in a list of directories

Author:
Paolo Calafiura <pcalafiura@lbl.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.

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

Definition at line 29 of file DirSearchPath.cpp.

                                                                                    {
  addCWD(); //FIXME is this a good idea?

  typedef  tokenizer<char_separator<char> > Tokenizer;

  Tokenizer tok(stringifiedPath, char_separator<char>(separator));

  //add names to dir container, filtering dir names to remove invalid ones
  //notice how we iterate over all tokens even if there is an illegal one
  Tokenizer::iterator it = tok.begin();
  while(it != tok.end()) {
    try {
      path p(*(it++));
      add(p);
    }
    catch (boost::filesystem::filesystem_error &/*err*/) {
    }
  }
}

Member Function Documentation

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

Definition at line 54 of file DirSearchPath.cpp.

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

add current work dir (*nix pwd) to path

Definition at line 50 of file DirSearchPath.cpp.

                           {
  return add(boost::filesystem::current_path());
}
bool DirSearchPath::existsDir ( const path dir ) [static]

check dir path is valid

Definition at line 109 of file DirSearchPath.cpp.

                                             {
  return (exists(dir) && is_directory(dir));
}
bool DirSearchPath::existsDir ( const std::string dirName ) [static]

check dirName is valid

Definition at line 102 of file DirSearchPath.cpp.

                                                      {
  bool rc(false);
  try {
    rc=is_directory(path(dirName));
  } catch(...) {}
  return rc;
}
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.

                                                                {
  bool rc(false);
  for (std::list<path>::const_iterator iDir=m_dirs.begin(); iDir!=m_dirs.end(); ++iDir) {
    path full(*iDir / file);
    if (exists(full)) {
      fileFound = full;
      rc = true;
      break;
    }
  }
  return rc;
}
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.

                                                                           {
  bool rc(false);
  try {
    path fileFound;
    if ( (rc = find(path(fileName), fileFound)) )
      fullFileName = fileFound.native_directory_string();
  } catch (...) {}
  return rc;
}
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.

                                              {
  std::list<path> found;
  for (std::list<path>::const_iterator iDir=m_dirs.begin(); iDir!=m_dirs.end(); ++iDir) {
    path full(*iDir / file);
    if (exists(full)) {
      found.push_back(full);
    }
  }
  return found;
}

Member Data Documentation

the dir container

Definition at line 81 of file DirSearchPath.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Fri Sep 2 2011 16:25:18 for Gaudi Framework, version v22r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004