Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
c0b0a6b7
Commit
c0b0a6b7
authored
Aug 16, 2009
by
Tiago Peixoto
Browse files
Add is_writable() method to PropertyMap
This also includes convenience property map checks.
parent
5292b8ce
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/graph/graph_python_interface.hh
View file @
c0b0a6b7
...
...
@@ -459,6 +459,13 @@ public:
return
python
::
object
();
}
bool
IsWritable
()
const
{
return
is_convertible
<
typename
property_traits
<
PropertyMap
>::
category
,
readable_property_map_tag
>::
value
;
}
private:
PropertyMap
_pmap
;
// hold an internal copy, since it's cheap
};
...
...
src/graph/graph_python_interface_export.cc
View file @
c0b0a6b7
...
...
@@ -67,7 +67,8 @@ struct export_vertex_property_map
.
def
(
"__setitem__"
,
&
pmap_t
::
template
SetValue
<
PythonVertex
>)
.
def
(
"get_map"
,
&
pmap_t
::
GetMap
)
.
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
;
...
...
@@ -132,7 +133,8 @@ struct export_edge_property_map
.
def
(
"value_type"
,
&
pmap_t
::
GetType
)
.
def
(
"get_map"
,
&
pmap_t
::
GetMap
)
.
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
,
...
...
@@ -175,7 +177,8 @@ struct export_graph_property_map
.
def
(
"__setitem__"
,
&
pmap_t
::
template
SetValue
<
GraphInterface
>)
.
def
(
"get_map"
,
&
pmap_t
::
GetMap
)
.
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
;
...
...
src/graph_tool/core.py
View file @
c0b0a6b7
...
...
@@ -201,6 +201,21 @@ class PropertyMap(object):
n
=
1
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
):
"""Wrapper for the dict of vertex, graph or edge properties, which sets the
value on the property map when changed in the dict."""
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment