Commit 7cdf9658 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Expose internal graph and index maps in GraphInterface

This makes operations on graphs more flexible in some circumstances.
parent c153e0c0
...@@ -147,9 +147,12 @@ public: ...@@ -147,9 +147,12 @@ public:
typedef property_map<multigraph_t,edge_index_t>::type edge_index_map_t; typedef property_map<multigraph_t,edge_index_t>::type edge_index_map_t;
typedef ConstantPropertyMap<size_t,graph_property_tag> graph_index_map_t; typedef ConstantPropertyMap<size_t,graph_property_tag> graph_index_map_t;
boost::any GetVertexIndex() {return _vertex_index;} // internal access
boost::any GetEdgeIndex() {return _edge_index;}
boost::any GetGraphIndex() {return graph_index_map_t(0);} multigraph_t& GetGraph() {return _mg;}
vertex_index_map_t GetVertexIndex() {return _vertex_index;}
edge_index_map_t GetEdgeIndex() {return _edge_index;}
graph_index_map_t GetGraphIndex() {return graph_index_map_t(0);}
private: private:
// Gets the encapsulated graph view. See graph_filtering.cc for details // Gets the encapsulated graph view. See graph_filtering.cc for details
......
...@@ -322,6 +322,10 @@ BOOST_PYTHON_MODULE(libgraph_tool_core) ...@@ -322,6 +322,10 @@ BOOST_PYTHON_MODULE(libgraph_tool_core)
.def("CopyVertexProperty", &GraphInterface::CopyVertexProperty) .def("CopyVertexProperty", &GraphInterface::CopyVertexProperty)
.def("CopyEdgeProperty", &GraphInterface::CopyEdgeProperty); .def("CopyEdgeProperty", &GraphInterface::CopyEdgeProperty);
class_<GraphInterface::vertex_index_map_t>("vertex_index_map", no_init);
class_<GraphInterface::edge_index_map_t>("edge_index_map", no_init);
class_<GraphInterface::graph_index_map_t>("graph_index_map", no_init);
enum_<GraphInterface::degree_t>("Degree") enum_<GraphInterface::degree_t>("Degree")
.value("In", GraphInterface::IN_DEGREE) .value("In", GraphInterface::IN_DEGREE)
.value("Out", GraphInterface::OUT_DEGREE) .value("Out", GraphInterface::OUT_DEGREE)
......
...@@ -299,14 +299,14 @@ PythonPropertyMap<GraphInterface::vertex_index_map_t> ...@@ -299,14 +299,14 @@ PythonPropertyMap<GraphInterface::vertex_index_map_t>
get_vertex_index(GraphInterface& g) get_vertex_index(GraphInterface& g)
{ {
return PythonPropertyMap<GraphInterface::vertex_index_map_t> return PythonPropertyMap<GraphInterface::vertex_index_map_t>
(any_cast<GraphInterface::vertex_index_map_t>(g.GetVertexIndex())); (g.GetVertexIndex());
} }
PythonPropertyMap<GraphInterface::edge_index_map_t> PythonPropertyMap<GraphInterface::edge_index_map_t>
get_edge_index(GraphInterface& g) get_edge_index(GraphInterface& g)
{ {
return PythonPropertyMap<GraphInterface::edge_index_map_t> return PythonPropertyMap<GraphInterface::edge_index_map_t>
(any_cast<GraphInterface::edge_index_map_t>(g.GetEdgeIndex())); (g.GetEdgeIndex());
} }
// register everything // register everything
......
...@@ -455,17 +455,8 @@ struct new_property_map ...@@ -455,17 +455,8 @@ struct new_property_map
}; };
template <class IndexMap> template <class IndexMap>
python::object new_property(const string& type, boost::any imap) python::object new_property(const string& type, IndexMap index_map)
{ {
IndexMap index_map;
try
{
index_map = any_cast<IndexMap>(imap);
}
catch (bad_any_cast&)
{
throw GraphException("Invalid index map");
}
python::object prop; python::object prop;
bool found = false; bool found = false;
mpl::for_each<value_types>(lambda::bind<void>(new_property_map(), mpl::for_each<value_types>(lambda::bind<void>(new_property_map(),
......
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