Commit db440664 authored by Tiago Peixoto's avatar Tiago Peixoto

Fix edit_{vertex|edge|graph}_property()

The graph object passed to the edit function is now a instance of the
Graph class which wraps GraphInterface, not a GraphInterface instance.
parent de0a0a8e
......@@ -156,9 +156,12 @@ public:
void RemoveGraphProperty(string property);
void InsertEdgeIndexProperty(string property);
void InsertVertexIndexProperty(string property);
void EditVertexProperty(string property, string type, python::object op);
void EditEdgeProperty(string property, string type, python::object op);
void EditGraphProperty(string property, string type, python::object op);
void EditVertexProperty(string property, string type, python::object op,
python::object g);
void EditEdgeProperty(string property, string type, python::object op,
python::object g);
void EditGraphProperty(string property, string type, python::object op,
python::object g);
void ReIndexEdges();
void PurgeVertices();
void PurgeEdges();
......
......@@ -146,18 +146,18 @@ template <class Descriptor>
struct edit_property
{
template <class Graph>
void operator()(GraphInterface& gi, const Graph& g,
const dynamic_properties& dp,
dynamic_property_map* prop_map, python::object& op) const
void operator()(const Graph& g, const dynamic_properties& dp,
dynamic_property_map* prop_map, python::object& op,
python::object& pg) const
{
put_properties(gi, g, Descriptor(), *prop_map, op);
put_properties(g, Descriptor(), *prop_map, op, pg);
}
template<class Graph>
void put_properties(GraphInterface& gi, const Graph& g,
void put_properties(const Graph& g,
typename graph_traits<Graph>::vertex_descriptor,
dynamic_property_map& prop_map,
python::object& operation) const
python::object& operation, python::object& pg) const
{
if (operation == python::object()) // don't set properties if op == None
return;
......@@ -166,17 +166,16 @@ struct edit_property
for (tie(v, v_end) = vertices(g); v != v_end; ++v)
{
python::object val =
operation(python::object(PythonVertex<Graph>(g, *v)),
python::object(ref(gi)));
operation(python::object(PythonVertex<Graph>(g, *v)), pg);
prop_map.put(*v, val);
}
}
template<class Graph>
void put_properties(GraphInterface& gi, const Graph& g,
void put_properties(const Graph& g,
typename graph_traits<Graph>::edge_descriptor,
dynamic_property_map& prop_map,
python::object& operation) const
python::object& operation, python::object& pg) const
{
if (operation == python::object()) // don't set properties if op == None
return;
......@@ -185,8 +184,7 @@ struct edit_property
for (tie(e, e_end) = edges(g); e != e_end; ++e)
{
python::object val =
operation(python::object(PythonEdge<Graph>(g, *e)),
python::object(ref(gi)));
operation(python::object(PythonEdge<Graph>(g, *e)), pg);
prop_map.put(*e, val);
}
}
......@@ -271,8 +269,8 @@ private:
};
void GraphInterface::EditVertexProperty(string property,
string type, python::object op)
void GraphInterface::EditVertexProperty(string property, string type,
python::object op, python::object g)
{
bool valid = false;
for(int i = 0; i < mpl::size<value_types>::type::value; ++i)
......@@ -287,16 +285,15 @@ void GraphInterface::EditVertexProperty(string property,
(get_property_map<value_types,vertex_descriptor,vertex_index_map_t>
(*this, _properties, _vertex_index, property, type, type_names, pmap));
check_filter(*this, lambda::bind<void>(edit_property<vertex_descriptor>(),
var(*this), lambda::_1,
var(_properties), var(pmap),
var(op)),
lambda::_1, var(_properties),
var(pmap), var(op), var(g)),
reverse_check(), directed_check());
delete pmap;
}
void GraphInterface::EditEdgeProperty(string property, string type,
python::object op)
python::object op, python::object g)
{
bool valid = false;
for(int i = 0; i < mpl::size<value_types>::type::value; ++i)
......@@ -311,15 +308,14 @@ void GraphInterface::EditEdgeProperty(string property, string type,
(get_property_map<value_types,edge_descriptor,edge_index_map_t>
(*this, _properties, _edge_index, property, type, type_names,pmap));
check_filter(*this, lambda::bind<void>(edit_property<edge_descriptor>(),
var(*this), lambda::_1,
var(_properties), var(pmap),
var(op)),
lambda::_1, var(_properties),
var(pmap), var(op), var(g)),
reverse_check(), directed_check());
delete pmap;
}
void GraphInterface::EditGraphProperty(string property, string type,
python::object op)
python::object op, python::object g)
{
bool valid = false;
for(int i = 0; i < mpl::size<value_types>::type::value; ++i)
......@@ -338,7 +334,7 @@ void GraphInterface::EditGraphProperty(string property, string type,
if (op != python::object()) // don't set property if op == None
{
python::object val = op(python::object(ref(*this)));
python::object val = op(g);
pmap->put(graph_property_tag(), val);
}
delete pmap;
......
......@@ -589,7 +589,7 @@ class Graph(object):
"""Edit the selected vertex property"""
self.__graph.EditVertexProperty(property, type,
_eval_expr(expr,
edit_expr="v"))
edit_expr="v"), self)
@_attrs(opt_group=__groups[-1])
@_handle_exceptions
......@@ -598,7 +598,7 @@ class Graph(object):
"""Edit the selected edge property"""
self.__graph.EditEdgeProperty(property, type,
_eval_expr(expr,
edit_expr="e"))
edit_expr="e"), self)
@_attrs(opt_group=__groups[-1])
@_handle_exceptions
......@@ -607,7 +607,7 @@ class Graph(object):
"""Edit the selected graph property"""
self.__graph.EditGraphProperty(property, type,
_eval_expr(expr,
edit_expr="g"))
edit_expr="g"), self)
@_attrs(opt_group=__groups[-1])
@_handle_exceptions
......
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