PathSearcher Class Reference

Handles searching a list of paths for a file. More...

`#include <SearchPath.h>`

Collaboration diagram for PathSearcher:
[legend]

## Public Types

enum | _target_type { kFindFile, kFindDirectory, kFindFile, kFindDirectory }
enum | _target_type { kFindFile, kFindDirectory, kFindFile, kFindDirectory }
typedef enum _target_type | target_type_t
typedef enum _target_type | target_type_t

## Public Member Functions

| PathSearcher ()
| Constructor.
void | addSearchPath (std::string &path)
| Add a new search path to the end of the list.
bool | search (const std::string &base, target_type_t targetType, bool searchCwd, std::string &result)
| Attempts to locate a file by using the search paths. More...
| PathSearcher ()
| Constructor.
void | addSearchPath (std::string &path)
| Add a new search path to the end of the list.
bool | search (const std::string &base, target_type_t targetType, bool searchCwd, std::string &result)
| Attempts to locate a file by using the search paths.

## Static Public Member Functions

static PathSearcher & | getGlobalSearcher ()
| Access global path searching object. More...
static PathSearcher & | getGlobalSearcher ()
| Access global path searching object.

## Protected Types

typedef std::list< std::string > | string_list_t
| Linked list of strings.
typedef std::list< std::string > | string_list_t
| Linked list of strings.

## Protected Member Functions

bool | isAbsolute (const std::string &path)
| Returns whether path is absolute.
std::string | joinPaths (const std::string &first, const std::string &second)
| Combines two paths into a single one.
bool | isAbsolute (const std::string &path)
| Returns whether path is absolute.
std::string | joinPaths (const std::string &first, const std::string &second)
| Combines two paths into a single one.

## Protected Attributes

string_list_t | m_paths
| Ordered list of paths to search.

## Static Protected Attributes

static PathSearcher * | s_searcher = NULL
| Global search object singleton.

## Detailed Description

Handles searching a list of paths for a file.

## Member Function Documentation

PathSearcher & PathSearcher::getGlobalSearcher | ( |  | ) |

static

Access global path searching object.

This function will create the global path search object if it has not already been created.

bool PathSearcher::search | ( | const std::string & | base,
|  | target_type_t | targetType,
|  | bool | searchCwd,
|  | std::string & | result
| ) |  |

Attempts to locate a file by using the search paths.

The base path argument can be either a relative or absolute path. If the path is relative, then it is joined with search paths one after another until a matching file is located or all search paths are exhausted. If the base is absolute, only that path is tested and if invalid false is returned.

Parameters

  | base | A path to the file that is to be found.
  | targetType | Currently ignored. In the future it will let you select whether to find a file or directory.
  | searchCwd | If set to true, the current working directory is searched before using any of the search paths. Otherwise only the search paths are considered.
  [out] | result | When true is returned this string is set to the first path at which a valid file was found.

Return values

  true | A matching file was found among the search paths. The contents of result are a valid path.
  false | No match could be made. result has been left unmodified.

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

- apps/elftosb/common/SearchPath.h
- apps/elftosb/common/SearchPath.cpp