bool KeywordGenerator::updateSource(const KeywordLoader& loader , const std::string& sourceFile ) const { std::stringstream newSource; newSource << sourceHeader << std::endl; newSource << "void addDefaultKeywords(Parser& p);" << std::endl << "void addDefaultKeywords(Parser& p) {" << std::endl; for( auto iter = loader.keyword_begin(); iter != loader.keyword_end(); ++iter ) { newSource << "p.addKeyword< ParserKeywords::" << iter->second->className() << " >();" << std::endl; } newSource << "}" << std::endl; for (auto iter = loader.keyword_begin(); iter != loader.keyword_end(); ++iter) { std::shared_ptr<ParserKeyword> keyword = (*iter).second; newSource << keyword->createCode() << std::endl; } newSource << "}" << std::endl; newSource << "void Parser::addDefaultKeywords() {" << std::endl << "Opm::ParserKeywords::addDefaultKeywords(*this);" << std::endl << "}}" << std::endl; return write_file( newSource, sourceFile, m_verbose, "source" ); }
bool KeywordGenerator::updateTest(const KeywordLoader& loader , const std::string& testFile) const { std::stringstream stream; stream << testHeader; for (auto iter = loader.keyword_begin(); iter != loader.keyword_end(); ++iter) { const std::string& keywordName = (*iter).first; std::shared_ptr<ParserKeyword> keyword = (*iter).second; stream << startTest(keywordName); stream << " std::string jsonFile = \"" << loader.getJsonFile( keywordName) << "\";" << std::endl; stream << " boost::filesystem::path jsonPath( jsonFile );" << std::endl; stream << " Json::JsonObject jsonConfig( jsonPath );" << std::endl; stream << " ParserKeyword jsonKeyword(jsonConfig);" << std::endl; stream << " ParserKeywords::" << keywordName << " inlineKeyword;" << std::endl; stream << " BOOST_CHECK_EQUAL( jsonKeyword, inlineKeyword );" << std::endl; stream << " if (jsonKeyword.hasDimension()) {" <<std::endl; stream << " const auto& parserRecord = jsonKeyword.getRecord(0);" << std::endl; stream << " for (size_t i=0; i < parserRecord.size(); i++){ " << std::endl; stream << " const auto& item = parserRecord.get( i );" << std::endl; stream << " for (size_t j=0; j < item.numDimensions(); j++) {" << std::endl; stream << " const std::string& dimString = item.getDimension(j);" << std::endl; stream << " BOOST_CHECK_NO_THROW( unitSystem.getNewDimension( dimString ));" << std::endl; stream << " }" << std::endl; stream << " }" << std::endl; stream << " }" << std::endl; stream << endTest( ); } return updateFile( stream , testFile ); }
bool KeywordGenerator::updateSource(const KeywordLoader& loader , const std::string& sourceFile, int blocks ) const { std::stringstream newSource; const int keywords = loader.size(); const int blocksize = (keywords / blocks) + 1; std::vector< std::stringstream > streams( blocks ); for( unsigned int i = 0; i < streams.size(); ++i ) streams[ i ] << sourceHeader << std::endl << "void addDefaultKeywords" << i << "(Parser& p);" << std::endl << "void addDefaultKeywords" << i << "(Parser& p) {" << std::endl; int bi = 0; for( auto iter = loader.keyword_begin(); iter != loader.keyword_end(); ++iter ) { auto block = bi++ / blocksize; streams[ block ] << "p.addKeyword< ParserKeywords::" << iter->second->className() << " >();" << std::endl; } for( auto& stream : streams ) stream << "}}}" << std::endl; for( unsigned int i = 0; i < streams.size(); ++i ) { auto srcfile = sourceFile; updateFile( streams[i], srcfile.insert( srcfile.size() - 4, std::to_string( i ) ) ); } newSource << sourceHeader; for (auto iter = loader.keyword_begin(); iter != loader.keyword_end(); ++iter) { std::shared_ptr<ParserKeyword> keyword = (*iter).second; newSource << keyword->createCode() << std::endl; } for( auto i = 0; i < blocks; ++i ) newSource << "void addDefaultKeywords" << i << "(Parser& p);" << std::endl; newSource << "}" << std::endl; newSource << "void Parser::addDefaultKeywords() {" << std::endl; for( auto i = 0; i < blocks; ++i ) newSource << "Opm::ParserKeywords::addDefaultKeywords" << i << "(*this);" << std::endl; newSource << "}}" << std::endl; return write_file( newSource, sourceFile, m_verbose, "source" ); }
bool KeywordGenerator::updateHeader(const KeywordLoader& loader, const std::string& headerBuildPath, const std::string& headerFile) const { bool update = false; std::map< char, std::vector< const ParserKeyword* > > keywords; for( auto iter = loader.keyword_begin(); iter != loader.keyword_end(); ++iter ) keywords[ std::toupper( iter->second->className().at(0) ) ].push_back( iter->second.get() ); for( const auto& iter : keywords ) { std::stringstream stream; stream << headerHeader( std::string( 1, std::toupper( iter.first ) ) ); for( auto& kw : iter.second ) stream << kw->createDeclaration(" ") << std::endl; stream << "}" << std::endl << "}" << std::endl; stream << "#endif" << std::endl; const auto final_path = headerBuildPath + headerFile + "/" + std::string( 1, iter.first ) + ".hpp"; if( write_file( stream, final_path, m_verbose, "header" ) ) update = true; } std::stringstream stream; stream << headerHeader(""); stream << "}}" << std::endl; for( const auto& iter : keywords ) stream << "#include <" << headerFile + "/" << std::string( 1, std::toupper( iter.first ) ) + ".hpp>" << std::endl; stream << "#endif" << std::endl; const auto final_path = headerBuildPath + headerFile + ".hpp"; return write_file( stream, final_path, m_verbose, "header" ) || update; }