Skip to content

Commit

Permalink
Merge pull request #4413 from lisajulia/documentation/python
Browse files Browse the repository at this point in the history
Add documentation for DeckRecord and UDAValue
  • Loading branch information
blattms authored Jan 9, 2025
2 parents e27878e + 33e1e99 commit 325b176
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 14 deletions.
28 changes: 14 additions & 14 deletions python/cxx/deck_keyword.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ void python::common::export_DeckKeyword(py::module& module) {
.def("get_SI_array", &get_SI_array, DeckKeyword_get_SI_array_docstring);


py::class_< DeckRecord >( module, "DeckRecord")
.def( "__repr__", &str<DeckRecord> )
.def( "__iter__", +[] (const DeckRecord& record) { return py::make_iterator(record.begin(), record.end()); }, py::keep_alive<0,1>())
.def( "__getitem__", &getItem, ref_internal)
.def( "__len__", &DeckRecord::size )
py::class_<DeckRecord>(module, "DeckRecord", DeckRecord_docstring)
.def("__repr__", &str<DeckRecord>, DeckRecord_repr_docstring)
.def( "__iter__", +[] (const DeckRecord& record) { return py::make_iterator(record.begin(), record.end()); }, py::keep_alive<0,1>(), DeckRecord_iter_docstring)
.def("__getitem__", &getItem, ref_internal, py::arg("index"), DeckRecord_getitem_docstring)
.def("__len__", &DeckRecord::size, DeckRecord_len_docstring)
;


Expand All @@ -273,20 +273,20 @@ void python::common::export_DeckKeyword(py::module& module) {
;


py::class_< UDAValue >(module, "UDAValue")
.def(py::init<double, const Dimension& >())
.def(py::init<const std::string&, const Dimension&>())
.def("dimension", &UDAValue::get_dim)
.def("is_double", &UDAValue::is<double>)
.def("is_string", &UDAValue::is<std::string>)
.def("get_string", &UDAValue::get<std::string>)
.def("get_double", &UDAValue::get<double>)
py::class_<UDAValue>(module, "UDAValue", UDAValue_docstring)
.def(py::init<double, const Dimension&>(), UDAValue_init_double_docstring)
.def(py::init<const std::string&, const Dimension&>(), UDAValue_init_string_docstring)
.def("dimension", &UDAValue::get_dim, UDAValue_dimension_docstring)
.def("is_double", &UDAValue::is<double>, UDAValue_is_double_docstring)
.def("is_string", &UDAValue::is<std::string>, UDAValue_is_string_docstring)
.def("get_string", &UDAValue::get<std::string>, UDAValue_get_string_docstring)
.def("get_double", &UDAValue::get<double>, UDAValue_get_double_docstring)
.def("__repr__", [](const UDAValue& value) {
if (value.is<double>())
return fmt::format("UDAValue(value = {})", value.get<double>());
else
return fmt::format("UDAValue(value = {})", value.get<std::string>());
})
}, UDAValue_repr_docstring)
;


Expand Down
59 changes: 59 additions & 0 deletions python/docstrings_common.json
Original file line number Diff line number Diff line change
Expand Up @@ -476,5 +476,64 @@
"DeckItem_name": {
"signature": "opm.io.deck.DeckItem.name() -> str",
"doc": "Returns the name of the DeckItem.\n\n:return: The name of the DeckItem.\n:type: str"
},
"DeckRecord": {
"type": "class",
"signature": "DeckRecord",
"doc": "Represents a record of data in the deck. A DeckRecord holds a collection of `DeckItem <#opm.io.deck.DeckItem>`_s and provides access to them in various ways."
},
"DeckRecord_repr": {
"signature": "DeckRecord.__repr__() -> str",
"doc": "Returns a string representation of the DeckRecord.\n\n:return: A string representation of the DeckRecord.\n:type: str"
},
"DeckRecord_iter": {
"signature": "DeckRecord.__iter__() -> iterator",
"doc": "Returns an iterator for the DeckRecord, allowing iteration over the contained DeckItems.\n\n:return: An iterator for iterating through the DeckItems.\n:type: iterator"
},
"DeckRecord_getitem": {
"signature": "DeckRecord.__getitem__(index: int) -> DeckItem",
"doc": "Returns the `DeckItem <#opm.io.deck.DeckItem>`_ at the specified index.\n\n:param index: The index used to retrieve the DeckItem.\n:type index: int\n:return: The DeckItem at the specified index.\n:type: DeckItem"
},
"DeckRecord_len": {
"signature": "DeckRecord.__len__() -> int",
"doc": "Returns the number of `DeckItems <#opm.io.deck.DeckItem>`_ in the DeckRecord.\n\n:return: The number of DeckItems.\n:type: int"
},
"UDAValue": {
"type": "class",
"signature": "opm.io.deck.UDAValue",
"doc": "Represents a UDA (User-Defined Arguments) in the deck."
},
"UDAValue_init_double": {
"signature": "opm.io.deck.UDAValue.__init__(value: double, dimension: Dimension) -> UDAValue",
"doc": "Initializes a UDA with a double value and a dimension.\n\n:param value: The double value to store.\n:type value: double\n:param dimension: The dimension associated with this UDA.\n:type dimension: Dimension"
},
"UDAValue_init_string": {
"signature": "opm.io.deck.UDAValue.__init__(value: str, dimension: Dimension) -> UDAValue",
"doc": "Initializes a UDA with a string value and a dimension.\n\n:param value: The string value to store.\n:type value: str\n:param dimension: The dimension associated with this UDA.\n:type dimension: Dimension"
},
"UDAValue_dimension": {
"signature": "opm.io.deck.UDAValue.dimension() -> Dimension",
"doc": "Returns the dimension associated with this UDA.\n\n:return: The dimension of the UDA.\n:type: Dimension"
},
"UDAValue_is_double": {
"signature": "opm.io.deck.UDAValue.is_double() -> bool",
"doc": "Returns whether the UDA is of type double.\n\n:return: True if the UDA is a double, False otherwise.\n:type: bool"
},
"UDAValue_is_string": {
"signature": "opm.io.deck.UDAValue.is_string() -> bool",
"doc": "Returns whether the UDA is of type string.\n\n:return: True if the UDA is a string, False otherwise.\n:type: bool"
},
"UDAValue_get_string": {
"signature": "opm.io.deck.UDAValue.get_string() -> str",
"doc": "Returns the string value of the UDA.\n\n:return: The string value of the UDA.\n:type: str"
},
"UDAValue_get_double": {
"signature": "opm.io.deck.UDAValue.get_double() -> double",
"doc": "Returns the double value of the UDA.\n\n:return: The double value of the UDA.\n:type: double"
},
"UDAValue_repr": {
"signature": "opm.io.deck.UDAValue.__repr__() -> str",
"doc": "Returns a string representation of the UDA. This works for both string and double UDAs.\n\n:return: A string representation of the UDA.\n:type: str"
}

}

0 comments on commit 325b176

Please sign in to comment.