sofa::helper::system::FileRepository Class Reference

Helper class to find files in a list of directories. More...

#include <FileRepository.h>

Collaboration diagram for sofa::helper::system::FileRepository:

Collaboration graph
[legend]

Public Member Functions

 FileRepository (const char *envVar="SOFA_DATA_PATH", const char *relativePath="../share")
 Initialize the set of paths from an environment variable.
 ~FileRepository ()
void addFirstPath (const std::string &path)
 Adds a path to the front of the set of paths.
void addLastPath (const std::string &path)
 Adds a path to the back of the set of paths.
std::string getFirstPath ()
 Get the first path into the set of paths.
bool findFile (std::string &filename, const std::string &basedir="")
 Find file using the stored set of paths.
std::string getFile (std::string filename, const std::string &basedir="")
 Alias for findFile, but returning the resolved file as the result.
bool findFileFromFile (std::string &filename, const std::string &basefile)
 Find file using the stored set of paths.
void print ()
 Print the list of path to std::cout.

Static Public Member Functions

static char entrySeparator ()
 OS-dependant character separing entries in list of paths.

Static Protected Member Functions

static bool findFileIn (std::string &filename, const std::string &path)
 Search file in a given path.

Protected Attributes

std::vector< std::string > vpath
 Vector of paths.

Detailed Description

Helper class to find files in a list of directories.

Each file is searched as follow:

1: Using the specified filename in current directory, or in the specified directory. If the filename does not start with "/", "./", or "../" : 2: In the directory path specified using addFirstPath method. 3: In the directory path specified using an environment variable (default to SOFA_DATA_PATH). 4: In the default directories relative to the main executable (default to ../share). 5: In the directory path specified using addLastPath method.

For file name starting with '/', './' or '../' only the first step is used.

A path is considered as a concatenation of directories separated by :

Definition at line 57 of file FileRepository.h.


Constructor & Destructor Documentation

sofa::helper::system::FileRepository::FileRepository ( const char *  envVar = "SOFA_DATA_PATH",
const char *  relativePath = "../share" 
)

Initialize the set of paths from an environment variable.

Definition at line 60 of file FileRepository.cpp.

References addFirstPath(), addLastPath(), entrySeparator(), and sofa::helper::system::SetDirectory::GetRelativeFromProcess().

sofa::helper::system::FileRepository::~FileRepository (  ) 

Definition at line 88 of file FileRepository.cpp.


Member Function Documentation

void sofa::helper::system::FileRepository::addFirstPath ( const std::string &  path  ) 

Adds a path to the front of the set of paths.

Definition at line 92 of file FileRepository.cpp.

References entrySeparator(), and vpath.

Referenced by FileRepository().

void sofa::helper::system::FileRepository::addLastPath ( const std::string &  path  ) 

Adds a path to the back of the set of paths.

Definition at line 110 of file FileRepository.cpp.

References entrySeparator(), and vpath.

Referenced by FileRepository().

static char sofa::helper::system::FileRepository::entrySeparator (  )  [inline, static]

OS-dependant character separing entries in list of paths.

Definition at line 99 of file FileRepository.h.

Referenced by addFirstPath(), addLastPath(), and FileRepository().

bool sofa::helper::system::FileRepository::findFile ( std::string &  filename,
const std::string &  basedir = "" 
)

Find file using the stored set of paths.

Parameters:
basedir override current directory (optional)
filename requested file as input, resolved file path as output
Returns:
true if the file was found in one of the directories, false otherwise

Definition at line 152 of file FileRepository.cpp.

References findFileIn(), sofa::helper::system::SetDirectory::GetCurrentDir(), sofa::helper::system::SetDirectory::GetRelativeFromDir(), sofa::helper::system::SetDirectory::IsAbsolute(), and vpath.

Referenced by findFileFromFile(), getFile(), and sofa::simulation::tree::Simulation::load().

bool sofa::helper::system::FileRepository::findFileFromFile ( std::string &  filename,
const std::string &  basefile 
)

Find file using the stored set of paths.

Parameters:
basefile override current directory by using the parent directory of the given file
filename requested file as input, resolved file path as output
Returns:
true if the file was found in one of the directories, false otherwise

Definition at line 174 of file FileRepository.cpp.

References findFile(), and sofa::helper::system::SetDirectory::GetParentDir().

bool sofa::helper::system::FileRepository::findFileIn ( std::string &  filename,
const std::string &  path 
) [static, protected]

Search file in a given path.

Definition at line 136 of file FileRepository.cpp.

References sofa::helper::system::SetDirectory::GetRelativeFromDir().

Referenced by findFile().

std::string sofa::helper::system::FileRepository::getFile ( std::string  filename,
const std::string &  basedir = "" 
) [inline]

Alias for findFile, but returning the resolved file as the result.

Less informative for errors, but sometimes easier to use

Definition at line 83 of file FileRepository.h.

References findFile().

std::string sofa::helper::system::FileRepository::getFirstPath (  ) 

Get the first path into the set of paths.

Definition at line 129 of file FileRepository.cpp.

References vpath.

void sofa::helper::system::FileRepository::print (  ) 

Print the list of path to std::cout.

Definition at line 179 of file FileRepository.cpp.

References vpath.


Field Documentation

std::vector<std::string> sofa::helper::system::FileRepository::vpath [protected]

Vector of paths.

Definition at line 111 of file FileRepository.h.

Referenced by addFirstPath(), addLastPath(), findFile(), getFirstPath(), and print().


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

Generated on Sun Nov 23 04:24:20 2008 for Sofa by  doxygen 1.5.7.1