python: implement __getitem__ for formula

* wrap/python/spot_impl.i: Implement it.
* wrap/python/tests/ltlsimple.py: Test a for loop.
* src/ltlast/formula.hh: Remove superfluous assert().
This commit is contained in:
Alexandre Duret-Lutz 2015-09-27 20:36:07 +02:00
parent 5711d34489
commit 533268000d
3 changed files with 15 additions and 1 deletions

View file

@ -295,10 +295,22 @@ namespace std {
#undef ltl
%exception spot::ltl::formula::__getitem__ {
try {
$action
}
catch (const std::runtime_error& e)
{
SWIG_exception(SWIG_IndexError, e.what());
}
}
%extend spot::ltl::formula {
// __cmp__ is for Python 2.0
int __cmp__(spot::ltl::formula b) { return self->id() - b.id(); }
size_t __hash__() { return self->id(); }
unsigned __len__() { return self->size(); }
formula __getitem__(unsigned pos) { return self->nth(pos); }
std::string __repr__() { return spot::ltl::str_psl(*self); }
std::string _repr_latex_()