All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SurgSim::Framework::ApplicationData Class Reference

Enable searching for files in a given list of paths, give access to the current directory and wrap boost::filesystem functionality. More...

#include <SurgSim/Framework/ApplicationData.h>

Collaboration diagram for SurgSim::Framework::ApplicationData:
Collaboration graph
[legend]

Public Member Functions

 ApplicationData (const std::vector< std::string > &paths)
 Constructor, class is immutable, pass a list of paths to be used for searching duplicate paths will be eliminated, invalid paths will be eliminated, the order of the paths given here is the order that will be used in searching, the first occurrance of a file within a given path will be used. More...
 
 ApplicationData (const std::string &configFile)
 Reads the search paths from a given configuration file. More...
 
 ~ApplicationData ()
 
std::vector< std::string > getPaths () const
 Gets the search paths. More...
 
std::string findFile (const std::string &fileName) const
 Searches for the first occurrence of fileName amongst the given paths, the search is shallow, only direct content of the directories in the path list will be used as search candidates. More...
 
bool tryFindFile (const std::string &fileName, std::string *target) const
 Searches for the first occurrence of fileName amongst the given paths, see findFile() for details. More...
 
bool isValidFilename (const std::string &fileName) const
 Checks if the filename is acceptable. More...
 

Private Member Functions

bool addPath (const std::string &pathName)
 Adds a single path to the list of search paths. More...
 
bool setPaths (const std::vector< std::string > &paths)
 Sets the list of search paths to be used for finding the location of files. More...
 

Private Attributes

std::vector
< boost::filesystem::path > 
m_paths
 

Detailed Description

Enable searching for files in a given list of paths, give access to the current directory and wrap boost::filesystem functionality.

Constructor & Destructor Documentation

SurgSim::Framework::ApplicationData::ApplicationData ( const std::vector< std::string > &  paths)
explicit

Constructor, class is immutable, pass a list of paths to be used for searching duplicate paths will be eliminated, invalid paths will be eliminated, the order of the paths given here is the order that will be used in searching, the first occurrance of a file within a given path will be used.

Parameters
pathsThe list of search paths.
SurgSim::Framework::ApplicationData::ApplicationData ( const std::string &  configFile)
explicit

Reads the search paths from a given configuration file.

Parameters
configFileThe configuration file for reading the search paths.
SurgSim::Framework::ApplicationData::~ApplicationData ( )

Member Function Documentation

bool SurgSim::Framework::ApplicationData::addPath ( const std::string &  pathName)
private

Adds a single path to the list of search paths.

Parameters
pathNameFull pathname.
Returns
true if it succeeds, false if the given path does not exist or if it is already in the list of paths.
std::string SurgSim::Framework::ApplicationData::findFile ( const std::string &  fileName) const

Searches for the first occurrence of fileName amongst the given paths, the search is shallow, only direct content of the directories in the path list will be used as search candidates.

Parameters
fileNameFilename of the file.
Returns
The absolute path to the file in system format i.e c:\xxx\yyy\file.txt for windows and /xxx/yyy/file.txt for all other systems. An empty string will be returned if the file cannot be found.
std::vector< std::string > SurgSim::Framework::ApplicationData::getPaths ( ) const

Gets the search paths.

Returns
The paths, passed in the constructor with duplicates and invalid paths removed. All paths returned will be absolute and in system format.
bool SurgSim::Framework::ApplicationData::isValidFilename ( const std::string &  fileName) const

Checks if the filename is acceptable.

Parameters
fileNameFilename to be checked.
Returns
true if the name is valid, false otherwise.
bool SurgSim::Framework::ApplicationData::setPaths ( const std::vector< std::string > &  paths)
private

Sets the list of search paths to be used for finding the location of files.

Eliminates duplicate paths and paths that do not exist

Parameters
pathsThe paths to be used for finding files.
Returns
true if it succeeds, false if one or more of the paths do not exist in the system or are duplicated.
bool SurgSim::Framework::ApplicationData::tryFindFile ( const std::string &  fileName,
std::string *  target 
) const

Searches for the first occurrence of fileName amongst the given paths, see findFile() for details.

If the file is found the full pathName will be sent in target and true returned. If the file is not found the result will be false and the content of target will not change.

Parameters
fileNameFilename of the file.
targetThe location for the converted filename if it was found.
Returns
true if the file is found, false otherwise.

Member Data Documentation

std::vector<boost::filesystem::path> SurgSim::Framework::ApplicationData::m_paths
private

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