|
Gaudi Framework, version v22r1 |
| Home | Generated: Mon Feb 28 2011 |
#include <ParserUtils.h>

Public Types | |
| enum | Sign { S_ASSIGN = 0, S_PLUSASSIGN = 1, S_MINUSASSIGN = 2 } |
| typedef std::vector < Gaudi::Parsers::Message > | MessagesStoreT |
| typedef std::map< std::string, double > | UnitsStoreT |
Public Member Functions | |
| Parser (Catalogue &catalogue, std::vector< std::string > &included, std::ostream &m=std::cout) | |
| Default creator. | |
| Parser (Catalogue &catalogue, std::vector< std::string > &included, const std::vector< std::string > &searchPath, std::ostream &m=std::cout) | |
| Constructor from directories list for search files in. | |
| Parser (Catalogue &catalogue, std::vector< std::string > &included, const std::string &searchPath, std::ostream &m=std::cout) | |
| Constructor from directories list for search files in. | |
| StatusCode | parse (const std::string &fileName) |
| Start parse file. | |
| const std::vector< Message > & | messages () |
| Return parser messages. | |
| int | errorsCount () |
| Count of errors. | |
| UnitsStoreT & | units (void) |
| void | matchInclude (const std::string &fileName, const Position &pos) |
| Do actions when include file is matched. | |
| void | matchUnits (const std::string &fileName, const Position &pos) |
| Do actions when units file is matched. | |
| long double | matchUnit (const std::string &unit, const Position &pos) |
| Do actions when we match unit. | |
| void | matchUnitEntry (const std::string &newUnit, double value, const Position &pos) |
| Do actions when we match unit entry in units file. | |
| void | matchAssign (const std::string &objName, const std::string &propName, const Sign &oper, const std::vector< std::string > &vectorValues, const Position &pos, bool isVector) |
| Do actions when we match property. | |
| void | setIsPrint (bool on, const Position &pos) |
| Control printing. | |
| void | setIsPrintOptions (bool on, const Position &pos) |
| Control printing options. | |
Private Member Functions | |
| void | initUnits () |
| Init units. | |
| StatusCode | parseFile (const std::string &fileName, const Position &pos, bool isUnitFile=false) |
| Parse file from another file. | |
| void | resolveReferences () |
| Resolve references. | |
| void | addMessage (const Message::Severity &severity, const Message::Code &code, const std::string &message, const Position &pos) |
| Add message. | |
| std::string | severityName (Message::Severity severity) |
| String representation of severity. | |
| bool | isIncluded (const std::string &fileName) |
| Test if file already included. | |
| std::string | sign (Sign aSign) |
| String representation of sign. | |
| std::string | valueToString (std::vector< std::string > value, bool isVector) |
| String representation of value vector. | |
| bool | isPrint () |
| Print information or not. | |
| void | printOptions () |
| Print options. | |
| std::string | posString (int line, int column) |
| Convert position to string. | |
Private Attributes | |
| bool | m_isPrint |
| bool | m_isPrintOptions |
| std::vector< std::string > | m_searchPath |
| Catalogue & | m_catalogue |
| std::vector< std::string > & | m_included |
| MessagesStoreT | m_messages |
| UnitsStoreT | m_units |
| std::ostream & | m_stream |
Parser controller.
Definition at line 100 of file ParserUtils.h.
| typedef std::vector<Gaudi::Parsers::Message> Gaudi::Parsers::Parser::MessagesStoreT |
Definition at line 103 of file ParserUtils.h.
| typedef std::map<std::string,double> Gaudi::Parsers::Parser::UnitsStoreT |
Definition at line 104 of file ParserUtils.h.
| enum Gaudi::Parsers::Parser::Sign |
Definition at line 105 of file ParserUtils.h.
{
S_ASSIGN = 0 ,
S_PLUSASSIGN = 1 ,
S_MINUSASSIGN = 2
};
| Gaudi::Parsers::Parser::Parser | ( | Catalogue & | catalogue, |
| std::vector< std::string > & | included, | ||
| std::ostream & | m = std::cout |
||
| ) |
Default creator.
Definition at line 35 of file Parser.cpp.
: m_isPrint(true) , m_isPrintOptions(false) , m_catalogue(catalogue) , m_included(included) , m_stream ( m ) { m_searchPath = Gaudi::Parsers::Utils::extractPath("$JOBOPTSEARCHPATH"); initUnits(); }
| Gaudi::Parsers::Parser::Parser | ( | Catalogue & | catalogue, |
| std::vector< std::string > & | included, | ||
| const std::vector< std::string > & | searchPath, | ||
| std::ostream & | m = std::cout |
||
| ) |
Constructor from directories list for search files in.
Definition at line 49 of file Parser.cpp.
: m_isPrint(true) , m_isPrintOptions(false) , m_catalogue(catalogue) , m_included(included) , m_stream ( m ) { m_searchPath = searchPath; initUnits(); }
| Gaudi::Parsers::Parser::Parser | ( | Catalogue & | catalogue, |
| std::vector< std::string > & | included, | ||
| const std::string & | searchPath, | ||
| std::ostream & | m = std::cout |
||
| ) |
Constructor from directories list for search files in.
Definition at line 64 of file Parser.cpp.
: m_isPrint(true) , m_isPrintOptions(false) , m_catalogue(catalogue) , m_included(included) , m_stream ( m ) { m_searchPath = Gaudi::Parsers::Utils::extractPath(searchPath); initUnits(); }
| void Gaudi::Parsers::Parser::addMessage | ( | const Message::Severity & | severity, |
| const Message::Code & | code, | ||
| const std::string & | message, | ||
| const Position & | pos | ||
| ) | [private] |
Add message.
Definition at line 403 of file Parser.cpp.
{
Message result
( severity , code,
boost::str(boost::format("%1%(%2%,%3%) : %4% #%5% : %6%") % pos.fileName()
% pos.line() % pos.column() % severityName(severity) % code
% message));
m_messages.push_back(result);
}
| int Gaudi::Parsers::Parser::errorsCount | ( | ) |
Count of errors.
Definition at line 88 of file Parser.cpp.
{
int result=0;
for ( MessagesStoreT::const_iterator cur=m_messages.begin();
cur!=m_messages.end() ; ++cur)
{ if ( cur->severity() == Message::E_ERROR){ ++result; } }
return result;
}
| void Gaudi::Parsers::Parser::initUnits | ( | ) | [private] |
Init units.
Definition at line 264 of file Parser.cpp.
{
m_units[ "mm" ] = Gaudi::Units::mm ;
m_units[ "cm" ] = Gaudi::Units::cm ;
m_units[ "cm2" ] = Gaudi::Units::cm2 ;
m_units[ "m" ] = Gaudi::Units::m ;
m_units[ "m2" ] = Gaudi::Units::m2 ;
//
m_units[ "ns" ] = Gaudi::Units::nanosecond ;
m_units[ "ps" ] = Gaudi::Units::picosecond ;
m_units[ "fs" ] = Gaudi::Units::picosecond * 0.001 ;
//
m_units[ "MeV" ] = Gaudi::Units::MeV ;
m_units[ "GeV" ] = Gaudi::Units::GeV ;
m_units[ "keV" ] = Gaudi::Units::keV ;
}
| bool Gaudi::Parsers::Parser::isIncluded | ( | const std::string & | fileName ) | [private] |
Test if file already included.
| fileName | File name |
Definition at line 422 of file Parser.cpp.
{
for(std::vector<std::string>::const_iterator cur=m_included.begin();
cur!=m_included.end();cur++)
{ if(fileName==*cur){ return true; } }
return false;
}
| bool Gaudi::Parsers::Parser::isPrint | ( | ) | [inline, private] |
| void Gaudi::Parsers::Parser::matchAssign | ( | const std::string & | objName, |
| const std::string & | propName, | ||
| const Sign & | oper, | ||
| const std::vector< std::string > & | vectorValues, | ||
| const Position & | pos, | ||
| bool | isVector | ||
| ) |
Do actions when we match property.
| objName | Object name |
| propName | Property name |
| oper | Operation ("=","+=","-=") |
| value | String value |
| vectorValues | Vector values |
Definition at line 141 of file Parser.cpp.
{
// --------------------------------------------------------------------------
if(isPrint())
{
m_stream
<< boost::format("%2% %3% %4%;%|72t|%5% %1%")
% posString(pos.line(),pos.column())
% (objName+"."+propName)
% sign(oper)
% valueToString(vectorValue , isVector)
% GPP_COMMENT
<< std::endl ;
}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
if (oper == S_ASSIGN)
{
// ------------------------------------------------------------------------
PropertyEntry* assignProp;
if(isVector){
assignProp = new PropertyEntry(propName,vectorValue,pos);
}else{
assignProp = new PropertyEntry(propName,vectorValue[0],pos);
}
m_catalogue.addProperty(objName,*assignProp);
delete assignProp;
// ------------------------------------------------------------------------
}
else
{
// += or -=
// ------------------------------------------------------------------------
PropertyEntry foundProp;
StatusCode ok;
ok = m_catalogue.findProperty(objName,propName,foundProp);
if (ok.isFailure())
{
foundProp = PropertyEntry(propName,std::vector<std::string>());
}
if(oper == S_PLUSASSIGN)
{
ok = foundProp.addValues(vectorValue);
if(ok.isFailure()){
addMessage
( Message::E_ERROR,
Message::C_CANNOTADDTONOTVECTOR,
boost::str
( boost::format
("Cannot add values to not vector property \"%1%.%2%\"")
% objName % propName),pos);
return;
}
m_catalogue.addProperty(objName,foundProp);
}
// ------------------------------------------------------------------------
if(oper == S_MINUSASSIGN)
{
int count=0;
ok = foundProp.removeValues(vectorValue,count);
if(ok.isFailure()){
addMessage
( Message::E_ERROR,
Message::C_CANNOTREMOVEFROMNOTVECTOR,
boost::str
( boost::format
( "Cannot remove values from not vector property \"%1%.%2%\"" )
% objName % propName),pos);
return;
}
// ----------------------------------------------------------------------
if (count == 0)
{
addMessage
( Message::E_WARNING,
Message::C_ZEROREMOVED,
boost::str
( boost::format
( "Nothing removed from property \"%1%.%2%\"" )
% objName % propName),pos);
}
else
{
m_catalogue.addProperty(objName,foundProp);
}
}
// ------------------------------------------------------------------------
}
}
| void Gaudi::Parsers::Parser::matchInclude | ( | const std::string & | fileName, |
| const Position & | pos | ||
| ) |
Do actions when include file is matched.
| fileName | File to include |
Definition at line 98 of file Parser.cpp.
| long double Gaudi::Parsers::Parser::matchUnit | ( | const std::string & | unit, |
| const Position & | pos | ||
| ) |
Do actions when we match unit.
| unit | Unit name |
Definition at line 107 of file Parser.cpp.
{
UnitsStoreT::const_iterator u = m_units.find(unit);
if ( u==m_units.end())
{
addMessage
( Message::E_ERROR ,
Message::C_UNITNOTFOUND,
boost::str(boost::format("Cann't find unit \"%1%\"")%unit),pos);
return 1;
}
return u->second;
}
| void Gaudi::Parsers::Parser::matchUnitEntry | ( | const std::string & | newUnit, |
| double | value, | ||
| const Position & | pos | ||
| ) |
Do actions when we match unit entry in units file.
| newUnit | New unit |
| value | value of new unit |
| pos | Position of entry |
Definition at line 123 of file Parser.cpp.
| void Gaudi::Parsers::Parser::matchUnits | ( | const std::string & | fileName, |
| const Position & | pos | ||
| ) |
Do actions when units file is matched.
| fileName | File to include |
Definition at line 102 of file Parser.cpp.
| const std::vector<Message>& Gaudi::Parsers::Parser::messages | ( | ) | [inline] |
| StatusCode Gaudi::Parsers::Parser::parse | ( | const std::string & | fileName ) |
Start parse file.
| fileName | File to parse |
Definition at line 78 of file Parser.cpp.
{
m_stream << GPP_COMMENT + std::string(80,'=') << std::endl;
parseFile(fileName,Position()).ignore();
resolveReferences();
if ( m_isPrintOptions ){ printOptions(); }
m_stream << GPP_COMMENT + std::string(80,'=') << std::endl;
return errorsCount()==0?StatusCode::SUCCESS:StatusCode::FAILURE;
}
| StatusCode Gaudi::Parsers::Parser::parseFile | ( | const std::string & | fileName, |
| const Position & | pos, | ||
| bool | isUnitFile = false |
||
| ) | [private] |
Parse file from another file.
| fileName | File to parse Information about from what file we call parsing of file |
Definition at line 282 of file Parser.cpp.
{
StatusCode ok;
std::vector<std::string> sp = m_searchPath;
if(pos.fileName().length()>0){
// Add current file directory to search path
sp.insert(sp.begin(),
fs::path(pos.fileName(),fs::native).branch_path()
.native_directory_string());
}
std::string fileToParse;
ok = Gaudi::Parsers::Utils::searchFile(fileName,true,sp,fileToParse);
if(ok.isFailure()){
addMessage( Message::E_ERROR, Message::C_FILENOTFOUND,
boost::str(boost::format("Couldn't find file \"%1%\"") % fileName),pos);
return StatusCode::FAILURE;
}
ok = isIncluded(fileToParse);
if(ok.isSuccess())
{
const std::string _msg =
( boost::format("Skip already included file \"%1%\"") % fileToParse ).str() ;
addMessage ( Message::E_WARNING , Message::C_OK , _msg , pos ) ;
if ( isPrint() )
{
m_stream
<< boost::format("%3% skip already included file \"%2%\" %|78t|%1%")
% posString(pos.line(), pos.column())
% fileToParse
% GPP_COMMENT
<< std::endl ;
}
return StatusCode::SUCCESS;
}
std::string input;
ok = Gaudi::Parsers::Utils::readFile(fileToParse,input);
if(ok.isFailure())
{
addMessage
( Message::E_ERROR, Message::C_FILENOTOPENED,
boost::str
(boost::format("Couldn't open file \"%1%\"") % fileToParse),pos);
return StatusCode::FAILURE;
}
m_included.push_back(fileToParse);
IteratorT beginpos(input.begin(), input.end(), fileToParse);
IteratorT endpos;
boost::spirit::parse_info<IteratorT> info;
SkipperGrammar grSkipper;
if(!isUnitsFile){
m_stream
<< boost::format("%3% include \"%2%\" %|78t|%1%")
% posString(pos.line(), pos.column())
% fileToParse
% GPP_COMMENT
<< std::endl ;
ParserGrammar grParser(this);
info = boost::spirit::parse(beginpos, endpos, grParser >> end_p,grSkipper);
}else{
m_stream
<< boost::format("#units \"%3%\" %|72t|%2% %1%")
% posString(pos.line(), pos.column())
% GPP_COMMENT
% fileToParse
<< std::endl ;
UnitsFileGrammar grParser(this);
info = boost::spirit::parse(beginpos, endpos, grParser >> end_p,grSkipper);
}
boost::spirit::file_position stoppos = info.stop.get_position();
if (!info.full) {
addMessage(Message::E_ERROR, Message::C_SYNTAXERROR,
"Syntax error",Position(stoppos.file,stoppos.line,stoppos.column));
return StatusCode::FAILURE;
}
{
std::string _msg =
( boost::format("Parsed file \"%2%\" %|78t|%1%")
% posString(stoppos.line, stoppos.column)
% fileToParse ) .str() ;
addMessage ( Message::E_VERBOSE ,
Message::C_OK ,
_msg ,
Position(stoppos.file,stoppos.line,stoppos.column) ) ;
if ( isPrint() )
{
m_stream
<< boost::format("%3% end \"%2%\" %|78t|%1%")
% posString(stoppos.line, stoppos.column)
% fileToParse
% GPP_COMMENT
<< std::endl ;
}
}
return StatusCode::SUCCESS;
}
| std::string Gaudi::Parsers::Parser::posString | ( | int | line, |
| int | column | ||
| ) | [private] |
Convert position to string.
| line | Line |
| column | Column |
Definition at line 545 of file Parser.cpp.
{ return boost::str(boost::format("(%1%,%2%)") % line % column); }
| void Gaudi::Parsers::Parser::printOptions | ( | ) | [private] |
| void Gaudi::Parsers::Parser::resolveReferences | ( | ) | [private] |
Resolve references.
Definition at line 434 of file Parser.cpp.
{
Catalogue::CatalogueT cat = m_catalogue.catalogue();
// ----------------------------------------------------------------------------
for( Catalogue::CatalogueT::const_iterator curObj = cat.begin();
curObj!=cat.end();curObj++)
{
std::string objName = curObj->first;
// ------------------------------------------------------------------------
for( std::vector<PropertyEntry>::const_iterator curProp =
curObj->second.begin();curProp != curObj->second.end(); curProp++)
{
std::string value = curProp->value();
if ( (value.length()>0) && (value[0]=='@'))
{
// --------------------------------------------------------------------
std::vector<std::string> objAndProp;
std::string refprop(value.begin()+1,value.end());
ba::split(objAndProp,
refprop,
ba::is_any_of("."));
PropertyEntry foundProperty;
StatusCode ok;
ok = m_catalogue.findProperty(objAndProp[0],objAndProp[1],
foundProperty);
if(ok.isFailure())
{
addMessage
( Message::E_ERROR,
Message::C_PROPERTYNOTFOUND,
boost::str(boost::format("Cannot find property \"%1%.%2%\"")
% objAndProp[0] % objAndProp[1]),curProp->position());
}
else
{
// -------------------------------------------------------------------
if((ba::to_lower_copy(objAndProp[0]) == objName)
&&
(ba::to_lower_copy(objAndProp[1])
== curProp->name()))
{
// ----------------------------------------------------------------
addMessage
( Message::E_ERROR,
Message::C_BADREFERENCE,
boost::str(boost::format("Reference to self \"%1%.%2%\"")
% objAndProp[0] % objAndProp[1]),curProp->position());
// ----------------------------------------------------------------
}
else
{
PropertyEntry property = foundProperty;
property.setName(curProp->name());
m_catalogue.addProperty(objName,property);
}
// ------------------------------------------------------------------
}
// --------------------------------------------------------------------
}
}
// ------------------------------------------------------------------------
}
}
| void Gaudi::Parsers::Parser::setIsPrint | ( | bool | on, |
| const Position & | pos | ||
| ) |
Control printing.
Definition at line 237 of file Parser.cpp.
{
// ignore the printout if the full print is activated
if ( on && m_isPrintOptions ) { return ; }
m_isPrint = on;
m_stream
<< boost::format("%3% printing is %2% %|78t|%1%")
% posString(pos.line(),pos.column())
% (on?"ON":"OFF")
% GPP_COMMENT
<< std::endl ;
}
| void Gaudi::Parsers::Parser::setIsPrintOptions | ( | bool | on, |
| const Position & | pos | ||
| ) |
Control printing options.
Definition at line 251 of file Parser.cpp.
{
m_isPrintOptions = on;
m_stream
<< boost::format ("%3% printing options is %2% %|78t|%1%")
% posString(pos.line(),pos.column())
% (on?"ON":"OFF")
% GPP_COMMENT
<< std::endl ;
// deactivate the printout if the print of all options is activated
if ( m_isPrintOptions && m_isPrint ) { setIsPrint ( false , pos ) ; }
}
| std::string Gaudi::Parsers::Parser::severityName | ( | Message::Severity | severity ) | [private] |
String representation of severity.
| severity | Severity |
Definition at line 386 of file Parser.cpp.
{
switch(severity)
{
case Message::E_ERROR :
return "ERROR" ;
case Message::E_WARNING :
return "WARNING" ;
case Message::E_NOTICE :
return "NOTICE" ;
case Message::E_VERBOSE :
return "VERBOSE" ;
default:
return "UNDEFINED" ;
}
}
| std::string Gaudi::Parsers::Parser::sign | ( | Sign | aSign ) | [private] |
String representation of sign.
Definition at line 500 of file Parser.cpp.
{
switch(aSign)
{
case S_ASSIGN:
return "=";
case S_PLUSASSIGN:
return "+=";
case S_MINUSASSIGN:
return "-=";
default:
return "unknown_operation";
}
}
| UnitsStoreT& Gaudi::Parsers::Parser::units | ( | void | ) | [inline] |
Definition at line 131 of file ParserUtils.h.
{return m_units;}
| std::string Gaudi::Parsers::Parser::valueToString | ( | std::vector< std::string > | value, |
| bool | isVector | ||
| ) | [private] |
String representation of value vector.
Definition at line 518 of file Parser.cpp.
{
if ( !isVector){ return value[0]; }
//
std::string result;
std::string delim;
result+=" [ ";
for ( std::vector<std::string>::const_iterator cur = value.begin();
cur != value.end(); cur++ )
{
result += delim + *cur;
delim = " , ";
}
return result + " ] ";
}
Catalogue& Gaudi::Parsers::Parser::m_catalogue [private] |
Definition at line 178 of file ParserUtils.h.
std::vector<std::string>& Gaudi::Parsers::Parser::m_included [private] |
Definition at line 179 of file ParserUtils.h.
bool Gaudi::Parsers::Parser::m_isPrint [private] |
Definition at line 175 of file ParserUtils.h.
bool Gaudi::Parsers::Parser::m_isPrintOptions [private] |
Definition at line 176 of file ParserUtils.h.
MessagesStoreT Gaudi::Parsers::Parser::m_messages [private] |
Definition at line 180 of file ParserUtils.h.
std::vector<std::string> Gaudi::Parsers::Parser::m_searchPath [private] |
Definition at line 177 of file ParserUtils.h.
std::ostream& Gaudi::Parsers::Parser::m_stream [private] |
Definition at line 182 of file ParserUtils.h.
UnitsStoreT Gaudi::Parsers::Parser::m_units [private] |
Definition at line 181 of file ParserUtils.h.