createDefaultKeywordList now able to generate dump file.
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
namespace Json {
|
namespace Json {
|
||||||
|
|
||||||
void JsonObject::initialize(const std::string& inline_json) {
|
void JsonObject::initialize(const std::string& inline_json) {
|
||||||
|
content = inline_json;
|
||||||
root = cJSON_Parse( inline_json.c_str() );
|
root = cJSON_Parse( inline_json.c_str() );
|
||||||
if (!root)
|
if (!root)
|
||||||
throw std::invalid_argument("Parsing json input failed");
|
throw std::invalid_argument("Parsing json input failed");
|
||||||
@@ -192,6 +193,9 @@ namespace Json {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string JsonObject::get_content() const {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,12 +54,15 @@ namespace Json {
|
|||||||
bool is_array( ) const;
|
bool is_array( ) const;
|
||||||
bool is_object( ) const;
|
bool is_object( ) const;
|
||||||
|
|
||||||
|
std::string get_content() const;
|
||||||
|
|
||||||
size_t size() const;
|
size_t size() const;
|
||||||
private:
|
private:
|
||||||
JsonObject get_scalar_object(const std::string& key) const;
|
JsonObject get_scalar_object(const std::string& key) const;
|
||||||
void initialize(const std::string& inline_json);
|
void initialize(const std::string& inline_json);
|
||||||
cJSON * root;
|
cJSON * root;
|
||||||
bool owner;
|
bool owner;
|
||||||
|
std::string content;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
using namespace Opm;
|
using namespace Opm;
|
||||||
|
|
||||||
|
typedef void (*keywordGenerator)(std::ofstream& of, const std::string keywordName, Json::JsonObject* jsonKeyword);
|
||||||
|
|
||||||
void createHeader(std::ofstream& of ) {
|
void createHeader(std::ofstream& of ) {
|
||||||
of << "#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>" << std::endl;
|
of << "#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>" << std::endl;
|
||||||
of << "#include <opm/parser/eclipse/Parser/ParserItem.hpp>" << std::endl;
|
of << "#include <opm/parser/eclipse/Parser/ParserItem.hpp>" << std::endl;
|
||||||
@@ -35,9 +37,28 @@ void endFunction(std::ofstream& of) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void inlineKeyword(const boost::filesystem::path& file , std::ofstream& of) {
|
void generateSourceForKeyword(std::ofstream& of, const std::string keywordName, Json::JsonObject* jsonKeyword)
|
||||||
std::string keyword(file.filename().string());
|
{
|
||||||
if (ParserKeyword::validName(keyword)) {
|
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;
|
||||||
|
|
||||||
|
std::cout << "Creating keyword: " << keywordName << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
Json::JsonObject * jsonKeyword;
|
||||||
try {
|
try {
|
||||||
jsonKeyword = new Json::JsonObject(file);
|
jsonKeyword = new Json::JsonObject(file);
|
||||||
@@ -46,28 +67,18 @@ void inlineKeyword(const boost::filesystem::path& file , std::ofstream& of) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
generate(of, file.filename().string(), jsonKeyword);
|
||||||
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;
|
delete jsonKeyword;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void inlineAllKeywords(const boost::filesystem::path& directory , std::ofstream& of) {
|
void scanAllKeywords(const boost::filesystem::path& directory , std::ofstream& of, keywordGenerator generate) {
|
||||||
boost::filesystem::directory_iterator end;
|
boost::filesystem::directory_iterator end;
|
||||||
for (boost::filesystem::directory_iterator iter(directory); iter != end; iter++) {
|
for (boost::filesystem::directory_iterator iter(directory); iter != end; iter++) {
|
||||||
if (boost::filesystem::is_directory(*iter))
|
if (boost::filesystem::is_directory(*iter))
|
||||||
inlineAllKeywords(*iter , of);
|
scanAllKeywords(*iter , of, generate);
|
||||||
else
|
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) {
|
int main(int argc , char ** argv) {
|
||||||
const char * config_root = argv[1];
|
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);
|
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);
|
createHeader(of);
|
||||||
startFunction(of);
|
startFunction(of);
|
||||||
inlineAllKeywords( directory , of );
|
scanAllKeywords( directory , of, &generateSourceForKeyword );
|
||||||
endFunction(of);
|
endFunction(of);
|
||||||
of << "}" << std::endl;
|
of << "}" << std::endl;
|
||||||
|
|
||||||
of.close();
|
of.close();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user