Commit c0b0a6b7 authored by Tiago Peixoto's avatar Tiago Peixoto

Add is_writable() method to PropertyMap

This also includes convenience property map checks.
parent 5292b8ce
...@@ -459,6 +459,13 @@ public: ...@@ -459,6 +459,13 @@ public:
return python::object(); return python::object();
} }
bool IsWritable() const
{
return is_convertible<
typename property_traits<PropertyMap>::category,
readable_property_map_tag>::value;
}
private: private:
PropertyMap _pmap; // hold an internal copy, since it's cheap PropertyMap _pmap; // hold an internal copy, since it's cheap
}; };
......
...@@ -67,7 +67,8 @@ struct export_vertex_property_map ...@@ -67,7 +67,8 @@ struct export_vertex_property_map
.def("__setitem__", &pmap_t::template SetValue<PythonVertex>) .def("__setitem__", &pmap_t::template SetValue<PythonVertex>)
.def("get_map", &pmap_t::GetMap) .def("get_map", &pmap_t::GetMap)
.def("get_dynamic_map", &pmap_t::GetDynamicMap) .def("get_dynamic_map", &pmap_t::GetDynamicMap)
.def("get_array", &pmap_t::GetArray); .def("get_array", &pmap_t::GetArray)
.def("is_writable", &pmap_t::IsWritable);
} }
string _name; string _name;
...@@ -132,7 +133,8 @@ struct export_edge_property_map ...@@ -132,7 +133,8 @@ struct export_edge_property_map
.def("value_type", &pmap_t::GetType) .def("value_type", &pmap_t::GetType)
.def("get_map", &pmap_t::GetMap) .def("get_map", &pmap_t::GetMap)
.def("get_dynamic_map", &pmap_t::GetDynamicMap) .def("get_dynamic_map", &pmap_t::GetDynamicMap)
.def("get_array", &pmap_t::GetArray); .def("get_array", &pmap_t::GetArray)
.def("is_writable", &pmap_t::IsWritable);
typedef mpl::transform<graph_tool::detail::all_graph_views, typedef mpl::transform<graph_tool::detail::all_graph_views,
...@@ -175,7 +177,8 @@ struct export_graph_property_map ...@@ -175,7 +177,8 @@ struct export_graph_property_map
.def("__setitem__", &pmap_t::template SetValue<GraphInterface>) .def("__setitem__", &pmap_t::template SetValue<GraphInterface>)
.def("get_map", &pmap_t::GetMap) .def("get_map", &pmap_t::GetMap)
.def("get_dynamic_map", &pmap_t::GetDynamicMap) .def("get_dynamic_map", &pmap_t::GetDynamicMap)
.def("get_array", &pmap_t::GetArray); .def("get_array", &pmap_t::GetArray)
.def("is_writable", &pmap_t::IsWritable);
} }
string _name; string _name;
......
...@@ -201,6 +201,21 @@ class PropertyMap(object): ...@@ -201,6 +201,21 @@ class PropertyMap(object):
n = 1 n = 1
return self.__map.get_array(n) return self.__map.get_array(n)
def is_writable(self):
"""Return True if the property is writable."""
return self.__map.is_writable()
def _check_prop_writable(prop, name=None):
if not prop.is_writable():
raise ValueError("property map%s is not writable." %\
((" '%s'" % name) if name != None else ""))
def _check_prop_scalar(prop, name=None):
if prop.value_type() not in ["bool", "int32_t", "int64_t", "unsigned long",
"double", "long double"]:
raise ValueError("property map%s is not of scalar type." %\
((" '%s'" % name) if name != None else ""))
class PropertyDict(dict): class PropertyDict(dict):
"""Wrapper for the dict of vertex, graph or edge properties, which sets the """Wrapper for the dict of vertex, graph or edge properties, which sets the
value on the property map when changed in the dict.""" value on the property map when changed in the dict."""
......
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