Files
opm-common/sunbeam/deck.cpp
Joakim Hove 67b30fe715 Use pybind11 as binding framework
This commit changes the api for the Schedule class, the various time related
methods now return datetime.datetime instances instead of datetime.data.
2018-02-08 18:53:15 +01:00

56 lines
1.5 KiB
C++

#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <pybind11/pybind11.h>
#include "converters.hpp"
#include "sunbeam.hpp"
namespace {
size_t size( const Deck& deck ) {
return deck.size();
}
size_t count( const Deck& deck, const std::string& kw ) {
return deck.count(kw);
}
bool hasKeyword( const Deck& deck, const std::string& kw ) {
return deck.hasKeyword(kw);
}
const DeckKeyword& getKeyword_tuple( const Deck& deck, py::tuple kw_index ) {
const std::string kw = py::cast<const std::string>(kw_index[0]);
const size_t index = py::cast<size_t>(kw_index[1]);
return deck.getKeyword(kw, index);
}
const DeckKeyword& getKeyword_string( const Deck& deck, const std::string& kw ) {
return deck.getKeyword(kw);
}
const DeckKeyword& getKeyword_int( const Deck& deck, size_t index ) {
return deck.getKeyword(index);
}
}
void sunbeam::export_Deck(py::module &module) {
py::class_< Deck >(module, "Deck")
.def( "__len__", &size )
.def( "__contains__", &hasKeyword )
.def("__iter__",
[] (const Deck &deck) { return py::make_iterator(deck.begin(), deck.end()); }, py::keep_alive<0, 1>())
.def( "__getitem__", &getKeyword_int, ref_internal)
.def( "__getitem__", &getKeyword_string, ref_internal)
.def( "__getitem__", &getKeyword_tuple, ref_internal)
.def( "__str__", &str<Deck>)
.def( "count", &count )
;
}