13 #include <boost/algorithm/string/classification.hpp>
14 #include <boost/algorithm/string/split.hpp>
15 #include <boost/filesystem.hpp>
20 namespace bf = boost::filesystem;
24 static const char* path_separator =
",;";
26 static const char* path_separator =
",:";
36 PathResolver::SearchType search_type,
string& result ) {
44 ( file_type ==
PR_directory && is_directory( file ) ) ) {
45 result = bf::system_complete( file ).string();
48 }
catch (
const bf::filesystem_error& ) {}
53 bf::path local = bf::initial_path() / file;
55 ( file_type ==
PR_directory && is_directory( local ) ) ) {
56 result = bf::system_complete( file ).string();
59 }
catch (
const bf::filesystem_error& ) {}
63 split( spv, search_list, boost::is_any_of( path_separator ), boost::token_compress_on );
64 for (
const auto& itr : spv ) {
71 result = bf::system_complete( fp ).string();
74 }
catch (
const bf::filesystem_error& ) {}
77 if ( search_type == PathResolver::RecursiveSearch && is_directory(
bf::path( itr ) ) ) {
79 bf::recursive_directory_iterator end_itr;
81 for ( bf::recursive_directory_iterator ritr( itr ); ritr != end_itr; ++ritr ) {
84 if ( !is_directory(
bf::path( *ritr ) ) ) {
continue; }
89 result = bf::system_complete( fp2 ).string();
93 }
catch (
const bf::filesystem_error& ) {}
100 string PathResolver::find_file(
const std::string& logical_file_name,
const std::string& search_path,
103 std::string path_list;
106 return ( find_file_from_list( logical_file_name, path_list, search_type ) );
109 std::string PathResolver::find_file_from_list(
const std::string& logical_file_name,
const std::string& search_list,
111 std::string result(
"" );
131 string PathResolver::find_directory(
const std::string& logical_file_name,
const std::string& search_path,
133 std::string path_list;
136 return ( find_directory_from_list( logical_file_name, path_list, search_type ) );
139 string PathResolver::find_directory_from_list(
const std::string& logical_file_name,
const std::string& search_list,
143 if ( !PR_find( logical_file_name, search_list,
PR_directory, search_type, result ) ) { result =
""; }
149 std::string path_list;
150 if ( !
System::getEnv( search_path, path_list ) )
return ( EnvironmentVariableUndefined );
153 boost::split( spv, path_list, boost::is_any_of( path_separator ), boost::token_compress_on );
156 for (
const auto& itr : spv ) {
158 if ( !is_directory(
pp ) ) {
return ( UnknownDirectory ); }
160 }
catch (
const bf::filesystem_error& ) {
return ( UnknownDirectory ); }
166 return PathResolver::find_file( logical_file_name,
"XMLPATH" );
170 return PathResolver::find_file( logical_file_name,
"DATAPATH" );