forked from JuliaGraphs/MultilayerGraphs.jl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
traits.jl
47 lines (34 loc) · 1.29 KB
/
traits.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Define traits from SimpleTraits.jl. Right now, no trait except `IsDirected` is used by MultilayerGraphs.jl
"""
IsWeighted{X}
Trait that discerns between weighted and unweighted graphs. A graph type should take the `IsWeighted` trait IF AND ONLY IF it implements the signature add_edge!(src,dst,weight). Otherwise it should not.
"""
@traitdef IsWeighted{X}
@traitimpl IsWeighted{SimpleWeightedGraphs.AbstractSimpleWeightedGraph}
"""
is_weighted(g::G) where { G <: AbstractGraph}
Check whether `g` is weighted.
"""
is_weighted(g::G) where {G<:AbstractGraph} = is_weighted(G)
"""
is_weighted(g::G) where {G<:Type{<:AbstractGraph}}
Check whether `g` is weighted.
"""
is_weighted(g::G) where {G<:Type{<:AbstractGraph}} = istrait(IsWeighted{g})
"""
IsMeta{X}
Trait that discerns between graphs that sport edge and vertex metadata.
"""
@traitdef IsMeta{X}
@traitimpl IsMeta{MetaGraphs.AbstractMetaGraph}
@traitimpl IsMeta{SimpleValueGraphs.AbstractValGraph}
"""
is_meta(g::G) where {G <: AbstractGraph}
Check whether `g` supports edge AND vertex metadata.
"""
is_meta(g::G) where {G<:AbstractGraph} = is_meta(G)
"""
is_meta(g::G) where {G<:Type{<:AbstractGraph}}
Check whether `g` supports edge AND vertex metadata.
"""
is_meta(g::G) where {G<:Type{<:AbstractGraph}} = istrait(IsMeta{g})