|
Gaudi Framework, version v22r1 |
| Home | Generated: Mon Feb 28 2011 |
Functions | |
| StatusCode | getEnv (const std::string &envName, std::string &envValue) |
| Get enviroment variable. | |
| StatusCode | searchFile (const std::string &fileInput, bool addCurrent, const std::vector< std::string > &dirs, std::string &fileOutput) |
| Search file StatusCode::SUCCESS if file was founded. | |
| std::string | removeEnvironment (const std::string &input) |
| Remove enviroment variables from string. | |
| bool | isWin () |
| Check if os is Windows. | |
| std::string | pathSeparator () |
| Get path separator. | |
| std::vector< std::string > | extractPath (const std::string &input, bool removeEnv=true) |
| Extract paths separeted by '. | |
| StatusCode | readFile (const std::string &name, std::string &result) |
| Read file to string. | |
| StatusCode | parseValue (const std::string &input, std::string &stringResult, std::vector< std::string > &vectorResult) |
| Try to recognize string as value of job options type. | |
| std::vector< std::string > Gaudi::Parsers::Utils::extractPath | ( | const std::string & | input, |
| bool | removeEnv = true |
||
| ) |
Extract paths separeted by '.
' or ':' or ';'
| input | String to process |
| removeEnv | Remove enviroment variables? |
Definition at line 182 of file ParserUtils.cpp.
{
std::string in = removeEnv?removeEnvironment(input):input;
std::string separator = ","+pathSeparator();
typedef boost::tokenizer<boost::char_separator<char> > Tokenizer;
std::vector<std::string> result;
Tokenizer tok(in, boost::char_separator<char>(separator.c_str()));
Tokenizer::iterator it =tok.begin();
while(it!=tok.end())
{
if(it->length()>0){ result.push_back(*it); }
it++;
}
return result;
}
| StatusCode Gaudi::Parsers::Utils::getEnv | ( | const std::string & | envName, |
| std::string & | envValue | ||
| ) |
Get enviroment variable.
| envName | Enviroment variable name |
| envValue | Result = enviroment value |
Definition at line 84 of file ParserUtils.cpp.
{
char* envch = getenv(envName.c_str());
if(envch==NULL) { return StatusCode::FAILURE; }
envValue = envch;
return StatusCode::SUCCESS;
}
| bool Gaudi::Parsers::Utils::isWin | ( | ) |
Check if os is Windows.
Definition at line 169 of file ParserUtils.cpp.
{
#ifdef _WIN32
return true;
#else
return false;
#endif
}
| StatusCode Gaudi::Parsers::Utils::parseValue | ( | const std::string & | input, |
| std::string & | stringResult, | ||
| std::vector< std::string > & | vectorResult | ||
| ) |
Try to recognize string as value of job options type.
| input | string |
| stringResult | String representation of value |
| vectorResult | Result vector. Values represented as strings |
Definition at line 199 of file ParserUtils.cpp.
{
typedef
boost::spirit::position_iterator<std::string::const_iterator> IteratorT;
Gaudi::Parsers::ValueGrammar grValue;
Gaudi::Parsers::SkipperGrammar grSkipper;
IteratorT beginpos(input.begin(), input.end(), "");
IteratorT endpos;
boost::tuple<std::string, std::vector<std::string> > result;
boost::spirit::parse_info<IteratorT> info =
boost::spirit::parse
(beginpos, endpos, grValue[var(result)=arg1] ,grSkipper);
if (!info.full){ return StatusCode::FAILURE; }
stringResult = result.get<0>();
vectorResult = result.get<1>();
return StatusCode::SUCCESS;
}
| std::string Gaudi::Parsers::Utils::pathSeparator | ( | ) |
Get path separator.
Definition at line 178 of file ParserUtils.cpp.
{ return Gaudi::Parsers::Utils::isWin()?";":":"; }
| StatusCode Gaudi::Parsers::Utils::readFile | ( | const std::string & | name, |
| std::string & | result | ||
| ) |
Read file to string.
| name | Path to file |
| result | Result string |
Definition at line 160 of file ParserUtils.cpp.
{
std::ifstream in(name.c_str());
if (!in.is_open()) { return StatusCode::FAILURE; }
char c;
while (!in.get(c).eof()) { result += c; }
return StatusCode::SUCCESS;
}
| std::string Gaudi::Parsers::Utils::removeEnvironment | ( | const std::string & | input ) |
Remove enviroment variables from string.
| input | String to process |
Definition at line 93 of file ParserUtils.cpp.
{
std::string result=input;// result
const char* re = "\\$(([A-Za-z0-9_]+)|\\(([A-Za-z0-9_]+)\\))";
std::string::const_iterator start, end;
boost::regex expression(re);
start = input.begin();
end = input.end();
boost::match_results<std::string::const_iterator> what;
boost::match_flag_type flags = boost::match_default;
while ( boost::regex_search(start, end, what, expression, flags ) )
{
std::string var,env;
std::string matched(what[0].first,what[0].second);
std::string v1(what[2].first,what[2].second);
std::string v2(what[3].first,what[3].second);
if ( v1.length()>0){ var = v1; }
else { var = v2; }
StatusCode ok = getEnv(var, env);
if(ok.isSuccess())
{ boost::algorithm::replace_first(result,matched, env); }
start = what[0].second;
// update flags:
flags |= boost::match_prev_avail;
flags |= boost::match_not_bob;
}
return result;
}
| StatusCode Gaudi::Parsers::Utils::searchFile | ( | const std::string & | fileInput, |
| bool | addCurrent, | ||
| const std::vector< std::string > & | dirs, | ||
| std::string & | fileOutput | ||
| ) |
Search file StatusCode::SUCCESS if file was founded.
| fileInput | Path to file which can be not completed |
| addCurrent | Add current program directory? |
| dirs | Directories in which we can search file |
| fileOutPut | Result - absolute path to file |
Definition at line 125 of file ParserUtils.cpp.
{
std::string result;
try {
fs::path givenPath(removeEnvironment(fileInput),fs::native);
//std::cout<<"Given path="<<givenPath.string()<<std::endl;
fs::path currentPath = givenPath;
std::vector<std::string> sdirs = dirs;
if(addCurrent){
sdirs.insert(sdirs.begin(),
fs::initial_path().native_directory_string());
}
std::vector<std::string>::const_iterator current =
sdirs.begin(),end=sdirs.end();
while(1) {
if(fs::exists(currentPath)) {
fileOutput = currentPath.native_directory_string();
return StatusCode::SUCCESS;
}
if(current!=end) {
std::string _n = *current;
currentPath = fs::path(_n, fs::native)/givenPath;
}else{
return StatusCode::FAILURE;
}
++current;
}
}catch(...) {}
return StatusCode::FAILURE;
}