BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
PathResolver Class Reference

#include <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 6 of file PathResolver.h.

Member Enumeration Documentation

◆ SearchPathStatus

Enumerator
Ok 
EnvironmentVariableUndefined 
UnknownDirectory 

Definition at line 8 of file PathResolver.h.

◆ SearchType

Enumerator
LocalSearch 
RecursiveSearch 

Definition at line 10 of file PathResolver.h.

Member Function Documentation

◆ check_search_path()

PathResolver::SearchPathStatus 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 512 of file PathResolver.cxx.

512 {
513 const char* path_env = ::getenv( search_path.c_str() );
514
515 if ( path_env == 0 ) return ( EnvironmentVariableUndefined );
516
517#ifdef WIN32
518 static const char path_separator = ';';
519#else
520 static const char path_separator = ':';
521#endif
522
523 std::string path_list( path_env );
524
525 std::string::size_type pos = 0;
526
527 for ( int i = 0;; i++ )
528 {
529 bool ending = false;
530
531 std::string::size_type next = path_list.find( path_separator, pos );
532
533 std::string path = path_list.substr( pos, next - pos );
534
535 if ( next == std::string::npos )
536 {
537 path = path_list.substr( pos );
538 ending = true;
539 }
540 else
541 {
542 path = path_list.substr( pos, next - pos );
543 pos = next + 1;
544 }
545
546 std::string real_name = "";
547
548 if ( !PR_test_exist( path, real_name, PR_directory ) ) { return ( UnknownDirectory ); }
549
550 if ( ending ) break;
551 }
552
553 return ( Ok );
554}
@ PR_directory
Index next(Index i)

Referenced by PathResolverCheckSearchPath().

◆ find_directory()

std::string 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 487 of file PathResolver.cxx.

489 {
490 const char* path_env = ::getenv( search_path.c_str() );
491
492 std::string path_list;
493
494 if ( path_env != 0 ) { path_list = path_env; }
495
496 return ( find_directory_from_list( logical_file_name, path_list, search_type ) );
497}
static std::string find_directory_from_list(const std::string &logical_file_name, const std::string &search_list, SearchType search_type=LocalSearch)

Referenced by PathResolverFindDirectory().

◆ find_directory_from_list()

std::string 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 499 of file PathResolver.cxx.

501 {
502 std::string result;
503
504 if ( !PR_find_from_list( logical_file_name, search_list, PR_directory, search_type,
505 result ) )
506 { result = ""; }
507
508 return ( result );
509}

Referenced by find_directory(), and PathResolverFindDirectoryFromList().

◆ find_file()

std::string 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 464 of file PathResolver.cxx.

465 {
466 const char* path_env = ::getenv( search_path.c_str() );
467
468 std::string path_list;
469
470 if ( path_env != 0 ) { path_list = path_env; }
471
472 return ( find_file_from_list( logical_file_name, path_list, search_type ) );
473}
static std::string find_file_from_list(const std::string &logical_file_name, const std::string &search_list, SearchType search_type=LocalSearch)

Referenced by main(), PathResolverFindDataFile(), PathResolverFindFile(), and PathResolverFindXMLFile().

◆ find_file_from_list()

std::string 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 475 of file PathResolver.cxx.

477 {
478 std::string result;
479
480 if ( !PR_find_from_list( logical_file_name, search_list, PR_regular_file, search_type,
481 result ) )
482 { result = ""; }
483
484 return ( result );
485}
@ PR_regular_file

Referenced by find_file(), and PathResolverFindFileFromList().


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