python: give access to the "product-states" property

* python/spot/impl.i (get_product_states, set_product_states): New.
* tests/python/product.ipynb: Use it.
* NEWS: Mention it.
This commit is contained in:
Alexandre Duret-Lutz 2017-12-22 17:23:56 +01:00
parent 904cfb27fa
commit 19348c8938
3 changed files with 259 additions and 13 deletions

View file

@ -428,8 +428,10 @@ namespace swig
namespace std {
%template(liststr) list<std::string>;
%template(pairunsigned) pair<unsigned, unsigned>;
%template(vectorformula) vector<spot::formula>;
%template(vectorunsigned) vector<unsigned>;
%template(vectorpairunsigned) vector<pair<unsigned, unsigned>>;
%template(vectorbool) vector<bool>;
%template(vectorbdd) vector<bdd>;
%template(vectorstring) vector<string>;
@ -465,6 +467,19 @@ namespace std {
DeprecationWarning)
%}
// Must occur before the twa declaration
%typemap(out) SWIGTYPE* spot::twa::get_product_states %{
if (!$1)
$result = SWIG_Py_Void();
else
{
unsigned sz = $1->size();
$result = PyList_New(sz);
for (unsigned i = 0; i < sz; ++i)
PyList_SetItem($result, i, swig::from((*$1)[i]));
}
%}
%include <spot/twa/twa.hh>
%include <spot/tl/apcollect.hh>
@ -769,6 +784,21 @@ def state_is_accepting(self, src) -> "bool":
return self->get_named_prop<std::vector<std::string>>("state-names");
}
void set_product_states(std::vector<std::pair<unsigned, unsigned>> pairs)
{
self->set_named_prop("product-states", new
std::vector<std::pair<unsigned,
unsigned>>(std::move(pairs)));
}
std::vector<std::pair<unsigned, unsigned>>* get_product_states()
{
return self->get_named_prop
<std::vector<std::pair<unsigned, unsigned>>>("product-states");
}
twa* highlight_state(unsigned state, unsigned color)
{
auto hs =