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 =
",:";
42 static bool PR_find(
const bf::path& file,
const string& search_list, PR_file_type file_type,
52 ( file_type ==
PR_directory && is_directory( file ) ) ) {
53 result = bf::system_complete( file ).
string();
56 }
catch (
const bf::filesystem_error& ) {
62 bf::path local = bf::initial_path() / file;
64 ( file_type ==
PR_directory && is_directory( local ) ) ) {
65 result = bf::system_complete( file ).
string();
68 }
catch (
const bf::filesystem_error& ) {
73 split( spv, search_list, boost::is_any_of( path_separator ), boost::token_compress_on );
74 for (
const auto& itr : spv ) {
81 result = bf::system_complete( fp ).
string();
84 }
catch (
const bf::filesystem_error& ) {
88 if ( search_type == PathResolver::RecursiveSearch && is_directory(
bf::path( itr ) ) ) {
90 bf::recursive_directory_iterator end_itr;
92 for ( bf::recursive_directory_iterator ritr( itr ); ritr != end_itr; ++ritr ) {
95 if ( !is_directory(
bf::path( *ritr ) ) ) {
101 ( file_type ==
PR_directory && is_directory( fp2 ) ) ) {
102 result = bf::system_complete( fp2 ).
string();
106 }
catch (
const bf::filesystem_error& ) {
123 return ( find_file_from_list( logical_file_name, path_list, search_type ) );
159 return ( find_directory_from_list( logical_file_name, path_list, search_type ) );
169 if ( !PR_find( logical_file_name, search_list,
PR_directory, search_type, result ) ) {
181 if ( !
System::getEnv( search_path, path_list ) )
return ( EnvironmentVariableUndefined );
184 boost::split( spv, path_list, boost::is_any_of( path_separator ), boost::token_compress_on );
187 for (
const auto& itr : spv ) {
189 if ( !is_directory( pp ) ) {
190 return ( UnknownDirectory );
193 }
catch (
const bf::filesystem_error& ) {
194 return ( UnknownDirectory );
204 return PathResolver::find_file( logical_file_name,
"XMLPATH" );
209 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)