| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- Namespace List
- Namespace Members

# Gaudi::Parsers::Utils Namespace Reference

## Functions
StatusCode | getEnv (const std::string &envName, std::string &envValue)
| Get enviroment variable.
std::string | removeEnvironment (const std::string &input)
| Remove enviroment variables from string.
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.
StatusCode | readFile (const std::string &name, std::string &result)
| Read file to 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 | parseValue (const std::string &input, std::string &stringResult, std::vector< std::string > &vectorResult)
| Try to recognize string as value of job options type.

## Function Documentation

std::vector< std::string > Gaudi::Parsers::Utils::extractPath | ( | const std::string & | input,
|  | bool | removeEnv = `true` |
| ) |  |  |

Extract paths separeted by '.

' or ':' or ';'

Returns:
  List of paths

Parameters:

  | input | String to process
  | removeEnv | Remove enviroment variables?

Definition at line 182 of file ParserUtils.cpp.

References std::basic_string< _CharT, _Traits, _Alloc >::c_str(), pathSeparator(), std::vector< _Tp, _Alloc >::push_back(), and removeEnvironment().

Referenced by Gaudi::Parsers::Parser::Parser().

    00183 {
    00184   std::string in = removeEnv?removeEnvironment(input):input;
    00185   std::string separator = ","+pathSeparator();
    00186   typedef boost::tokenizer<boost::char_separator<char> > Tokenizer;
    00187   std::vector<std::string> result;
    00188   Tokenizer tok(in, boost::char_separator<char>(separator.c_str()));
    00189   Tokenizer::iterator it =tok.begin();
    00190   while(it!=tok.end())
    00191   {
    00192     if(it->length()>0){ result.push_back(*it); }
    00193     it++;
    00194   }
    00195   return result;
    00196 }

StatusCode Gaudi::Parsers::Utils::getEnv | ( | const std::string & | envName,
|  | std::string & | envValue |
| ) |  |  |

Get enviroment variable.

Returns:
  StatusCode::SUCCESS if variable exists

Parameters:

  | envName | Enviroment variable name
  | envValue | Result = enviroment value

Definition at line 84 of file ParserUtils.cpp.

References std::basic_string< _CharT, _Traits, _Alloc >::c_str(), StatusCode::FAILURE, and StatusCode::SUCCESS.

Referenced by removeEnvironment().

    00085 {
    00086   char* envch = getenv(envName.c_str());
    00087         if(envch==NULL) { return StatusCode::FAILURE; }
    00088         envValue = envch;
    00089   return StatusCode::SUCCESS;
    00090 }

bool Gaudi::Parsers::Utils::isWin | ( |  | ) |

Check if os is Windows.

Definition at line 169 of file ParserUtils.cpp.

Referenced by Gaudi::Parsers::ParserGrammar::matchPlatform(), and pathSeparator().

    00170 {
    00171 #ifdef _WIN32
    00172   return true;
    00173 #else
    00174   return false;
    00175 #endif
    00176 }

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.

Returns:
  StatusCode::SUCCESS if string is recognized

Parameters:

  | input | string
  | stringResult | String representation of value
  | vectorResult | Result vector. Values represented as strings

Definition at line 199 of file ParserUtils.cpp.

References std::basic_string< _CharT, _Traits, _Alloc >::begin(), std::basic_string< _CharT, _Traits, _Alloc >::end(), StatusCode::FAILURE, Gaudi::Parsers::parse(), and StatusCode::SUCCESS.

Referenced by Gaudi::Parsers::Catalogue::addProperty().

    00202 {
    00203
    00204   typedef
    00205     boost::spirit::position_iterator<std::string::const_iterator> IteratorT;
    00206
    00207   Gaudi::Parsers::ValueGrammar   grValue;
    00208   Gaudi::Parsers::SkipperGrammar grSkipper;
    00209   IteratorT beginpos(input.begin(), input.end(), "");
    00210   IteratorT endpos;
    00211   boost::tuple<std::string, std::vector<std::string> > result;
    00212   boost::spirit::parse_info<IteratorT> info =
    00213     boost::spirit::parse
    00214     (beginpos, endpos, grValue[var(result)=arg1] ,grSkipper);
    00215   if (!info.full){ return StatusCode::FAILURE; }
    00216   stringResult = result.get<0>();
    00217   vectorResult = result.get<1>();
    00218   return StatusCode::SUCCESS;
    00219 }

std::string Gaudi::Parsers::Utils::pathSeparator | ( |  | ) |

Get path separator.

Definition at line 178 of file ParserUtils.cpp.

References isWin().

Referenced by extractPath().

    00179 { return Gaudi::Parsers::Utils::isWin()?";":":"; }

StatusCode Gaudi::Parsers::Utils::readFile | ( | const std::string & | name,
|  | std::string & | result |
| ) |  |  |

Read file to string.

Returns:
  StatusCode::SUCCESS if file was readen succesfully

Parameters:

  | name | Path to file
  | result | Result string

Definition at line 160 of file ParserUtils.cpp.

References c, std::basic_string< _CharT, _Traits, _Alloc >::c_str(), StatusCode::FAILURE, name, and StatusCode::SUCCESS.

Referenced by Gaudi::Parsers::Parser::parseFile().

    00161 {
    00162   std::ifstream in(name.c_str());
    00163   if (!in.is_open()) { return StatusCode::FAILURE; }
    00164   char c;
    00165   while (!in.get(c).eof()) { result += c; }
    00166   return StatusCode::SUCCESS;
    00167 }

std::string Gaudi::Parsers::Utils::removeEnvironment | ( | const std::string & | input | ) |

Remove enviroment variables from string.

Returns:
  String without enviroment variables

Parameters:

  | input | String to process

Definition at line 93 of file ParserUtils.cpp.

References std::basic_string< _CharT, _Traits, _Alloc >::begin(), std::basic_string< _CharT, _Traits, _Alloc >::end(), getEnv(), StatusCode::isSuccess(), std::basic_string< _CharT, _Traits, _Alloc >::length(), and second.

Referenced by extractPath(), Gaudi::Parsers::PropertyEntry::removeEnv(), and searchFile().

    00093                                                           {
    00094   std::string result=input;// result
    00095
    00096   const char* re = "\\$(([A-Za-z0-9_]+)|\\(([A-Za-z0-9_]+)\\))";
    00097   std::string::const_iterator start, end;
    00098   boost::regex expression(re);
    00099   start = input.begin();
    00100   end = input.end();
    00101   boost::match_results<std::string::const_iterator> what;
    00102   boost::match_flag_type flags = boost::match_default;
    00103   while ( boost::regex_search(start, end, what, expression, flags ) )
    00104   {
    00105     std::string var,env;
    00106     std::string matched(what[0].first,what[0].second);
    00107     std::string v1(what[2].first,what[2].second);
    00108     std::string v2(what[3].first,what[3].second);
    00109
    00110     if ( v1.length()>0){ var = v1; }
    00111     else { var = v2; }
    00112
    00113     StatusCode ok = getEnv(var, env);
    00114     if(ok.isSuccess())
    00115     { boost::algorithm::replace_first(result,matched, env); }
    00116     start = what[0].second;
    00117     // update flags:
    00118     flags |= boost::match_prev_avail;
    00119     flags |= boost::match_not_bob;
    00120   }
    00121   return result;
    00122 }

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.

Parameters:

  | 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.

References std::vector< _Tp, _Alloc >::begin(), std::vector< _Tp, _Alloc >::end(), StatusCode::FAILURE, std::vector< _Tp, _Alloc >::insert(), Gaudi::Utils::Histos::path(), removeEnvironment(), and StatusCode::SUCCESS.

Referenced by Gaudi::Parsers::Parser::parseFile().

    00129 {
    00130         std::string result;
    00131   try {
    00132     fs::path givenPath(removeEnvironment(fileInput),fs::native);
    00133     //std::cout<<"Given path="<<givenPath.string()<<std::endl;
    00134     fs::path currentPath = givenPath;
    00135     std::vector<std::string> sdirs = dirs;
    00136     if(addCurrent){
    00137       sdirs.insert(sdirs.begin(),
    00138                    fs::initial_path().native_directory_string());
    00139     }
    00140     std::vector<std::string>::const_iterator current =
    00141       sdirs.begin(),end=sdirs.end();
    00142     while(1) {
    00143       if(fs::exists(currentPath)) {
    00144         fileOutput = currentPath.native_directory_string();
    00145         return StatusCode::SUCCESS;
    00146       }
    00147       if(current!=end) {
    00148         std::string _n = *current;
    00149         currentPath = fs::path(_n, fs::native)/givenPath;
    00150       }else{
    00151         return StatusCode::FAILURE;
    00152       }
    00153       ++current;
    00154     }
    00155   }catch(...) {}
    00156   return StatusCode::FAILURE;
    00157 }