/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

OptionParser.cc
Go to the documentation of this file.
00001 #include "LafKernel/OptionParser.h"
00002 #include "LafKernel/LafException.h"
00003 #include "LafKernel/LafLog.h"
00004 #include "Parsers/ParserUtils.h"
00005 #include "Parsers/Catalogue.h"
00006 
00007 OptionParser* OptionParser::_instance = 0;
00008 
00009 OptionParser* OptionParser::instance(char* fname)
00010 {
00011     if ( _instance == 0 ) {
00012         _instance = new OptionParser(fname);
00013     }
00014     return _instance;
00015 }
00016 
00017 bool OptionParser::addOption(const std::string& client, const std::string& name, const std::string& value)
00018 {
00019     std::string stringResult;
00020     std::vector<std::string> vectorResult;
00021     bool ok = Gaudi::Parsers::Utils::parseValue(value, stringResult, vectorResult);
00022     if ( ok ) {
00023         bool isVector = (vectorResult.size()>0) || (stringResult=="{}");
00024         if ( isVector ) {
00025             Gaudi::Parsers::PropertyEntry property(name, vectorResult);
00026             if ( _instance->m_entries->findProperty(client, name, property, false) ) {
00027                 int count = 0;
00028                 property.removeValues(vectorResult, count);
00029                 property.addValues(vectorResult);
00030             }
00031             _instance->m_entries->addProperty(client, property);
00032         }
00033         return true;
00034     }
00035     return false;
00036 }
00037 
00038 OptionParser::OptionParser(char* fname)
00039     : m_name("OptionParser")
00040 {
00041     m_entries = new Gaudi::Parsers::Catalogue();
00042     std::vector<std::string> m_included;
00043     Gaudi::Parsers::Parser parser(*m_entries, m_included);
00044 
00045     bool sc = parser.parse( fname );
00046     if ( !sc ) {
00047         using Gaudi::Parsers::Message;
00048         const std::vector<Message>& messages = parser.messages();
00049         for (std::vector<Message>::const_iterator it = messages.begin(); it != messages.end(); ++it ) {
00050             if ( it->severity() == Gaudi::Parsers::Message::E_ERROR ) {
00051                 LogError << it->message() << std::endl;
00052             }
00053         }
00054         delete m_entries;
00055         throw LafException("OptionParser: error while parsing option file");
00056     }
00057 }
00058 
00059 OptionParser::~OptionParser()
00060 {
00061     delete m_entries;
00062 }
00063 
00064 bool OptionParser::validate()
00065 {
00066     Gaudi::Parsers::Catalogue::CatalogueT left = m_entries->catalogue();
00067     if ( ! left.empty() ) {
00068         LogError << "INVALID OPTIONS FOUND." << std::endl;
00069         std::cout << "Attention: following line(s) in your configuration file is(are) not recognized:" << std::endl;
00070         m_entries->print(std::cout);
00071         std::cout << "Please ensure your spell is right, otherwise remove the useless settings!" << std::endl;
00072         return false;
00073     }
00074     return true;
00075 }
00076 
00077 bool OptionParser::getValueStr(const std::string& client, const std::string& name, std::string& value)
00078 {
00079     Gaudi::Parsers::PropertyEntry property;
00080     if ( m_entries->findProperty(client, name, property, true) ) {
00081         value = property.value();
00082         return true;
00083     }
00084     return false;
00085 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:50:18 for LafKernel by doxygen 1.7.4