Skip to content

Commit 2a615c6

Browse files
jcmoscKyle-Ye
andauthored
Subgraph interface (#172)
Co-authored-by: Kyle <[email protected]>
1 parent bdf2352 commit 2a615c6

File tree

7 files changed

+131
-3
lines changed

7 files changed

+131
-3
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/OpenAttributeGraphCxx/Graph/OAGGraph.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,12 @@ bool OAGGraphAnyInputsChanged(const OAGAttribute *excluded_inputs, size_t count)
209209
// TODO
210210
return false;
211211
}
212+
213+
bool OAGGraphBeginDeferringSubgraphInvalidation(OAGGraphRef graph) {
214+
// TODO
215+
return false;
216+
}
217+
218+
void OAGGraphEndDeferringSubgraphInvalidation(OAGGraphRef graph, bool was_deferring) {
219+
// TODO
220+
}

Sources/OpenAttributeGraphCxx/Graph/OAGSubgraph.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,31 @@ void OAGSubgraphRemoveChild(OAGSubgraphRef parent, OAGSubgraphRef child) {
136136
// TODO
137137
}
138138

139+
OAGSubgraphRef OAGSubgraphGetChild(OAGSubgraphRef cf_subgraph, uint32_t index, uint8_t *_Nullable tag_out) {
140+
// TODO
141+
return nullptr;
142+
}
143+
144+
uint32_t OAGSubgraphGetChildCount(OAGSubgraphRef cf_subgraph) {
145+
// TODO
146+
return 0;
147+
}
148+
149+
OAGSubgraphRef OAGSubgraphGetParent(OAGSubgraphRef cf_subgraph, int64_t index) {
150+
// TODO
151+
return nullptr;
152+
}
153+
154+
uint64_t OAGSubgraphGetParentCount(OAGSubgraphRef cf_subgraph) {
155+
// TODO
156+
return 0;
157+
}
158+
159+
bool OAGSubgraphIsAncestor(OAGSubgraphRef cf_subgraph, OAGSubgraphRef other) {
160+
// TODO
161+
return false;
162+
}
163+
139164
void OAGSubgraphApply(OAGSubgraphRef cf_subgraph,
140165
OAGAttributeFlags flags,
141166
const void (*function)(const void * _Nullable context OAG_SWIFT_CONTEXT, OAGAttribute attribute) OAG_SWIFT_CC(swift),

Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGGraph.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ OAG_REFINED_FOR_SWIFT
114114
bool OAGGraphAnyInputsChanged(const OAGAttribute *excluded_inputs, size_t count);
115115
#endif
116116

117+
OAG_EXPORT
118+
OAG_REFINED_FOR_SWIFT
119+
bool OAGGraphBeginDeferringSubgraphInvalidation(OAGGraphRef graph) OAG_SWIFT_NAME(OAGGraphRef.beginDeferringSubgraphInvalidation(self:));
120+
121+
OAG_EXPORT
122+
OAG_REFINED_FOR_SWIFT
123+
void OAGGraphEndDeferringSubgraphInvalidation(OAGGraphRef graph, bool was_deferring) OAG_SWIFT_NAME(OAGGraphRef.endDeferringSubgraphInvalidation(self:wasDeferring:));
124+
117125
OAG_EXTERN_C_END
118126

119127
OAG_IMPLICIT_BRIDGING_DISABLED

Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGSubgraph.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ OAG_EXTERN_C_BEGIN
2222

2323
OAG_EXPORT
2424
OAG_REFINED_FOR_SWIFT
25-
CFTypeID OAGSubgraphGetTypeID();
25+
CFTypeID OAGSubgraphGetTypeID(void) OAG_SWIFT_NAME(getter:OAGSubgraphRef.typeID());
2626

2727
OAG_EXPORT
2828
OAG_REFINED_FOR_SWIFT
@@ -68,6 +68,26 @@ OAG_EXPORT
6868
OAG_REFINED_FOR_SWIFT
6969
void OAGSubgraphRemoveChild(OAGSubgraphRef parent, OAGSubgraphRef child) OAG_SWIFT_NAME(OAGSubgraphRef.removeChild(self:_:));
7070

71+
OAG_EXPORT
72+
OAG_REFINED_FOR_SWIFT
73+
OAGSubgraphRef OAGSubgraphGetChild(OAGSubgraphRef cf_subgraph, uint32_t index, uint8_t *_Nullable tag_out) OAG_SWIFT_NAME(OAGSubgraphRef.child(self:at:tag:));
74+
75+
OAG_EXPORT
76+
OAG_REFINED_FOR_SWIFT
77+
uint32_t OAGSubgraphGetChildCount(OAGSubgraphRef cf_subgraph) OAG_SWIFT_NAME(getter:OAGSubgraphRef.childCount(self:));
78+
79+
OAG_EXPORT
80+
OAG_REFINED_FOR_SWIFT
81+
OAGSubgraphRef OAGSubgraphGetParent(OAGSubgraphRef cf_subgraph, int64_t index) OAG_SWIFT_NAME(OAGSubgraphRef.parent(self:at:));
82+
83+
OAG_EXPORT
84+
OAG_REFINED_FOR_SWIFT
85+
uint64_t OAGSubgraphGetParentCount(OAGSubgraphRef cf_subgraph) OAG_SWIFT_NAME(getter:OAGSubgraphRef.parentCount(self:));
86+
87+
OAG_EXPORT
88+
OAG_REFINED_FOR_SWIFT
89+
bool OAGSubgraphIsAncestor(OAGSubgraphRef cf_subgraph, OAGSubgraphRef other) OAG_SWIFT_NAME(OAGSubgraphRef.isAncestor(self:of:));
90+
7191
OAG_EXPORT
7292
OAG_REFINED_FOR_SWIFT
7393
bool OAGSubgraphIntersects(OAGSubgraphRef subgraph, OAGAttributeFlags flags) OAG_SWIFT_NAME(OAGSubgraphRef.intersects(self:flags:));

Tests/OpenAttributeGraphCompatibilityTests/Graph/GraphCompatibilityTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,18 @@ struct GraphCompatibilityTests {
8585
#expect(graph.mainUpdates == 0)
8686
}
8787
#endif
88+
89+
@Test(.disabled(if: !compatibilityTestEnabled, "Not implemented on OAG"))
90+
func beginDeferringSubgraphInvalidation() {
91+
let graph = Graph()
92+
93+
let wasDeferring1 = graph.beginDeferringSubgraphInvalidation()
94+
#expect(wasDeferring1 == false)
95+
96+
let wasDeferring2 = graph.beginDeferringSubgraphInvalidation()
97+
#expect(wasDeferring2 == true)
98+
99+
graph.endDeferringSubgraphInvalidation(wasDeferring: wasDeferring2)
100+
graph.endDeferringSubgraphInvalidation(wasDeferring: wasDeferring1)
101+
}
88102
}

Tests/OpenAttributeGraphCompatibilityTests/Graph/SubgraphCompatibilityTests.swift

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,56 @@ struct SubgraphCompatibilityTests {
7676
#expect(notifiedCount == 0)
7777
}
7878
}
79+
80+
@MainActor
81+
@Suite // Both ConditionTrait and GraphEnvironmentTrait's isRecursive are true
82+
struct ChildrenTests {
83+
@Test
84+
func addChild() {
85+
let graph = Graph()
86+
let subgraph = Subgraph(graph: graph)
87+
let child = Subgraph(graph: graph)
88+
89+
subgraph.addChild(child)
90+
#expect(subgraph.childCount == 1)
91+
#expect(subgraph.isAncestor(of: child) == true)
92+
93+
#expect(subgraph.child(at: 0, tag: nil) === child)
94+
95+
#expect(child.parentCount == 1)
96+
#expect(child.parent(at: 0) === subgraph)
97+
}
98+
99+
@Test
100+
func addChildWithTag() {
101+
let graph = Graph()
102+
let subgraph = Subgraph(graph: graph)
103+
let child = Subgraph(graph: graph)
104+
105+
subgraph.addChild(child, tag: 1)
106+
#expect(subgraph.childCount == 1)
107+
#expect(subgraph.isAncestor(of: child) == true)
108+
109+
var tag = 0
110+
#expect(subgraph.child(at: 0, tag: &tag) === child)
111+
#expect(tag == 1)
112+
113+
#expect(child.parentCount == 1)
114+
#expect(child.parent(at: 0) === subgraph)
115+
}
116+
117+
@Test
118+
func removeChild() {
119+
let graph = Graph()
120+
let subgraph = Subgraph(graph: graph)
121+
let child = Subgraph(graph: graph)
122+
123+
subgraph.addChild(child)
124+
subgraph.removeChild(child)
125+
#expect(subgraph.childCount == 0)
126+
#expect(subgraph.isAncestor(of: child) == false)
127+
128+
#expect(child.parentCount == 0)
129+
}
130+
}
79131
}

0 commit comments

Comments
 (0)