Files
opm-common/python/cxx/parser.cpp
T

64 lines
2.0 KiB
C++
Raw Normal View History

2019-09-06 10:45:33 +02:00
#include <string>
#include <exception>
2017-08-31 13:49:09 +02:00
#include <opm/json/JsonObject.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
2019-09-06 10:45:33 +02:00
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
2017-08-31 13:49:09 +02:00
#include <opm/parser/eclipse/Deck/Deck.hpp>
2018-01-30 07:46:03 +01:00
#include <pybind11/stl.h>
#include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
2018-01-30 07:46:03 +01:00
#include "export.hpp"
2017-08-31 13:49:09 +02:00
namespace {
2017-08-31 13:49:09 +02:00
Deck create_deck( const std::string& deckStr,
const ParseContext& pc,
const Parser& parser) {
Opm::ErrorGuard guard;
auto p = parser.parseFile( deckStr, pc, guard );
guard.clear();
return p;
}
Deck create_deck_string( const std::string& deckStr,
const ParseContext& pc,
const Parser& parser) {
Opm::ErrorGuard guard;
auto p = parser.parseString( deckStr, pc, guard );
guard.clear();
return p;
2017-08-31 13:49:09 +02:00
}
void add_keyword(Parser* parser, const std::string& json_string) {
const Json::JsonObject keyword(json_string);
parser->addParserKeyword(keyword);
}
2019-09-06 10:45:33 +02:00
}
2017-08-31 13:49:09 +02:00
void python::common::export_Parser(py::module& module) {
2017-08-31 13:49:09 +02:00
module.def( "create_deck", &create_deck );
module.def( "create_deck_string", &create_deck_string);
2019-09-04 14:42:52 +02:00
2019-09-06 10:45:33 +02:00
py::class_<ParserKeyword>(module, "ParserKeyword")
.def_property_readonly("name", &ParserKeyword::getName);
2019-09-06 10:45:33 +02:00
py::class_<Parser>(module, "Parser")
.def(py::init<>())
2019-09-04 14:42:52 +02:00
.def("parse", py::overload_cast<const std::string&>(&Parser::parseFile, py::const_))
.def("parse" , py::overload_cast<const std::string&, const ParseContext&>(&Parser::parseFile, py::const_))
.def("parse_string", py::overload_cast<const std::string&>(&Parser::parseString, py::const_))
.def("parse_string", py::overload_cast<const std::string&, const ParseContext&>(&Parser::parseString, py::const_))
2019-09-06 10:45:33 +02:00
.def("add_keyword", add_keyword)
.def("__getitem__", &Parser::getKeyword, ref_internal);
2017-08-31 13:49:09 +02:00
}