Commit 1eee12b8 authored by Laurent XU's avatar Laurent XU Committed by Alexandre Duret-Lutz
Browse files

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().
parent cd661801
...@@ -389,6 +389,7 @@ namespace std { ...@@ -389,6 +389,7 @@ namespace std {
%include <spot/graph/graph.hh> %include <spot/graph/graph.hh>
%nodefaultctor spot::digraph; %nodefaultctor spot::digraph;
%nodefaultctor spot::internal::state_out; %nodefaultctor spot::internal::state_out;
%nodefaultctor spot::internal::all_trans;
%traits_swigtype(spot::internal::edge_storage<unsigned int, unsigned int, unsigned int, spot::internal::boxed_label<spot::twa_graph_edge_data, false> >); %traits_swigtype(spot::internal::edge_storage<unsigned int, unsigned int, unsigned int, spot::internal::boxed_label<spot::twa_graph_edge_data, false> >);
%fragment(SWIG_Traits_frag(spot::internal::edge_storage<unsigned int, unsigned int, unsigned int, spot::internal::boxed_label<spot::twa_graph_edge_data, false> >)); %fragment(SWIG_Traits_frag(spot::internal::edge_storage<unsigned int, unsigned int, unsigned int, spot::internal::boxed_label<spot::twa_graph_edge_data, false> >));
...@@ -397,10 +398,17 @@ namespace std { ...@@ -397,10 +398,17 @@ namespace std {
SWIG_POINTER_OWN); SWIG_POINTER_OWN);
} }
%typemap(edges, optimal="1") spot::internal::all_trans<spot::digraph<spot::twa_graph_state, spot::twa_graph_edge_data>> {
$result = SWIG_NewPointerObj(new $1_ltype($1), $&1_descriptor,
SWIG_POINTER_OWN);
}
%noexception spot::twa_graph::out; %noexception spot::twa_graph::out;
%noexception spot::twa_graph::edges;
%include <spot/twa/twagraph.hh> %include <spot/twa/twagraph.hh>
%template(twa_graph_state_out) spot::internal::state_out<spot::digraph<spot::twa_graph_state, spot::twa_graph_edge_data>>; %template(twa_graph_state_out) spot::internal::state_out<spot::digraph<spot::twa_graph_state, spot::twa_graph_edge_data>>;
%template(twa_graph_all_trans) spot::internal::all_trans<spot::digraph<spot::twa_graph_state, spot::twa_graph_edge_data>>;
%template(twa_graph_edge_boxed_data) spot::internal::boxed_label<spot::twa_graph_edge_data, false>; %template(twa_graph_edge_boxed_data) spot::internal::boxed_label<spot::twa_graph_edge_data, false>;
%template(twa_graph_edge_storage) spot::internal::edge_storage<unsigned int, unsigned int, unsigned int, spot::internal::boxed_label<spot::twa_graph_edge_data, false> >; %template(twa_graph_edge_storage) spot::internal::edge_storage<unsigned int, unsigned int, unsigned int, spot::internal::boxed_label<spot::twa_graph_edge_data, false> >;
...@@ -582,6 +590,14 @@ namespace std { ...@@ -582,6 +590,14 @@ namespace std {
} }
} }
%extend spot::internal::all_trans<spot::digraph<spot::twa_graph_state, spot::twa_graph_edge_data>> {
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 { %extend spot::acc_cond::acc_code {
std::string __repr__() std::string __repr__()
{ {
......
...@@ -527,11 +527,13 @@ namespace spot ...@@ -527,11 +527,13 @@ namespace spot
template <typename Graph> template <typename Graph>
class SPOT_API all_trans class SPOT_API all_trans
{ {
public:
typedef typename std::conditional<std::is_const<Graph>::value, typedef typename std::conditional<std::is_const<Graph>::value,
const typename Graph::edge_vector_t, const typename Graph::edge_vector_t,
typename Graph::edge_vector_t>::type typename Graph::edge_vector_t>::type
tv_t; tv_t;
typedef all_edge_iterator<Graph> iter_t; typedef all_edge_iterator<Graph> iter_t;
private:
tv_t& tv_; tv_t& tv_;
public: public:
......
...@@ -408,11 +408,20 @@ namespace spot ...@@ -408,11 +408,20 @@ namespace spot
auto states() auto states()
SPOT_RETURN(g_.states()); SPOT_RETURN(g_.states());
auto edges() const internal::all_trans<const graph_t>
SPOT_RETURN(g_.edges()); edges() const
auto edges() {
SPOT_RETURN(g_.edges()); return g_.edges();
}
#endif
internal::all_trans<graph_t>
edges()
{
return g_.edges();
}
#ifndef SWIG
auto edge_vector() const auto edge_vector() const
SPOT_RETURN(g_.edge_vector()); SPOT_RETURN(g_.edge_vector());
auto edge_vector() auto edge_vector()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment