8 # pragma warning( disable : 4996 ) 16 #include <boost/algorithm/string/classification.hpp> 17 #include <boost/algorithm/string/split.hpp> 18 #include <boost/filesystem.hpp> 20 namespace bf = boost::filesystem;
24 static const char* path_separator =
",;";
26 static const char* path_separator =
",:";
41 static bool PR_find(
const bf::path& file,
const string& search_list, PR_file_type file_type,
50 ( file_type ==
PR_directory && is_directory( file ) ) ) {
51 result = bf::system_complete( file ).
string();
54 }
catch (
const bf::filesystem_error& ) {}
59 bf::path local = bf::initial_path() / file;
61 ( file_type ==
PR_directory && is_directory( local ) ) ) {
62 result = bf::system_complete( file ).
string();
65 }
catch (
const bf::filesystem_error& ) {}
69 split( spv, search_list, boost::is_any_of( path_separator ), boost::token_compress_on );
70 for (
const auto& itr : spv ) {
77 result = bf::system_complete( fp ).
string();
80 }
catch (
const bf::filesystem_error& ) {}
83 if ( search_type == PathResolver::RecursiveSearch && is_directory(
bf::path( itr ) ) ) {
85 bf::recursive_directory_iterator end_itr;
87 for ( bf::recursive_directory_iterator ritr( itr ); ritr != end_itr; ++ritr ) {
90 if ( !is_directory(
bf::path( *ritr ) ) ) {
continue; }
95 result = bf::system_complete( fp2 ).
string();
99 }
catch (
const bf::filesystem_error& ) {}
114 return ( find_file_from_list( logical_file_name, path_list, search_type ) );
148 return ( find_directory_from_list( logical_file_name, path_list, search_type ) );
157 if ( !PR_find( logical_file_name, search_list,
PR_directory, search_type, result ) ) { result =
""; }
166 if ( !
System::getEnv( search_path, path_list ) )
return ( EnvironmentVariableUndefined );
169 boost::split( spv, path_list, boost::is_any_of( path_separator ), boost::token_compress_on );
172 for (
const auto& itr : spv ) {
174 if ( !is_directory( pp ) ) {
return ( UnknownDirectory ); }
176 }
catch (
const bf::filesystem_error& ) {
return ( UnknownDirectory ); }
184 return PathResolver::find_file( logical_file_name,
"XMLPATH" );
188 return PathResolver::find_file( logical_file_name,
"DATAPATH" );
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Note: OS specific details for environment resolution.
GAUDI_API std::string PathResolverFindXMLFile(const std::string &logical_file_name)
GAUDI_API std::string PathResolverFindDataFile(const std::string &logical_file_name)