From 1eee12b8b49eccd97e0c7e6c881484c95f0640da Mon Sep 17 00:00:00 2001 From: Laurent XU Date: Tue, 8 Mar 2016 15:59:14 +0100 Subject: [PATCH] python: add wrapper on twa_graph::edges() * spot/twa/twagraph.hh (edges): Do not hide from SWIG. * spot/graph/graph.hh: Hide stuff that SWIG do not understand. * python/spot/impl.i: Add some typemaps and fragment to iterate over the result of twa_graph::edges(). --- python/spot/impl.i | 16 ++++++++++++++++ spot/graph/graph.hh | 2 ++ spot/twa/twagraph.hh | 17 +++++++++++++---- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/python/spot/impl.i b/python/spot/impl.i index 43bf8966e..a279d5d96 100644 --- a/python/spot/impl.i +++ b/python/spot/impl.i @@ -389,6 +389,7 @@ namespace std { %include %nodefaultctor spot::digraph; %nodefaultctor spot::internal::state_out; +%nodefaultctor spot::internal::all_trans; %traits_swigtype(spot::internal::edge_storage >); %fragment(SWIG_Traits_frag(spot::internal::edge_storage >)); @@ -397,10 +398,17 @@ namespace std { SWIG_POINTER_OWN); } +%typemap(edges, optimal="1") spot::internal::all_trans> { + $result = SWIG_NewPointerObj(new $1_ltype($1), $&1_descriptor, + SWIG_POINTER_OWN); +} + %noexception spot::twa_graph::out; +%noexception spot::twa_graph::edges; %include %template(twa_graph_state_out) spot::internal::state_out>; +%template(twa_graph_all_trans) spot::internal::all_trans>; %template(twa_graph_edge_boxed_data) spot::internal::boxed_label; %template(twa_graph_edge_storage) spot::internal::edge_storage >; @@ -582,6 +590,14 @@ namespace std { } } +%extend spot::internal::all_trans> { + swig::SwigPyIterator* __iter__(PyObject **PYTHON_SELF) + { + return swig::make_forward_iterator(self->begin(), self->begin(), + self->end(), *PYTHON_SELF); + } +} + %extend spot::acc_cond::acc_code { std::string __repr__() { diff --git a/spot/graph/graph.hh b/spot/graph/graph.hh index 2e948e8b6..6d9127c04 100644 --- a/spot/graph/graph.hh +++ b/spot/graph/graph.hh @@ -527,11 +527,13 @@ namespace spot template class SPOT_API all_trans { + public: typedef typename std::conditional::value, const typename Graph::edge_vector_t, typename Graph::edge_vector_t>::type tv_t; typedef all_edge_iterator iter_t; + private: tv_t& tv_; public: diff --git a/spot/twa/twagraph.hh b/spot/twa/twagraph.hh index 40d029491..bec6ff5e9 100644 --- a/spot/twa/twagraph.hh +++ b/spot/twa/twagraph.hh @@ -408,11 +408,20 @@ namespace spot auto states() SPOT_RETURN(g_.states()); - auto edges() const - SPOT_RETURN(g_.edges()); - auto edges() - SPOT_RETURN(g_.edges()); + internal::all_trans + edges() const + { + return g_.edges(); + } +#endif + internal::all_trans + edges() + { + return g_.edges(); + } + +#ifndef SWIG auto edge_vector() const SPOT_RETURN(g_.edge_vector()); auto edge_vector()