createDefaultKeywordList now able to generate dump file.

This commit is contained in:
atleh
2014-03-31 14:25:45 +02:00
parent 3087f33fd8
commit 0505c0a9ca
3 changed files with 53 additions and 29 deletions

View File

@@ -14,6 +14,8 @@
using namespace Opm;
typedef void (*keywordGenerator)(std::ofstream& of, const std::string keywordName, Json::JsonObject* jsonKeyword);
void createHeader(std::ofstream& of ) {
of << "#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>" << std::endl;
of << "#include <opm/parser/eclipse/Parser/ParserItem.hpp>" << std::endl;
@@ -35,39 +37,48 @@ void endFunction(std::ofstream& of) {
}
void inlineKeyword(const boost::filesystem::path& file , std::ofstream& of) {
std::string keyword(file.filename().string());
if (ParserKeyword::validName(keyword)) {
Json::JsonObject * jsonKeyword;
try {
jsonKeyword = new Json::JsonObject(file);
} catch(...) {
std::cerr << "Parsing json config file: " << file.string() << " failed - keyword skipped." << std::endl;
return;
}
void generateSourceForKeyword(std::ofstream& of, const std::string keywordName, Json::JsonObject* jsonKeyword)
{
if (ParserKeyword::validName(keywordName)) {
ParserKeywordConstPtr parserKeyword(new ParserKeyword(*jsonKeyword));
std::string indent(" ");
of << "{" << std::endl;
of << indent << "ParserKeyword *";
parserKeyword->inlineNew(of , keywordName , indent);
of << indent << "addKeyword( ParserKeywordConstPtr(" << keywordName << "));" << std::endl;
of << "}" << std::endl << std::endl;
{
ParserKeywordConstPtr parserKeyword(new ParserKeyword(*jsonKeyword));
std::string indent(" ");
of << "{" << std::endl;
of << indent << "ParserKeyword *";
parserKeyword->inlineNew(of , keyword , indent);
of << indent << "addKeyword( ParserKeywordConstPtr(" << keyword << "));" << std::endl;
of << "}" << std::endl << std::endl;
std::cout << "Creating keyword: " << file.filename() << std::endl;
delete jsonKeyword;
}
std::cout << "Creating keyword: " << keywordName << std::endl;
}
}
void inlineAllKeywords(const boost::filesystem::path& directory , std::ofstream& of) {
void generateDumpForKeyword(std::ofstream& of, const std::string keywordName, Json::JsonObject* jsonKeyword)
{
of << keywordName << std::endl;
of << jsonKeyword->get_content() << std::endl;
}
void scanKeyword(const boost::filesystem::path& file , std::ofstream& of, keywordGenerator generate) {
Json::JsonObject * jsonKeyword;
try {
jsonKeyword = new Json::JsonObject(file);
} catch(...) {
std::cerr << "Parsing json config file: " << file.string() << " failed - keyword skipped." << std::endl;
return;
}
generate(of, file.filename().string(), jsonKeyword);
delete jsonKeyword;
}
void scanAllKeywords(const boost::filesystem::path& directory , std::ofstream& of, keywordGenerator generate) {
boost::filesystem::directory_iterator end;
for (boost::filesystem::directory_iterator iter(directory); iter != end; iter++) {
if (boost::filesystem::is_directory(*iter))
inlineAllKeywords(*iter , of);
scanAllKeywords(*iter , of, generate);
else
inlineKeyword(*iter , of);
scanKeyword(*iter , of, generate);
}
}
@@ -76,15 +87,21 @@ void inlineAllKeywords(const boost::filesystem::path& directory , std::ofstream&
int main(int argc , char ** argv) {
const char * config_root = argv[1];
const char * target_file = argv[2];
const char * source_file_to_generate = argv[2];
const char * keyword_dump_file = argv[3];
boost::filesystem::path directory(config_root);
std::ofstream of( target_file );
if (keyword_dump_file) {
std::ofstream dump_file_stream( keyword_dump_file );
scanAllKeywords( directory , dump_file_stream, &generateDumpForKeyword );
dump_file_stream.close();
}
std::ofstream of( source_file_to_generate );
createHeader(of);
startFunction(of);
inlineAllKeywords( directory , of );
scanAllKeywords( directory , of, &generateSourceForKeyword );
endFunction(of);
of << "}" << std::endl;
of.close();
}