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
7a26fd5a
Commit
7a26fd5a
authored
Apr 14, 2009
by
Tiago Peixoto
Browse files
Add type alias in property creation for convenience
parent
6defdb43
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/graph_tool/core.py
View file @
7a26fd5a
...
...
@@ -106,6 +106,25 @@ def _parse_range(range):
raise
ValueError
(
"invalid value for range: %s: %s "
%
(
range
,
str
(
e
)))
return
(
ran
,
inc
,
inverted
)
def
_type_alias
(
type_name
):
alias
=
{
"int8_t"
:
"bool"
,
"boolean"
:
"bool"
,
"int"
:
"int32_t"
,
"long"
:
"int32_t"
,
"long long"
:
"int64_t"
,
"object"
:
"python::object"
}
if
type_name
in
value_types
():
return
type_name
if
alias
.
has_key
(
type_name
):
return
alias
[
type_name
]
ma
=
re
(
r
"vector<(.*)>"
).
match
(
type_name
)
if
ma
:
t
=
ma
.
group
(
1
)
if
alias
.
has_key
(
t
):
return
"vector<%s>"
%
alias
[
t
]
raise
ValueError
(
"invalid property value type: "
+
type_name
)
################################################################################
# Property Maps
################################################################################
...
...
@@ -513,7 +532,7 @@ class Graph(object):
def
new_vertex_property
(
self
,
type
):
"""Create a new (uninitialized) vertex property map of type `type`, and
return it."""
return
PropertyMap
(
new_vertex_property
(
type
,
return
PropertyMap
(
new_vertex_property
(
_
type
_alias
(
type
)
,
self
.
__graph
.
GetVertexIndex
()),
self
,
"v"
)
...
...
@@ -521,14 +540,15 @@ class Graph(object):
def
new_edge_property
(
self
,
type
):
"""Create a new (uninitialized) edge property map of type `type`, and
return it."""
return
PropertyMap
(
new_edge_property
(
type
,
self
.
__graph
.
GetEdgeIndex
()),
return
PropertyMap
(
new_edge_property
(
_type_alias
(
type
),
self
.
__graph
.
GetEdgeIndex
()),
self
,
"e"
)
@
_handle_exceptions
def
new_graph_property
(
self
,
type
,
val
=
None
):
"""Create a new graph property map of type `type`, and return it. If
`val` is not None, the property is initialized to its value."""
prop
=
PropertyMap
(
new_graph_property
(
type
,
prop
=
PropertyMap
(
new_graph_property
(
_
type
_alias
(
type
)
,
self
.
__graph
.
GetGraphIndex
()),
self
,
"g"
,
lambda
k
:
k
.
__graph
)
if
val
!=
None
:
...
...
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