The Gaudi Framework
master (bdbe7744)
Toggle main menu visibility
Loading...
Searching...
No Matches
DirSearchPath.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
12
#include <algorithm>
/* find */
13
#include <iostream>
14
#include <list>
15
#ifdef __ICC
16
// disable icc warning #279: controlling expression is constant
17
// ... a lot of noise produced by the boost/filesystem/operations.hpp
18
# pragma warning( disable : 279 )
19
#endif
20
#include <
GaudiKernel/DirSearchPath.h
>
21
#include <boost/filesystem/operations.hpp>
22
#include <boost/tokenizer.hpp>
23
24
using namespace
std
;
25
26
using
boost::filesystem::exists;
27
using
boost::filesystem::filesystem_error;
28
using
boost::filesystem::is_directory;
29
30
using
boost::char_separator;
31
using
boost::tokenizer;
32
33
// constructors
34
DirSearchPath::DirSearchPath
(
const
std::string& stringifiedPath,
const
char
* separator ) {
35
addCWD
();
// FIXME is this a good idea?
36
37
typedef
tokenizer<char_separator<char>> Tokenizer;
38
39
Tokenizer tok( stringifiedPath, char_separator<char>( separator ) );
40
41
// add names to dir container, filtering dir names to remove invalid ones
42
// notice how we iterate over all tokens even if there is an illegal one
43
auto
it = tok.begin();
44
while
( it != tok.end() ) {
45
try
{
46
path
p( *( it++ ) );
47
add
( p );
48
}
catch
( boost::filesystem::filesystem_error&
/*err*/
) {}
49
}
50
}
51
52
// modifiers
53
bool
DirSearchPath::addCWD
() {
return
add
( boost::filesystem::current_path() ); }
54
55
bool
DirSearchPath::add
(
const
path
& dir ) {
56
bool
dirExist(
existsDir
( dir ) );
57
// add dir to path even if dir does not (yet) exist,
58
// but don't add twice same dir
59
if
(
m_dirs
.end() == std::find_if(
m_dirs
.begin(),
m_dirs
.end(),
eqPath
( dir ) ) )
m_dirs
.push_back( dir );
60
return
dirExist;
61
}
62
63
// accessors
64
bool
DirSearchPath::find
(
const
string
& fileName,
string
& fullFileName )
const
{
65
bool
rc(
false
);
66
try
{
67
path
fileFound;
68
if
( ( rc =
find
(
path
( fileName ), fileFound ) ) ) fullFileName = fileFound.string();
69
}
catch
( ... ) {}
70
return
rc;
71
}
72
73
// accessors
74
bool
DirSearchPath::find
(
const
path
& file,
path
& fileFound )
const
{
75
bool
rc(
false
);
76
for
(
const
auto
& iDir :
m_dirs
) {
77
path
full{ iDir / file };
78
if
( exists( full ) ) {
79
fileFound = full;
80
rc =
true
;
81
break
;
82
}
83
}
84
return
rc;
85
}
86
87
// accessors
88
std::list<DirSearchPath::path>
DirSearchPath::find_all
(
const
path
& file )
const
{
89
std::list<path> found;
90
for
(
const
auto
& iDir :
m_dirs
) {
91
path
full{ iDir / file };
92
if
( exists( full ) ) found.push_back( full );
93
}
94
return
found;
95
}
96
97
// helpers
98
bool
DirSearchPath::existsDir
(
const
std::string& dirName ) {
99
bool
rc(
false
);
100
try
{
101
rc = is_directory(
path
( dirName ) );
102
}
catch
( ... ) {}
103
return
rc;
104
}
105
bool
DirSearchPath::existsDir
(
const
path
& dir ) {
return
( exists( dir ) && is_directory( dir ) ); }
DirSearchPath.h
search for files in a list of directories
DirSearchPath::DirSearchPath
DirSearchPath()
Definition
DirSearchPath.h:34
DirSearchPath::find_all
std::list< path > find_all(const path &file) const
returns lists of files found in search path.
Definition
DirSearchPath.cpp:88
DirSearchPath::existsDir
static bool existsDir(const std::string &dirName)
check dirName is valid
Definition
DirSearchPath.cpp:98
DirSearchPath::path
boost::filesystem::path path
Definition
DirSearchPath.h:30
DirSearchPath::addCWD
bool addCWD()
add current work dir (*nix pwd) to path
Definition
DirSearchPath.cpp:53
DirSearchPath::add
bool add(const path &dir)
Definition
DirSearchPath.cpp:55
DirSearchPath::find
bool find(const std::string &fileName, std::string &fullFileName) const
returns a flag if fileName found in search path, and sets ref to fully qualified file name (in native...
Definition
DirSearchPath.cpp:64
DirSearchPath::m_dirs
std::vector< path > m_dirs
the dir container
Definition
DirSearchPath.h:84
std
STL namespace.
DirSearchPath::eqPath
name
Definition
DirSearchPath.h:66
GaudiKernel
src
Lib
DirSearchPath.cpp
Generated on
for The Gaudi Framework by
1.17.0