| # Gaudi Framework, version v22r2 |

Home |  | Generated: Tue May 10 2011

Functions

# Gaudi::Parsers::Utils Namespace Reference

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

## 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 180 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
| ) |  | `[inline]`

Get enviroment variable.

Returns:
  StatusCode::SUCCESS if variable exists

Parameters:

  envName | Enviroment variable name
  envValue | Result = enviroment value

Definition at line 85 of file ParserUtils.cpp.

    {
      return (System::getEnv(envName, envValue)) ? StatusCode::SUCCESS : StatusCode::FAILURE;
    }

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

Check if os is Windows.

Definition at line 167 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.

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

Returns:
  StatusCode::SUCCESS if file was readen succesfully

Parameters:

  name | Path to file
  result | Result string

Definition at line 158 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.

Returns:
  String without enviroment variables

Parameters:

  input | String to process

Definition at line 91 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.

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 123 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;
    }

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines