13 #include <boost/algorithm/string/classification.hpp>
14 #include <boost/algorithm/string/split.hpp>
15 #include <boost/filesystem.hpp>
20 namespace bf = boost::filesystem;
23 static const char* path_separator =
",:";
32 PathResolver::SearchType search_type,
string& result ) {
40 ( file_type ==
PR_directory && is_directory( file ) ) ) {
41 result = bf::system_complete( file ).string();
44 }
catch (
const bf::filesystem_error& ) {}
49 bf::path local = bf::initial_path() / file;
51 ( file_type ==
PR_directory && is_directory( local ) ) ) {
52 result = bf::system_complete( file ).string();
55 }
catch (
const bf::filesystem_error& ) {}
59 split( spv, search_list, boost::is_any_of( path_separator ), boost::token_compress_on );
60 for (
const auto& itr : spv ) {
67 result = bf::system_complete( fp ).string();
70 }
catch (
const bf::filesystem_error& ) {}
73 if ( search_type == PathResolver::RecursiveSearch && is_directory(
bf::path( itr ) ) ) {
75 bf::recursive_directory_iterator end_itr;
77 for ( bf::recursive_directory_iterator ritr( itr ); ritr != end_itr; ++ritr ) {
80 if ( !is_directory(
bf::path( *ritr ) ) ) {
continue; }
85 result = bf::system_complete( fp2 ).string();
89 }
catch (
const bf::filesystem_error& ) {}
96 string PathResolver::find_file(
const std::string& logical_file_name,
const std::string& search_path,
99 std::string path_list;
102 return ( find_file_from_list( logical_file_name, path_list, search_type ) );
105 std::string PathResolver::find_file_from_list(
const std::string& logical_file_name,
const std::string& search_list,
107 std::string result(
"" );
127 string PathResolver::find_directory(
const std::string& logical_file_name,
const std::string& search_path,
129 std::string path_list;
132 return ( find_directory_from_list( logical_file_name, path_list, search_type ) );
135 string PathResolver::find_directory_from_list(
const std::string& logical_file_name,
const std::string& search_list,
139 if ( !PR_find( logical_file_name, search_list,
PR_directory, search_type, result ) ) { result =
""; }
145 std::string path_list;
146 if ( !
System::getEnv( search_path, path_list ) )
return ( EnvironmentVariableUndefined );
149 boost::split( spv, path_list, boost::is_any_of( path_separator ), boost::token_compress_on );
152 for (
const auto& itr : spv ) {
154 if ( !is_directory(
pp ) ) {
return ( UnknownDirectory ); }
156 }
catch (
const bf::filesystem_error& ) {
return ( UnknownDirectory ); }
162 return PathResolver::find_file( logical_file_name,
"XMLPATH" );
166 return PathResolver::find_file( logical_file_name,
"DATAPATH" );