The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
System::PathResolver Class Reference

#include </builds/gaudi/Gaudi/GaudiKernel/include/GaudiKernel/PathResolver.h>

Public Types

enum  SearchPathStatus { Ok , EnvironmentVariableUndefined , UnknownDirectory }
 
enum  SearchType { LocalSearch , RecursiveSearch }
 

Static Public Member Functions

static std::string find_file (const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
 
static std::string find_file_from_list (const std::string &logical_file_name, const std::string &search_list, SearchType search_type=LocalSearch)
 
static std::string find_directory (const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
 
static std::string find_directory_from_list (const std::string &logical_file_name, const std::string &search_list, SearchType search_type=LocalSearch)
 
static SearchPathStatus check_search_path (const std::string &search_path)
 

Detailed Description

Definition at line 18 of file PathResolver.h.

Member Enumeration Documentation

◆ SearchPathStatus

Enumerator
Ok 
EnvironmentVariableUndefined 
UnknownDirectory 

Definition at line 22 of file PathResolver.h.

◆ SearchType

Enumerator
LocalSearch 
RecursiveSearch 

Definition at line 24 of file PathResolver.h.

Member Function Documentation

◆ check_search_path()

PathResolver::SearchPathStatus System::PathResolver::check_search_path ( const std::string & search_path)
static
  • search_path the name of a path-like environment variable
Returns
the result of the verification. Can be one of Ok, EnvironmentVariableUndefined, UnknownDirectory

Definition at line 144 of file PathResolver.cpp.

144 {
145 std::string path_list;
146 if ( !System::getEnv( search_path, path_list ) ) return ( EnvironmentVariableUndefined );
147
148 vector<string> spv;
149 boost::split( spv, path_list, boost::is_any_of( path_separator ), boost::token_compress_on );
150
151 try {
152 for ( const auto& itr : spv ) {
153 bf::path pp( itr );
154 if ( !is_directory( pp ) ) { return ( UnknownDirectory ); }
155 }
156 } catch ( const bf::filesystem_error& /*err*/ ) { return ( UnknownDirectory ); }
157
158 return ( Ok );
159 }
GAUDI_API std::vector< std::string > getEnv()
get all environment variables
Definition System.cpp:356

◆ find_directory()

string System::PathResolver::find_directory ( const std::string & logical_file_name,
const std::string & search_path,
SearchType search_type = LocalSearch )
static
  • logical_file_name the name of the directory to locate in the search path
  • search_path the name of a path-like environment variable
  • search_type characterizes the type of search. Can be either LocalSearch or RecursiveSearch
Returns
the physical name of the located directory or empty string if not found

Definition at line 127 of file PathResolver.cpp.

128 {
129 std::string path_list;
130 System::getEnv( search_path, path_list );
131
132 return ( find_directory_from_list( logical_file_name, path_list, search_type ) );
133 }
static std::string find_directory_from_list(const std::string &logical_file_name, const std::string &search_list, SearchType search_type=LocalSearch)

◆ find_directory_from_list()

string System::PathResolver::find_directory_from_list ( const std::string & logical_file_name,
const std::string & search_list,
SearchType search_type = LocalSearch )
static
  • logical_file_name the name of the directory to locate in the search path
  • search_list the prioritized list of possible locations separated by the usual path separator
  • search_type characterizes the type of search. Can be either LocalSearch or RecursiveSearch
Returns
the physical name of the located directory or empty string if not found

Definition at line 135 of file PathResolver.cpp.

136 {
137 std::string result;
138
139 if ( !PR_find( logical_file_name, search_list, PR_directory, search_type, result ) ) { result = ""; }
140
141 return ( result );
142 }

◆ find_file()

string System::PathResolver::find_file ( const std::string & logical_file_name,
const std::string & search_path,
SearchType search_type = LocalSearch )
static
  • logical_file_name the name of the file to locate in the search path
  • search_path the name of a path-like environment variable
  • search_type characterizes the type of search. Can be either LocalSearch or RecursiveSearch
Returns
the physical name of the located file or empty string if not found

Definition at line 96 of file PathResolver.cpp.

97 {
98
99 std::string path_list;
100 System::getEnv( search_path, path_list );
101
102 return ( find_file_from_list( logical_file_name, path_list, search_type ) );
103 }
static std::string find_file_from_list(const std::string &logical_file_name, const std::string &search_list, SearchType search_type=LocalSearch)

◆ find_file_from_list()

std::string System::PathResolver::find_file_from_list ( const std::string & logical_file_name,
const std::string & search_list,
SearchType search_type = LocalSearch )
static
  • logical_file_name the name of the file to locate in the search path
  • search_list the prioritized list of possible locations separated by the usual path separator
  • search_type characterizes the type of search. Can be either LocalSearch or RecursiveSearch
Returns
the physical name of the located file or empty string if not found

Definition at line 105 of file PathResolver.cpp.

106 {
107 std::string result( "" );
108
109 bf::path lfn( logical_file_name );
110
111 /* bool found = */
112 PR_find( lfn, search_list, PR_regular_file, search_type, result );
113
114 // The following functionality was in the original PathResolver, but I believe
115 // that it's WRONG. It extracts the filename of the requested item, and searches
116 // for that if the preceding search fails. i.e., if you're looking for "B/a.txt",
117 // and that fails, it will look for just "a.txt" in the search list.
118
119 // if (! found && lfn.filename() != lfn ) {
120 // result = "";
121 // PR_find (lfn.filename(), search_list, PR_regular_file, search_type, result);
122 // }
123
124 return ( result );
125 }
@ PR_regular_file

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