1use std::ops::Deref;
9use std::path::Path;
10
11use crate::graph::*;
12use crate::properties;
13
14macro_rules! impl_deref {
15 ($type:ty) => {
16 impl<G: SwhGraph> SwhGraph for $type {
17 #[inline(always)]
18 fn path(&self) -> &Path {
19 self.deref().path()
20 }
21 #[inline(always)]
22 fn is_transposed(&self) -> bool {
23 self.deref().is_transposed()
24 }
25 #[inline(always)]
26 fn num_nodes(&self) -> usize {
27 self.deref().num_nodes()
28 }
29 #[inline(always)]
30 fn has_node(&self, node_id: NodeId) -> bool {
31 self.deref().has_node(node_id)
32 }
33 #[inline(always)]
34 fn num_arcs(&self) -> u64 {
35 self.deref().num_arcs()
36 }
37 #[inline(always)]
38 fn has_arc(&self, src_node_id: NodeId, dst_node_id: NodeId) -> bool {
39 self.deref().has_arc(src_node_id, dst_node_id)
40 }
41 }
42
43 impl<G: SwhForwardGraph> SwhForwardGraph for $type {
44 type Successors<'succ>
45 = <G as SwhForwardGraph>::Successors<'succ>
46 where
47 Self: 'succ;
48
49 #[inline(always)]
50 fn successors(&self, node_id: NodeId) -> Self::Successors<'_> {
51 self.deref().successors(node_id)
52 }
53 #[inline(always)]
54 fn outdegree(&self, node_id: NodeId) -> usize {
55 self.deref().outdegree(node_id)
56 }
57 }
58
59 impl<G: SwhLabeledForwardGraph> SwhLabeledForwardGraph for $type {
60 type LabeledArcs<'arc>
61 = <G as SwhLabeledForwardGraph>::LabeledArcs<'arc>
62 where
63 Self: 'arc;
64 type LabeledSuccessors<'succ>
65 = <G as SwhLabeledForwardGraph>::LabeledSuccessors<'succ>
66 where
67 Self: 'succ;
68
69 #[inline(always)]
70 fn untyped_labeled_successors(&self, node_id: NodeId) -> Self::LabeledSuccessors<'_> {
71 self.deref().untyped_labeled_successors(node_id)
72 }
73 }
74
75 impl<G: SwhBackwardGraph> SwhBackwardGraph for $type {
76 type Predecessors<'succ>
77 = <G as SwhBackwardGraph>::Predecessors<'succ>
78 where
79 Self: 'succ;
80
81 #[inline(always)]
82 fn predecessors(&self, node_id: NodeId) -> Self::Predecessors<'_> {
83 self.deref().predecessors(node_id)
84 }
85 #[inline(always)]
86 fn indegree(&self, node_id: NodeId) -> usize {
87 self.deref().indegree(node_id)
88 }
89 }
90
91 impl<G: SwhLabeledBackwardGraph> SwhLabeledBackwardGraph for $type {
92 type LabeledArcs<'arc>
93 = <G as SwhLabeledBackwardGraph>::LabeledArcs<'arc>
94 where
95 Self: 'arc;
96 type LabeledPredecessors<'succ>
97 = <G as SwhLabeledBackwardGraph>::LabeledPredecessors<'succ>
98 where
99 Self: 'succ;
100
101 #[inline(always)]
102 fn untyped_labeled_predecessors(
103 &self,
104 node_id: NodeId,
105 ) -> Self::LabeledPredecessors<'_> {
106 self.deref().untyped_labeled_predecessors(node_id)
107 }
108 }
109 impl<G: SwhGraphWithProperties> SwhGraphWithProperties for $type {
110 type Maps = <G as SwhGraphWithProperties>::Maps;
111 type Timestamps = <G as SwhGraphWithProperties>::Timestamps;
112 type Persons = <G as SwhGraphWithProperties>::Persons;
113 type Contents = <G as SwhGraphWithProperties>::Contents;
114 type Strings = <G as SwhGraphWithProperties>::Strings;
115 type LabelNames = <G as SwhGraphWithProperties>::LabelNames;
116 #[inline(always)]
117 fn properties(
118 &self,
119 ) -> &properties::SwhGraphProperties<
120 Self::Maps,
121 Self::Timestamps,
122 Self::Persons,
123 Self::Contents,
124 Self::Strings,
125 Self::LabelNames,
126 > {
127 self.deref().properties()
128 }
129 }
130 };
131}
132
133impl_deref!(&G);
134impl_deref!(&mut G);
135impl_deref!(Box<G>);
136impl_deref!(std::cell::Ref<'_, G>);
137impl_deref!(std::cell::RefMut<'_, G>);
138impl_deref!(std::cell::LazyCell<G>);
139impl_deref!(std::rc::Rc<G>);
140impl_deref!(std::sync::Arc<G>);
141impl_deref!(std::sync::LazyLock<G>);