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>`

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

## ApplicationData() [1/2]

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

  paths | The list of search paths.

## ApplicationData() [2/2]

SurgSim::Framework::ApplicationData::ApplicationData | ( | const std::string & | configFile | ) |

explicit

Reads the search paths from a given configuration file.

Parameters

  configFile | The configuration file for reading the search paths.

## ~ApplicationData()

SurgSim::Framework::ApplicationData::~ApplicationData | ( |  | ) |

## Member Function Documentation

## addPath()

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

private

Adds a single path to the list of search paths.

Parameters

  pathName | Full pathname.

Returns
  true if it succeeds, false if the given path does not exist or if it is already in the list of paths.

## findFile()

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

  fileName | Filename 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.

## getPaths()

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.

## isValidFilename()

bool SurgSim::Framework::ApplicationData::isValidFilename | ( | const std::string & | fileName | ) | const

Checks if the filename is acceptable.

Parameters

  fileName | Filename to be checked.

Returns
  true if the name is valid, false otherwise.

## setPaths()

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

  paths | The 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.

## tryFindFile()

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

  fileName | Filename of the file.
  target | The location for the converted filename if it was found.

Returns
  true if the file is found, false otherwise.

## Member Data Documentation

## m_paths

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

private

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

- SurgSim/Framework/ApplicationData.h
- SurgSim/Framework/ApplicationData.cpp